Skip to content

Commit 0fe0a2a

Browse files
committed
Fix the ping-pong test to use 2 channels.
1 parent 9d685ec commit 0fe0a2a

File tree

1 file changed

+29
-26
lines changed

1 file changed

+29
-26
lines changed

src/test/scala/com/github/yruslan/channel/ChannelSuite.scala

Lines changed: 29 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -780,38 +780,41 @@ class ChannelSuite extends AnyWordSpec with BeforeAndAfterAll {
780780
}
781781

782782
"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+
}
797799
}
798-
}
799800

800-
val channel = Channel.make[Int]
801+
val channel1 = Channel.make[Int]
802+
val channel2 = Channel.make[Int]
801803

802-
val fut1 = Future {
803-
worker(1, channel)
804-
}
804+
val fut1 = Future {
805+
worker(1, channel1, channel2)
806+
}
805807

806-
val fut2 = Future {
807-
worker(2, channel)
808-
}
808+
val fut2 = Future {
809+
worker(2, channel2, channel1)
810+
}
809811

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))
812814

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+
}
815818
}
816819

817820
"work with two channels" in {

0 commit comments

Comments
 (0)