Testing Akka Streams event order

(Thomas Smith) #1

Hello!

I’m currently writing some tests against streams where I’d like to assert that given some input events in a particular order, the correct output events are emitted. I’m trying to do this with TestProbe as follows:

val (probeOne, xs) = TestSource.probe[Int].preMaterialize()
val (probeTwo, ys) = TestSource.probe[Int].preMaterialize()
val r = xs zipLatest ys
val sinkProbe = r.runWith(TestSink.probe[(Int, Int)])

probeOne.sendNext(1)
probeOne.sendNext(2)
probeTwo.sendNext(3)

probeOne.sendComplete()
probeTwo.sendComplete()

sinkProbe.requestNext() shouldEqual (2,3)
sinkProbe.expectComplete()

However, the way TestProbe works, there is no oder specified in which events are delivered. In this specific case, debugging shows that the event to probeTwo is delivered first, while I’d like it to be delivered last.

Is there a way to achieve this without manually sleep()ing between sendNext invocations?
Thanks!

(Gabriel Giussi) #2

Hi Thomas, I’ve tried your test and it can’t be solved with a sleep.
I suppose you are proposing sleeping between send(2) and send(3)

probeOne.sendNext(2)
Thread.sleep(1000)
probeTwo.sendNext(3)

But you will get (1,3) anyway, because ZipLatestInlet isn’t making another pull when it receives the element (1) because outer.hasAllValues is false.

I don’t understay why because the expected behavior (at least by me) is that continues to always pull on push so it retains the last element.