I'm not very coroutines savvy, but I'm playing wit...
# kotest
b
I'm not very coroutines savvy, but I'm playing with a test and added a
delay
call inside of a
should
block and found it never seems to pick back up after the
delay
, is there a better way to do that? (I don't necessarily need it for the test, but was 'testing' the test and noticed the behavior)
s
What do you mean by pick back up
b
run the code after
delay
s
sounds like a bug
so
should("foo") { delay(1000) error("boom") }
won't fail
b
Let me double check a simple, isolated example
Ok guess I'm full of shit.
s
ok that's good 🙂
b
Hm, but I do see some weird behavior sometimes. I think it must be related to some other stuff I'm doing there.
I'm trying to test some code which blocks, so that might be throwing things off:
Copy code
should("notify waiters").config(timeout = 5.seconds) {
            val result = async {
                shutdownService.waitForShutdown()
                true
            }
            println("before delay")
            delay(1000)
            shutdownService.beginShutdown()
            println("after!")
            result.await() shouldBe true
        }
where
shutdownService
is:
Copy code
class ShutdownServiceImpl : ShutdownService {
    private val shutdownStarted = AtomicBoolean(false)

    private val shutdownSync = CountDownLatch(1)

    override fun beginShutdown() {
        if (shutdownStarted.compareAndSet(false, true)) {
            shutdownSync.countDown()
        }
    }

    fun waitForShutdown() {
        shutdownSync.await()
    }
}
will that
async
launch in the same thread? If so that may be blocking things sometimes? But it does print "before delay"
So maybe it does before delay -> delay, thread suspend, picks up the async block, then blocks indefinitely
That's probably it
Yup, ok...can ignore me. Thanks Sam.
s
ok so you're happy 🙂
l
rubber duck