Skip to content

Test Case Config does not behave as I expected #476

@Jager567

Description

@Jager567

The documentation states that I can add a timeout to a test. It states that it is "Useful for code that is non-deterministic and might not finish". This leads me to believe that this setting will stop the test execution after the given duration has passed. However, when I accidentally executed a test that called a method with an infinite loop, it didn't stop the execution after the timeout had passed. Is this a documentation issue, a fault on my side or a bug?

After some testing, I found out that this fails, but only after the full test has finished:

class FiniteLoopString: StringSpec() {
    "has a long finite loop test".config(timeout = 100.milliseconds) {
        val startTime = currentTimeMillis()
        while (currentTimeMillis() < startTime + 1000) {
            "this" shouldNotBe "that"
        }
    }
}

while the following test just keeps running forever:

class InfiniteLoopString: StringSpec() {
    "has an infinite loop test".config(timeout = 100.milliseconds) {
        while (true) {
            "this" shouldNotBe "that"
        }
    }
}

During my testing, I also found that this test succeeds, even though it takes longer than the timeout:

class SuccessfulTest: WordSpec() {
    init {
        "String.length" should {
            "return the length of the string".config(timeout = 2.seconds) {
                val startTime = currentTimeMillis()
                while (currentTimeMillis() < startTime + 10000) {
                    "this" shouldNotBe "that"
                }
            }
        }
    }
}

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions