File tree Expand file tree Collapse file tree 1 file changed +17
-4
lines changed
src/test/scala/com/github/yruslan/channel Expand file tree Collapse file tree 1 file changed +17
-4
lines changed Original file line number Diff line number Diff line change @@ -241,6 +241,8 @@ class ChannelSuite extends AnyWordSpec with BeforeAndAfterAll {
241
241
)
242
242
}
243
243
244
+ setUncaughtExceptionHandler(t1) ((_, _) => {})
245
+
244
246
t1.start()
245
247
t2.start()
246
248
@@ -275,6 +277,8 @@ class ChannelSuite extends AnyWordSpec with BeforeAndAfterAll {
275
277
ch.send(300 )
276
278
}
277
279
280
+ setUncaughtExceptionHandler(t1) ((_, _) => {})
281
+
278
282
val t2 = createThread {
279
283
ch.send(400 )
280
284
Thread .sleep(30 )
@@ -502,12 +506,18 @@ class ChannelSuite extends AnyWordSpec with BeforeAndAfterAll {
502
506
" handle non-blocking way" when {
503
507
" data is available" in {
504
508
val ch = Channel .make[String ]
509
+ val wg = WaitGroup ()
505
510
506
- Future {
511
+ wg.add(1 )
512
+ val t = createThread {
513
+ wg.done()
507
514
ch.send(" test" )
508
515
}
509
- Thread .sleep(30 )
516
+ t.start()
517
+ wg.await()
518
+ Thread .sleep(100 )
510
519
val v = ch.tryRecv(Duration .Zero )
520
+ t.join()
511
521
512
522
assert(v.nonEmpty)
513
523
assert(v.contains(" test" ))
@@ -525,11 +535,14 @@ class ChannelSuite extends AnyWordSpec with BeforeAndAfterAll {
525
535
" handle finite timeouts" when {
526
536
" timeout is not expired" in {
527
537
val ch = Channel .make[String ]
538
+ val wg = WaitGroup ()
539
+ wg.add()
528
540
529
541
val f = Future {
530
- Thread .sleep( 10 )
531
- ch.trySend (" test" , Duration . Zero )
542
+ wg.done( )
543
+ ch.send (" test" )
532
544
}
545
+ wg.await()
533
546
534
547
val v = ch.tryRecv(Duration .create(200 , TimeUnit .MILLISECONDS ))
535
548
Await .result(f, Duration .apply(2 , SECONDS ))
You can’t perform that action at this time.
0 commit comments