Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a stress test that spawns 1M tasks #106

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 23 additions & 2 deletions shared/src/test/scala/Stress.scala
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
import gears.async.Async
import gears.async.AsyncOperations
import gears.async.AsyncOperations.*
import gears.async.AsyncSupport
import gears.async.Future
import gears.async.Future.MutableCollector
import gears.async.Task
import gears.async.Timer
import gears.async.default.given
import gears.async.{Async, AsyncSupport, Future, uninterruptible}
import gears.async.uninterruptible

import java.util.concurrent.atomic.AtomicInteger
import scala.concurrent.duration._
import scala.concurrent.duration.*

class StressTest extends munit.FunSuite:
test("survives a stress test that hammers on creating futures") {
Expand Down Expand Up @@ -44,3 +49,19 @@ class StressTest extends munit.FunSuite:
for i <- 1L to parallelism do sum += collector.results.read().right.get.await
assertEquals(sum, total * (total + 1) / 2)
}

test("1 million concurrent tasks") {
val count = 1_000_000
def task(i: Int) = Task {
AsyncOperations.sleep(100L)
i * 2
}
Async.blocking {
val start = System.currentTimeMillis()
val res = 1.to(count).map(i => task(i).start()).awaitAll
val end = System.currentTimeMillis()
assert(end - start > 100)
assert(res.size == count)
assert(res.sum == (1 + count) * count)
}
}
Loading