From 9bbc5e0a19e41d8a7e7af371d7191061dbedde5b Mon Sep 17 00:00:00 2001 From: rcardin Date: Fri, 14 Jun 2024 14:20:03 +0200 Subject: [PATCH] Added missing test to 'race' --- core/src/test/scala/RaceSpec.scala | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/core/src/test/scala/RaceSpec.scala b/core/src/test/scala/RaceSpec.scala index 080723e..651b690 100644 --- a/core/src/test/scala/RaceSpec.scala +++ b/core/src/test/scala/RaceSpec.scala @@ -112,4 +112,28 @@ class RaceSpec extends AnyFlatSpec with Matchers { actual should be("42") } + + it should "honor the structured concurrency and cancel all the children jobs" in { + val results = new ConcurrentLinkedQueue[String]() + val actual: Int | String = structured { + race( + { + val job1 = fork { + delay(1.seconds) + results.add("job1") + } + 42 + }, { + delay(500.millis) + results.add("job2") + "42" + } + ) + } + + Thread.sleep(2000) + + actual should be("42") + results.toArray should contain theSameElementsInOrderAs List("job2") + } }