• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2016-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
3  */
4 
5 package kotlinx.coroutines.reactive
6 
7 import kotlinx.coroutines.*
8 import org.junit.Test
9 import kotlin.test.*
10 
11 class PublisherMultiTest : TestBase() {
12     @Test
<lambda>null13     fun testConcurrentStress() = runBlocking {
14         val n = 10_000 * stressTestMultiplier
15         val observable = publish {
16             // concurrent emitters (many coroutines)
17             val jobs = List(n) {
18                 // launch
19                 launch {
20                     send(it)
21                 }
22             }
23             jobs.forEach { it.join() }
24         }
25         val resultSet = mutableSetOf<Int>()
26         observable.collect {
27             assertTrue(resultSet.add(it))
28         }
29         assertEquals(n, resultSet.size)
30     }
31 }
32