-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a stress test for creating lots of futures
- Loading branch information
1 parent
c3d1c36
commit 6b64571
Showing
2 changed files
with
25 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import gears.async.{Async, Future, AsyncSupport, uninterruptible} | ||
import gears.async.AsyncOperations.* | ||
import gears.async.default.given | ||
import gears.async.Future.MutableCollector | ||
import java.util.concurrent.atomic.AtomicInteger | ||
|
||
class StressTest extends munit.FunSuite: | ||
test("survives a stress test that hammers on creating futures") { | ||
val total = 200_000L | ||
Seq[Long](1, 2, 4, 16, 1024).foreach: parallelism => | ||
val k = AtomicInteger(0) | ||
def compute(using Async) = | ||
k.incrementAndGet() | ||
Async.blocking: | ||
val collector = MutableCollector((1L to parallelism).map(_ => Future { compute })*) | ||
var sum = 0L | ||
for i <- parallelism + 1 to total do | ||
sum += collector.results.read().right.get.await | ||
collector += Future { compute } | ||
for i <- 1L to parallelism do sum += collector.results.read().right.get.await | ||
assertEquals(sum, total * (total + 1) / 2) | ||
|
||
} |