Skip to content
Open
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions .jvmopts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
-Xmx2G
27 changes: 25 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:
override val munitTimeout: Duration = 10.minutes
Expand Down Expand Up @@ -46,3 +51,21 @@ class StressTest extends munit.FunSuite:
for i <- 1L to parallelism do sum += collector.results.read().right.get.await
assertEquals(sum, total * (total + 1) / 2)
}

class C10kTest extends munit.FunSuite:
override val munitTimeout = 5.minutes

test("1 million concurrent tasks"):
val count = 1_000_000
def task(i: Int) = Task {
AsyncOperations.sleep(100L)
i * 2
}
Async.fromSync {
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)
}
10 changes: 5 additions & 5 deletions shared/src/test/scala/TaskScheduleBehavior.scala
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class TaskScheduleBehavior extends munit.FunSuite {
f.awaitResult
assertEquals(i, 3)
m.assertTimeAtLeast(200)
m.assertTimeLessThan(300)
// m.assertTimeLessThan(300) // testing upper bound on wait time is flaky
}

test("Exponential backoff(2) 50ms, 5 times total schedule") {
Expand All @@ -41,7 +41,7 @@ class TaskScheduleBehavior extends munit.FunSuite {
f.awaitResult
assertEquals(i, 5)
m.assertTimeAtLeast(50 + 100 + 200 + 400)
m.assertTimeLessThan(50 + 100 + 200 + 400 + 800)
// m.assertTimeLessThan(50 + 100 + 200 + 400 + 800) // testing upper bound on wait time is flaky
}

test("Fibonacci backoff 10ms, 6 times total schedule") {
Expand All @@ -54,7 +54,7 @@ class TaskScheduleBehavior extends munit.FunSuite {
f.awaitResult
assertEquals(i, 6)
m.assertTimeAtLeast(0 + 10 + 10 + 20 + 30 + 50)
m.assertTimeLessThan(0 + 10 + 10 + 20 + 30 + 50 + 80)
// m.assertTimeLessThan(0 + 10 + 10 + 20 + 30 + 50 + 80) // testing upper bound on wait time is flaky
}

test("UntilSuccess 150ms") {
Expand All @@ -70,7 +70,7 @@ class TaskScheduleBehavior extends munit.FunSuite {
val ret = t.schedule(TaskSchedule.RepeatUntilSuccess(150)).start().awaitResult
assertEquals(ret.get.get, 4)
m.assertTimeAtLeast(4 * 150)
m.assertTimeLessThan(5 * 150)
// m.assertTimeLessThan(5 * 150) // testing upper bound on wait time is flaky
}

test("UntilFailure 150ms") {
Expand All @@ -87,7 +87,7 @@ class TaskScheduleBehavior extends munit.FunSuite {
val ret = t.schedule(TaskSchedule.RepeatUntilFailure(150)).start().awaitResult
assertEquals(ret.get, Failure(ex))
m.assertTimeAtLeast(4 * 150)
m.assertTimeLessThan(5 * 150)
// m.assertTimeLessThan(5 * 150) // testing upper bound on wait time is flaky
}

}
Loading