Incorrect test expectations i FlowFutureFlowSpec fixed (#29899)

This commit is contained in:
Johan Andrén 2021-01-13 10:15:48 +01:00 committed by GitHub
parent a1d405d564
commit a34357644f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -24,14 +24,14 @@ class FlowFutureFlowSpec extends StreamSpec {
//so we run all tests cases using both modes of the attributes. //so we run all tests cases using both modes of the attributes.
//please notice most of the cases don't exhibit any difference in behaviour between the two modes //please notice most of the cases don't exhibit any difference in behaviour between the two modes
for { for {
att <- List( (att, name) <- List(
Attributes.NestedMaterializationCancellationPolicy.EagerCancellation, (Attributes.NestedMaterializationCancellationPolicy.EagerCancellation, "EagerCancellation"),
Attributes.NestedMaterializationCancellationPolicy.PropagateToNested) (Attributes.NestedMaterializationCancellationPolicy.PropagateToNested, "PropagateToNested"))
delayDownstreanCancellation = att.propagateToNestedMaterialization delayDownstreamCancellation = att.propagateToNestedMaterialization
attributes = Attributes(att) attributes = Attributes(att)
} { } {
s"a futureFlow with $att" must { s"a futureFlow with $name (delayDownstreamCancellation=$delayDownstreamCancellation)" must {
"work in the simple case with a completed future" in assertAllStagesStopped { "work in the simple case with a completed future" in assertAllStagesStopped {
val (fNotUsed, fSeq) = src10() val (fNotUsed, fSeq) = src10()
.viaMat { .viaMat {
@ -256,32 +256,32 @@ class FlowFutureFlowSpec extends StreamSpec {
} }
"handle closed downstream when flow future is late completed" in assertAllStagesStopped { "handle closed downstream when flow future is completed after downstream cancel" in assertAllStagesStopped {
val prFlow = Promise[Flow[Int, Int, Future[collection.immutable.Seq[Int]]]]() val prFlow = Promise[Flow[Int, Int, Future[collection.immutable.Seq[Int]]]]()
val (fSeq1, fSeq2) = src10() val (fNestedFlowMatVal, fSinkCompletion) = src10()
.viaMat { .viaMat {
Flow.futureFlow(prFlow.future) Flow.futureFlow(prFlow.future)
}(Keep.right) }(Keep.right)
.mapMaterializedValue(_.flatten) .mapMaterializedValue(_.flatten)
.take(0) .take(0) // cancel asap
.toMat(Sink.seq)(Keep.both) .toMat(Sink.ignore)(Keep.both)
.withAttributes(attributes) .withAttributes(attributes)
.run() .run()
if (delayDownstreanCancellation) { fSinkCompletion.futureValue // downstream has completed/cancelled
fSeq1.value should be(empty) if (delayDownstreamCancellation) {
fSeq2.value should be(empty) fNestedFlowMatVal.value should be(empty)
prFlow.success { prFlow.success {
Flow[Int].alsoToMat(Sink.seq)(Keep.right) Flow[Int].alsoToMat(Sink.seq)(Keep.right)
} }
fSeq1.futureValue should be(empty) // was materialized but cancelled
fSeq2.futureValue should be(empty) fNestedFlowMatVal.futureValue should be(empty)
} else { } else {
fSeq1.failed.futureValue should be(a[NeverMaterializedException]) // was never materialized
fSeq1.failed.futureValue.getCause should be(a[NonFailureCancellation]) fNestedFlowMatVal.failed.futureValue should be(a[NeverMaterializedException])
fSeq2.futureValue should be(empty) fNestedFlowMatVal.failed.futureValue.getCause should be(a[NonFailureCancellation])
} }
} }
@ -316,7 +316,7 @@ class FlowFutureFlowSpec extends StreamSpec {
.withAttributes(attributes) .withAttributes(attributes)
.run() .run()
if (delayDownstreanCancellation) { if (delayDownstreamCancellation) {
fSeq2.failed.futureValue should equal(TE("damn!")) fSeq2.failed.futureValue should equal(TE("damn!"))
fSeq1.value should be(empty) fSeq1.value should be(empty)