Skip to content

Commit

Permalink
- increase delay to fix flaky tests
Browse files Browse the repository at this point in the history
- add new config options to README
- some refactoring
  • Loading branch information
Thomas Sievert committed Jun 25, 2024
1 parent 28d3388 commit 1cfa975
Show file tree
Hide file tree
Showing 7 changed files with 55 additions and 37 deletions.
40 changes: 21 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -123,25 +123,27 @@ or `local.conf`) files.
`test.conf` files are in the [HOCON](https://github.com/lightbend/config/blob/master/HOCON.md) format and support all of
its features. As of the current version, these are the supported properties:

| Name | Description | Example |
| ---------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------- |
| endpoint | The endpoint of your backend to call. | `endpoint = "http://localhost:1234/api"` |
| mediaType | The media type of your content to send. | `mediaType = "application/soap+xml"` |
| method | The method for the request to use. The default is POST and requires a request.xml. Methods like GET do not require one. | `method = "GET"` |
| exclude | Excludes or un-excludes the test or test group. | `exclude = true` |
| ignore | Ignores or un-ignores the test or test group. This means that the test is run, but does not show up in anything generated at the end of the build. | `ignore = true` |
| databaseConfigurations | An array of database configurations to use for pre- and post scripts. See below for details. | `databaseConfigurations = [ { / *content */ } ]` |
| preProcessors | An array of pre processor classes to use. | `preProcessors = ["com.example.ExamplePreProcessor"]` |
| postProcessors | An array of post processor classes to use. | `postProcessors = ["com.example.ExamplePostProcessor"]` |
| preProcessorScripts | An array of paths to groovy pre processor scripts to use. | `preProcessorScripts = [./scripts/pre_processor.groovy]` |
| postProcessorScripts | An array of paths to groovy post processor scripts to use. | `postProcessorScripts = [./scripts/post_processor.groovy]` |
| preRunners | An array of pre runner classes to use. | `preRunners= ["com.example.ExamplePreRunner"]` |
| postRunners | An array of post runner classes to use. | `postRunners = ["com.example.ExamplePostRunner"]` |
| preRunnerScripts | An array of paths to groovy pre runner scripts to use. | `preRunnerScripts = [./scripts/pre_runner.groovy]` |
| postRunnerScripts | An array of paths to groovy post runner scripts to use. | `postRunnerScripts = [./scripts/post_runner.groovy]` |
| headers | A map of headers to use for requests. | `headers = { "some-header": "value" }` |
| title | An optional alternative title for the test. | `title = "Something"` |
| expectedResponseCode | An optional expected HTTP response code. Default is the 200-range. | `expectedResponseCode = 400` |
| Name | Description | Example |
|------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------|-------------------------------------------------------------------------------|
| endpoint | The endpoint of your backend to call. | `endpoint = "http://localhost:1234/api"` |
| mediaType | The media type of your content to send. | `mediaType = "application/soap+xml"` |
| method | The method for the request to use. The default is POST and requires a request.xml. Methods like GET do not require one. | `method = "GET"` |
| exclude | Excludes or un-excludes the test or test group. | `exclude = true` |
| ignore | Ignores or un-ignores the test or test group. This means that the test is run, but does not show up in anything generated at the end of the build. | `ignore = true` |
| databaseConfigurations | An array of database configurations to use for pre- and post scripts. See below for details. | `databaseConfigurations = [ { / *content */ } ]` |
| preProcessors | An array of pre processor classes to use. | `preProcessors = ["com.example.ExamplePreProcessor"]` |
| postProcessors | An array of post processor classes to use. | `postProcessors = ["com.example.ExamplePostProcessor"]` |
| preProcessorScripts | An array of paths to groovy pre processor scripts to use. | `preProcessorScripts = [./scripts/pre_processor.groovy]` |
| postProcessorScripts | An array of paths to groovy post processor scripts to use. | `postProcessorScripts = [./scripts/post_processor.groovy]` |
| preRunners | An array of pre runner classes to use. | `preRunners= ["com.example.ExamplePreRunner"]` |
| preTestTasks | An array of tasks to execute before the test. The order of the entries determines the order of execution. | `preTestTasks = ["DATABASE_SCRIPTS", "PRE_RUNNERS", "PRE_RUNNER_SCRIPTS"]` |
| postRunners | An array of post runner classes to use. | `postRunners = ["com.example.ExamplePostRunner"]` |
| preRunnerScripts | An array of paths to groovy pre runner scripts to use. | `preRunnerScripts = [./scripts/pre_runner.groovy]` |
| postRunnerScripts | An array of paths to groovy post runner scripts to use. | `postRunnerScripts = [./scripts/post_runner.groovy]` |
| preTestTasks | An array of tasks to execute after the test. The order of the entries determines the order of execution. | `postTestTasks = ["DATABASE_SCRIPTS", "POST_RUNNERS", "POST_RUNNER_SCRIPTS"]` |
| headers | A map of headers to use for requests. | `headers = { "some-header": "value" }` |
| title | An optional alternative title for the test. | `title = "Something"` |
| expectedResponseCode | An optional expected HTTP response code. Default is the 200-range. | `expectedResponseCode = 400` |

> The parameter `endpoint` is required and the build will fail if it is missing for a test.
Expand Down
4 changes: 4 additions & 0 deletions detekt.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,7 @@ exceptions:
style:
MagicNumber:
active: false

complexity:
TooManyFunctions:
ignorePrivate: true
12 changes: 6 additions & 6 deletions src/main/kotlin/de/smartsquare/squit/config/ConfigExtensions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,9 @@ val Config.preRunnerScripts get() = getSafePathList(PRE_RUN_SCRIPTS)
* preTestTasks to execute.
* default: PRE_RUNNERS, PRE_RUNNER_SCRIPTS, DATABASE_SCRIPTS
*/
val Config.preTestTasks get() =
when (hasPath(PRE_TEST_TASKS)) {
true -> getEnumList(SquitPreTestTask::class.java, PRE_TEST_TASKS)!!
val Config.preTestTasks: List<SquitPreTestTask>
get() = when (hasPath(PRE_TEST_TASKS)) {
true -> getEnumList(SquitPreTestTask::class.java, PRE_TEST_TASKS)
else -> listOf(
SquitPreTestTask.PRE_RUNNERS,
SquitPreTestTask.PRE_RUNNER_SCRIPTS,
Expand Down Expand Up @@ -146,9 +146,9 @@ val Config.postRunnerScripts get() = getSafePathList(POST_RUN_SCRIPTS)
* postTestTasks to execute.
* default: DATABASE_SCRIPTS, POST_RUNNERS, POST_RUNNER_SCRIPTS
*/
val Config.postTestTasks get() =
when (hasPath(POST_TEST_TASKS)) {
true -> getEnumList(SquitPostTestTask::class.java, POST_TEST_TASKS)!!
val Config.postTestTasks: List<SquitPostTestTask>
get() = when (hasPath(POST_TEST_TASKS)) {
true -> getEnumList(SquitPostTestTask::class.java, POST_TEST_TASKS)
else -> listOf(
SquitPostTestTask.DATABASE_SCRIPTS,
SquitPostTestTask.POST_RUNNERS,
Expand Down
5 changes: 2 additions & 3 deletions src/main/kotlin/de/smartsquare/squit/task/SquitRequestTask.kt
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ import java.util.concurrent.TimeUnit
* Task for running requests against the given api. Also capable of running existing sql scripts before and after the
* request.
*/
@Suppress("TooManyFunctions")
open class SquitRequestTask : DefaultTask() {

/**
Expand Down Expand Up @@ -250,7 +249,7 @@ open class SquitRequestTask : DefaultTask() {

private fun doPreScriptExecutions(config: Config, testDirectoryPath: Path) {
config.preTestTasks.forEach { task ->
when (task!!) {
when (task) {
SquitPreTestTask.PRE_RUNNERS -> executePreRunners(config)
SquitPreTestTask.PRE_RUNNER_SCRIPTS -> executePreRunnerScripts(config)
SquitPreTestTask.DATABASE_SCRIPTS -> executePreDatabaseScripts(config, testDirectoryPath)
Expand Down Expand Up @@ -289,7 +288,7 @@ open class SquitRequestTask : DefaultTask() {

private fun doPostScriptExecutions(config: Config, testDirectoryPath: Path) {
config.postTestTasks.forEach { task ->
when (task!!) {
when (task) {
SquitPostTestTask.POST_RUNNER_SCRIPTS -> executePostRunnerScripts(config)
SquitPostTestTask.POST_RUNNERS -> executePostRunners(config)
SquitPostTestTask.DATABASE_SCRIPTS -> executePostDatabaseScripts(config, testDirectoryPath)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -493,19 +493,32 @@ class ConfigExtensionsTest {
call shouldNotThrow AnyException
}

@Test
fun `config object with an valid preTestTask and postTestTask`() {
val config = ConfigFactory.parseMap(
mapOf(
"endpoint" to "https://example.com",
"preTestTasks" to listOf("DATABASE_SCRIPTS", "PRE_RUNNERS", "PRE_RUNNER_SCRIPTS"),
"postTestTasks" to emptyList<String>(),
)
)

val call = { config.validate() }
call shouldNotThrow AnyException
}

@Test
fun `config object with an invalid preTestTask`() {
val config = ConfigFactory.parseMap(
mapOf(
"endpoint" to "https://example.com",
"preTestTasks" to listOf("[NotExistingTask]"),
"preTestTasks" to listOf("NotExistingTask"),
)
)

val call = { config.validate() }
@Suppress("MaxLineLength")
call shouldThrow BadValue::class withMessage "hardcoded value: Invalid value at 'preTestTasks': " +
"The enum class SquitPreTestTask has no constant of the name '[NotExistingTask]' " +
"The enum class SquitPreTestTask has no constant of the name 'NotExistingTask' " +
"(should be one of [DATABASE_SCRIPTS, PRE_RUNNERS, PRE_RUNNER_SCRIPTS].)"
}

Expand All @@ -514,13 +527,13 @@ class ConfigExtensionsTest {
val config = ConfigFactory.parseMap(
mapOf(
"endpoint" to "https://example.com",
"postTestTasks" to listOf("[NotExistingTask]"),
"postTestTasks" to listOf("NotExistingTask"),
)
)

val call = { config.validate() }
call shouldThrow BadValue::class withMessage "hardcoded value: Invalid value at 'postTestTasks': " +
"The enum class SquitPostTestTask has no constant of the name '[NotExistingTask]' " +
"The enum class SquitPostTestTask has no constant of the name 'NotExistingTask' " +
"(should be one of [DATABASE_SCRIPTS, POST_RUNNERS, POST_RUNNER_SCRIPTS].)"
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import java.time.Instant
Thread.sleep(1)
Thread.sleep(10)
def file = new File(config.getString("rootDir") + "/build/post_run.txt")
file.text = Instant.now().toEpochMilli().toString()
Thread.sleep(1)
Thread.sleep(10)
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import java.time.Instant
Thread.sleep(1)
Thread.sleep(10)
def file = new File(config.getString("rootDir") + "/build/pre_run.txt")
file.text = Instant.now().toEpochMilli().toString()
Thread.sleep(1)
Thread.sleep(10)

0 comments on commit 1cfa975

Please sign in to comment.