title: RxJava2 PublishSubject subscriber fails to receive items when called from multiple threads using SingleScheduler
body: <p>I have the following unit test in which I try to send 10 <code>String</code>s from different threads and test that I receive those <code>String</code>s from a single thread. My problem is that this test flaps. Sometimes it succeeds but sometimes I only receive <code>8</code> or <code>9</code> items and after that the test hangs until the latch times out. Am I using the <code>SingleScheduler</code> in the wrong way? Did I miss something else?</p>
  
  <pre><code>val consumerCallerThreadNames = mutableSetOf&lt;String&gt;()
  val messageCount = AtomicInteger(0)
  
  val latch = CountDownLatch(MESSAGE_COUNT)
  
  @Test
  fun someTest() {
      val msg = "foo"
  
      val subject = PublishSubject.create&lt;String&gt;()
      subject
              .observeOn(SingleScheduler())
              .subscribe({ message -&gt;
                  consumerCallerThreadNames.add(Thread.currentThread().name)
                  messageCount.incrementAndGet()
                  latch.countDown()
              }, Throwable::printStackTrace)
  
      1.rangeTo(MESSAGE_COUNT).forEach {
          Thread({
              try {
                  subject.onNext(msg)
              } catch (t: Throwable) {
                  t.printStackTrace()
              }
          }).start()
      }
      latch.await(10, SECONDS)
  
      assertThat(consumerCallerThreadNames).hasSize(1)
      assertThat(messageCount.get()).isEqualTo(MESSAGE_COUNT)
  }
  
  companion object {
      val MESSAGE_COUNT = 10
  }
  </code></pre>
  
  <p>If I rewrite this to use a single threaded <code>ExecutorService</code> the test no longer flaps so the problem is either with Rx or my lacking knowledge about Rx.</p>