harden StreamTestKitSpec, #24308

This commit is contained in:
Patrik Nordwall 2018-01-16 18:30:33 +01:00 committed by Johan Andrén
parent e4dd3c24fc
commit 5fdb247488

View file

@ -7,7 +7,11 @@ import akka.stream._
import akka.stream.scaladsl.Source import akka.stream.scaladsl.Source
import akka.stream.testkit.scaladsl.TestSink import akka.stream.testkit.scaladsl.TestSink
import scala.concurrent.duration._ import scala.concurrent.duration._
import akka.testkit.AkkaSpec import akka.testkit.AkkaSpec
import akka.testkit.EventFilter
import akka.testkit.TestEvent.Mute
import akka.testkit.TestEvent.UnMute
class StreamTestKitSpec extends AkkaSpec { class StreamTestKitSpec extends AkkaSpec {
@ -18,14 +22,18 @@ class StreamTestKitSpec extends AkkaSpec {
"A TestSink Probe" must { "A TestSink Probe" must {
"#toStrict" in { "#toStrict" in {
Source(1 to 4).runWith(TestSink.probe) Source(1 to 4).runWith(TestSink.probe)
.toStrict(300.millis) should ===(List(1, 2, 3, 4)) .toStrict(remainingOrDefault) should ===(List(1, 2, 3, 4))
} }
"#toStrict with failing source" in { "#toStrict with failing source" in {
system.eventStream.publish(Mute(EventFilter[Exception]()))
try {
val error = intercept[AssertionError] { val error = intercept[AssertionError] {
Source.fromIterator(() new Iterator[Int] { Source.fromIterator(() new Iterator[Int] {
var i = 0 var i = 0
override def hasNext: Boolean = true override def hasNext: Boolean = true
override def next(): Int = { override def next(): Int = {
i += 1 i += 1
i match { i match {
@ -34,17 +42,21 @@ class StreamTestKitSpec extends AkkaSpec {
} }
} }
}).runWith(TestSink.probe) }).runWith(TestSink.probe)
.toStrict(300.millis) .toStrict(remainingOrDefault)
} }
error.getCause.getMessage should include("Boom!") error.getMessage should startWith("toStrict received OnError")
error.getMessage should include("List(1, 2)") error.getMessage should include("List(1, 2)")
error.getCause should ===(ex)
} finally {
system.eventStream.publish(UnMute(EventFilter[Exception]()))
}
} }
"#toStrict when subscription was already obtained" in { "#toStrict when subscription was already obtained" in {
val p = Source(1 to 4).runWith(TestSink.probe) val p = Source(1 to 4).runWith(TestSink.probe)
p.expectSubscription() p.expectSubscription()
p.toStrict(300.millis) should ===(List(1, 2, 3, 4)) p.toStrict(remainingOrDefault) should ===(List(1, 2, 3, 4))
} }
"#expectNextOrError with right element" in { "#expectNextOrError with right element" in {