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.

Unexpected execution order and failure with duplicated test names

See original GitHub issue

I tried with Kotest 5.0 and later updates

The issue seems to be related to be triggered by two tests not on the same level having the same name. The following tests should work: each load() is properly followed by a complete(), and the tests pass on Kotest 4.x. However, on 5.x they fail with two exceptions: one somewhere in JUnit code, the other in the FakeService. Looks like either InstancePerLeaf is not respected, or the execution order is just messed up because of the duplicated names.

Renaming one of the duplicated test names causes the tests to pass, also removing some its (I think).

This behavior is unexpected, because the “duplicated” test names appear on different levels. My understanding was that the names are considered duplicate on the same tests level only.

Repro:

package com.example
​
import io.kotest.core.TestConfiguration
import io.kotest.core.spec.IsolationMode
import io.kotest.core.spec.style.DescribeSpec
import kotlinx.coroutines.CompletableDeferred
import kotlinx.coroutines.Job
import kotlinx.coroutines.cancel
import kotlinx.coroutines.launch
import kotlinx.coroutines.test.TestCoroutineScope
​
fun TestConfiguration.customTestScope() = TestCoroutineScope(Job()).also { testScope ->
    afterSpec {
        testScope.cancel()
        testScope.cleanupTestCoroutines()
    }
}
​
internal class Repro : DescribeSpec() {
​
    override fun isolationMode() = IsolationMode.InstancePerLeaf
​
    private val service = FakeService()
​
    init {
        describe("test") {
            val load: suspend () -> Unit = { runCatching { service.await() } }
​
            describe("foo") {
                customTestScope().launch { load() }
​
                it("a") {}
​
                it("b") {}
​
                describe("THIS TEST NAME IS DUPLICATED") {
                    service.complete()
​
                    it("a") {}
​
                    it("b") {}
                }
​
                describe("bar") {
                    service.complete()
​
                    it("a") {}
​
                    it("b") {}
​
                    describe("baz") {
                        customTestScope().launch { load() }
​
                        it("a") {}
​
                        it("b") {}
​
                        describe("THIS TEST NAME IS DUPLICATED") {
                            service.complete()
​
                            it("a") {}
​
                            it("b") {}
                        }
                    }
                }
            }
        }
    }
}
​
class FakeService {
​
    var deferred: CompletableDeferred<Unit>? = null
​
    suspend fun await() {
        if (deferred != null) error("Can't await without completing first")
​
        val cd = CompletableDeferred<Unit>()
        deferred = cd
​
        val value = runCatching { cd.await() }
        deferred = null
        value.getOrThrow()
    }
​
    fun complete() {
        deferred!!.complete(Unit)
    }
}

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
sksamuelcommented, Apr 30, 2022

Fixed in master.

1reaction
lwasylcommented, Apr 22, 2022

Yep, looks like exactly the same issue, thanks for pointing me to it! I’ll keep both opened just in case though, as both have clear repros that can be verified.

Read more comments on GitHub >

github_iconTop Results From Across the Web

'Duplicate address' issues cropping up with new at ... - CBS 8
Applicants are then re-directed to a U.S. Postal Service page, where they fill in their name, email and address; click "Check out now"...
Read more >
The JSON Test Results Format
The JSON Test Results Format is a generic file format we use to record the results of each individual test in test run...
Read more >
Advanced googletest Topics
Checking for Failures in the Current Test​​ HasFatalFailure() in the ::testing::Test class returns true if an assertion in the current test has suffered...
Read more >
How do I filter to get a report of many cycles which may ...
Currently you can view the duplicate executions of test cases of many ... On> column name that will sort the date/time into ascending/descending...
Read more >
Test Annotation – Don't Confuse TestNG With Duplicate ...
Do you know that TestNG will execute methods in unexpected order if you provide duplicate priorities and can create a nightmare for you....
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