@@ -780,38 +780,41 @@ class ChannelSuite extends AnyWordSpec with BeforeAndAfterAll {
780
780
}
781
781
782
782
" ping pong messages between 2 workers" in {
783
- val actions = new StringBuffer ()
784
-
785
- /* Full qualified name 'com.github.yruslan.channel.Channel' is used here to make IntelliJ IDEA happy. */
786
- def worker (workerNum : Int , ch : com.github.yruslan.channel.Channel [Int ]): Unit = {
787
- for (i <- Range (0 , 10 )) {
788
- val k = select(
789
- ch.recver(n => {
790
- actions.append(s " R $workerNum$i- " )
791
- }),
792
- ch.sender(i) {
793
- actions.append(s " S $workerNum$i- " )
794
- }
795
- )
796
- if (! k) throw new IllegalArgumentException (" Failing the worker" )
783
+ for (_ <- Range (0 , 100 )) {
784
+ val actions = new StringBuffer ()
785
+
786
+ /* Full qualified name 'com.github.yruslan.channel.Channel' is used here to make IntelliJ IDEA happy. */
787
+ def worker (workerNum : Int , ch1 : com.github.yruslan.channel.Channel [Int ], ch2 : com.github.yruslan.channel.Channel [Int ]): Unit = {
788
+ for (i <- Range (0 , 10 )) {
789
+ val k = select(
790
+ ch1.recver(n => {
791
+ actions.append(s " R $workerNum$n- " )
792
+ }),
793
+ ch2.sender(i) {
794
+ actions.append(s " S $workerNum$i- " )
795
+ }
796
+ )
797
+ if (! k) throw new IllegalArgumentException (" Failing the worker" )
798
+ }
797
799
}
798
- }
799
800
800
- val channel = Channel .make[Int ]
801
+ val channel1 = Channel .make[Int ]
802
+ val channel2 = Channel .make[Int ]
801
803
802
- val fut1 = Future {
803
- worker(1 , channel )
804
- }
804
+ val fut1 = Future {
805
+ worker(1 , channel1, channel2 )
806
+ }
805
807
806
- val fut2 = Future {
807
- worker(2 , channel )
808
- }
808
+ val fut2 = Future {
809
+ worker(2 , channel2, channel1 )
810
+ }
809
811
810
- Await .result(fut1, Duration .apply(4 , SECONDS ))
811
- Await .result(fut2, Duration .apply(4 , SECONDS ))
812
+ Await .result(fut1, Duration .apply(4 , SECONDS ))
813
+ Await .result(fut2, Duration .apply(4 , SECONDS ))
812
814
813
- // 10 messages sent and received, by 2 workers
814
- assert(actions.toString.length == 80 )
815
+ // 10 messages sent and received, by 2 workers
816
+ assert(actions.toString.length == 80 )
817
+ }
815
818
}
816
819
817
820
" work with two channels" in {
0 commit comments