question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

timeout doesn't actually stop the test

See original GitHub issue

The current implementation of test timeouts makes the test’s result be failure but doesn’t actually proactively stop the test, so you can’t use it to make your tests end in a reasonable amount of time in failure.

For example, this diff applied to release/3.4 yields a failing test. (The embedded test here spins for a second.)

diff --git a/kotlintest-tests/kotlintest-tests-core/src/test/kotlin/com/sksamuel/kotlintest/TestCaseExecutorTest.kt b/kotlintest-tests/kotlintest-tests-core/src/test/kotlin/com/sksamuel/kotlintest/TestCaseExecutorTest.kt
index 51c67410..98f95459 100644
--- a/kotlintest-tests/kotlintest-tests-core/src/test/kotlin/com/sksamuel/kotlintest/TestCaseExecutorTest.kt
+++ b/kotlintest-tests/kotlintest-tests-core/src/test/kotlin/com/sksamuel/kotlintest/TestCaseExecutorTest.kt
@@ -8,6 +8,7 @@ import io.kotlintest.TestCase
 import io.kotlintest.TestCaseConfig
 import io.kotlintest.TestContext
 import io.kotlintest.TestStatus
+import io.kotlintest.matchers.numerics.shouldBeLessThan
 import io.kotlintest.milliseconds
 import io.kotlintest.runner.jvm.TestCaseExecutor
 import io.kotlintest.runner.jvm.TestEngineListener
@@ -258,12 +259,15 @@ class TestCaseExecutorTest : FunSpec() {
         override fun description(): Description = Description.spec("wibble")
       }
 
+      val executorStartTime = currentTimeMillis()
       executor.execute(testCase, context)
+      val executorTotalTimeMillis = currentTimeMillis() - executorStartTime
 
       then(listener).should().exitTestCase(
           argThat { description == Description.spec("wibble") },
           argThat { status == TestStatus.Error && this.error?.message == "Execution of test took longer than 125ms" }
       )
+      executorTotalTimeMillis.shouldBeLessThan(500)
     }
 
     test("test with infinite loop but invocations = 1 should complete with TestStatus.Failure") {

The test is commented out on master and the code seems to be pretty rewritten, so maybe this is fixed in 4.0?

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:11 (11 by maintainers)

github_iconTop GitHub Comments

1reaction
sksamuelcommented, May 16, 2020

I agree that the timeout should apply per invocation. We can add another config value to support that.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Selenium test timeout doesn't stop the test PHPUnit 3.6.10 ...
When a test tries to open a page that doesn't load, and the timeout value is reached, the test doesn't stop or throw...
Read more >
Test time limits and timeouts - Visual Studio App Center
Timed-out test suites could be caused by an issue with test code or because the test suite is too large to complete within...
Read more >
go test -timeout 30m can this be set inside Go code? disable ...
I have a long running test where I would like to set the testing package timeout to 30 minutes from with the my_test.go...
Read more >
Asserting timeouts in JUnit 5 - Level Up Coding
This is better than stopping the test when you get tired of waiting, because if you have @After or @AfterClass procedures, those will...
Read more >
Retry-ability - Cypress Documentation
Overriding the timeout to 0 will essentially disable retrying the query or waiting on an other, since it will spend 0 milliseconds retrying....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found