Skip to content

Conversation

aSemy
Copy link
Contributor

@aSemy aSemy commented Jun 18, 2024

Wait until the engine has completed before asserting the results.

Part of #4113

@aSemy aSemy mentioned this pull request Jun 18, 2024
20 tasks
@aSemy aSemy force-pushed the adam/fix/GlobalTimeoutTest branch from 4790583 to fc80c8e Compare June 18, 2024 20:29
use locks to wait until tests have launched before running assertions
@aSemy aSemy force-pushed the adam/fix/GlobalTimeoutTest branch from fc80c8e to 507c042 Compare June 18, 2024 21:43
@aSemy aSemy changed the title Stabilize GlobalTimeoutTest Stabilize GlobalTimeoutTest and EngineTimeoutTest Jun 19, 2024
@aSemy aSemy marked this pull request as ready for review June 19, 2024 07:25
@aSemy aSemy requested a review from OliverO2 June 19, 2024 07:25
* An active [Job] that will be completed when [engineFinished] is invoked.
* @see waitForEngineFinished
*/
private val engineFinishedJob = Job()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is an interesting solution, using a Job as a boolean-like state which one can wait for while suspending.

It took me some time to decipher, as I had to make sure that the Job

  • does not perform actual work, and
  • does not have children (in which case complete() would not make join() return immediately).

Could you add some comment to that effect?

(The same could be achieved with a Mutex (playground), but that would also require some comment explaining to its uncommon use. I have a similar thing called Gate in this KotlinConf talk companion repo.)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ahh yes, the mutex.withLock {} is probably better. I'll update the code and with a comment.

@aSemy aSemy enabled auto-merge June 21, 2024 14:19
@aSemy
Copy link
Contributor Author

aSemy commented Jun 21, 2024

Hmmm apparently engineFinished() can get called multiple times?

> Task :kotest-framework:kotest-framework-engine:jvmTest

com.sksamuel.kotest.engine.extensions.spec.BeforeSpecListenerTest[jvm]
  Test BeforeSpecListener inline should be triggered before tests[jvm] FAILED (2.3s)
  java.lang.IllegalStateException: This mutex is not locked
  Caused by: java.lang.IllegalStateException: This mutex is not locked

FAILURE: Executed 1423 tests in 6m 5s (1 failed, 186 skipped)

@aSemy aSemy disabled auto-merge June 21, 2024 15:23
Copy link
Contributor

@OliverO2 OliverO2 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, given the new insights. I also wonder why the same listener would observe multiple engines. 🤔

@aSemy
Copy link
Contributor Author

aSemy commented Jun 21, 2024

Looks good, given the new insights. I also wonder why the same listener would observe multiple engines. 🤔

Oh, I figured it out and forgot to update my message. The reason is one of the test re-uses a listener, which I think is reasonable.

test("BeforeSpecListener inline should be triggered before tests") {
val listener = CollectingTestEngineListener()
TestEngineLauncher(listener)
.withClasses(BeforeSpecInlineOrderFunSpecTest::class)
.launch()
TestEngineLauncher(listener)
.withClasses(BeforeSpecInlineOrderDescribeSpecTest::class)
.launch()
a shouldBe "spectest1test2spectestinner"
}

@aSemy aSemy force-pushed the adam/fix/GlobalTimeoutTest branch from 61d8d35 to 973e5b5 Compare June 21, 2024 16:38
@OliverO2
Copy link
Contributor

Thanks for clarifying! Helps to demystify what I suspected was one more piece of magic. Now I can relax again. :)

aSemy and others added 2 commits June 21, 2024 18:45
Co-authored-by: OliverO2 <Oliver.O456i@gmail.com>
Co-authored-by: OliverO2 <Oliver.O456i@gmail.com>
@aSemy aSemy force-pushed the adam/fix/GlobalTimeoutTest branch from 973e5b5 to b4e88a7 Compare June 21, 2024 16:45
@OliverO2 OliverO2 enabled auto-merge June 21, 2024 17:42
@aSemy aSemy disabled auto-merge June 21, 2024 18:36
@aSemy aSemy merged commit 22d38d8 into master Jun 21, 2024
@aSemy aSemy deleted the adam/fix/GlobalTimeoutTest branch June 21, 2024 18:36
OliverO2 added a commit that referenced this pull request Jun 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants