Skip to content

Commit 63ae61d

Browse files
committed
Add test for interaction between Future and uninterruptible
1 parent 06d9608 commit 63ae61d

File tree

1 file changed

+48
-35
lines changed

1 file changed

+48
-35
lines changed

shared/src/test/scala/FutureBehavior.scala

Lines changed: 48 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import gears.async.{Async, Future, Task, TaskSchedule, uninterruptible}
22
import gears.async.default.given
3-
import gears.async.Future.{*:, Promise, zip}
3+
import gears.async.Future.{Promise, zip}
44
import gears.async.AsyncOperations.*
55

66
import java.util.concurrent.CancellationException
@@ -215,40 +215,40 @@ class FutureBehavior extends munit.FunSuite {
215215
assertEquals(zombieModifiedThis, true)
216216
}
217217

218-
test("zip on tuples with EmptyTuple") {
219-
Async.blocking:
220-
val z1 = Future { sleep(500); 10 } *: Future { sleep(10); 222 } *: Future { sleep(150); 333 } *: Future {
221-
EmptyTuple
222-
}
223-
assertEquals(z1.await, (10, 222, 333))
224-
}
225-
226-
test("zip on tuples with last zip") {
227-
Async.blocking:
228-
val z1 = Future { 10 } *: Future { 222 }.zip(Future { 333 })
229-
assertEquals(z1.await, (10, 222, 333))
230-
}
231-
232-
test("zip(3) first error") {
233-
for (_ <- 1 to 20)
234-
Async.blocking:
235-
val e1 = AssertionError(111)
236-
val e2 = AssertionError(211)
237-
val e3 = AssertionError(311)
238-
assertEquals(
239-
(Future {
240-
sleep(Random.between(200, 300));
241-
throw e1
242-
} *: Future {
243-
sleep(Random.between(200, 300));
244-
throw e2
245-
} *: Future {
246-
sleep(Random.between(50, 100));
247-
throw e3
248-
} *: Future.now(Success(EmptyTuple))).awaitResult,
249-
Failure(e3)
250-
)
251-
}
218+
// test("zip on tuples with EmptyTuple") {
219+
// Async.blocking:
220+
// val z1 = Future { sleep(500); 10 } *: Future { sleep(10); 222 } *: Future { sleep(150); 333 } *: Future {
221+
// EmptyTuple
222+
// }
223+
// assertEquals(z1.await, (10, 222, 333))
224+
// }
225+
226+
// test("zip on tuples with last zip") {
227+
// Async.blocking:
228+
// val z1 = Future { 10 } *: Future { 222 }.zip(Future { 333 })
229+
// assertEquals(z1.await, (10, 222, 333))
230+
// }
231+
232+
// test("zip(3) first error") {
233+
// for (_ <- 1 to 20)
234+
// Async.blocking:
235+
// val e1 = AssertionError(111)
236+
// val e2 = AssertionError(211)
237+
// val e3 = AssertionError(311)
238+
// assertEquals(
239+
// (Future {
240+
// sleep(Random.between(200, 300));
241+
// throw e1
242+
// } *: Future {
243+
// sleep(Random.between(200, 300));
244+
// throw e2
245+
// } *: Future {
246+
// sleep(Random.between(50, 100));
247+
// throw e3
248+
// } *: Future.now(Success(EmptyTuple))).awaitResult,
249+
// Failure(e3)
250+
// )
251+
// }
252252

253253
test("cancelled futures return the same constant CancellationException with no stack attached".ignore) {
254254
Async.blocking:
@@ -434,4 +434,17 @@ class FutureBehavior extends munit.FunSuite {
434434
assert(!lastFutureFinished)
435435
}
436436

437+
test("uninterruptible should continue even when Future is cancelled") {
438+
Async.blocking:
439+
val ch = gears.async.UnboundedChannel[Int]()
440+
val reader = Future:
441+
gears.async.uninterruptible:
442+
val i = ch.read().right.get
443+
println(i)
444+
reader.cancel()
445+
ch.sendImmediately(1)
446+
ch.sendImmediately(2)
447+
reader.awaitResult
448+
assertEquals(ch.read(), Right(2))
449+
}
437450
}

0 commit comments

Comments
 (0)