diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 55d15ad5..73bf3a11 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -85,3 +85,5 @@ jobs: run: sudo apt-get install clang libstdc++-12-dev libgc-dev - name: Test run: sbt rootNative/test + - name: Stress Test with Lower Memory + run: env GC_MAXIMUM_HEAP_SIZE=64M sbt 'rootNative/testOnly StressTest' diff --git a/shared/src/test/scala/Stress.scala b/shared/src/test/scala/Stress.scala new file mode 100644 index 00000000..f4c5cb03 --- /dev/null +++ b/shared/src/test/scala/Stress.scala @@ -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, 10000).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) + + }