Skip to content

Commit

Permalink
Added missing test to 'race'
Browse files Browse the repository at this point in the history
  • Loading branch information
rcardin committed Jun 14, 2024
1 parent e41c232 commit 9bbc5e0
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions core/src/test/scala/RaceSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
}

0 comments on commit 9bbc5e0

Please sign in to comment.