diff --git a/spring-web-reactive/src/test/java/org/springframework/reactive/io/ByteArrayPublisherInputStreamTests.java b/spring-web-reactive/src/test/java/org/springframework/reactive/io/ByteArrayPublisherInputStreamTests.java index 134b07b5013..362355b0896 100644 --- a/spring-web-reactive/src/test/java/org/springframework/reactive/io/ByteArrayPublisherInputStreamTests.java +++ b/spring-web-reactive/src/test/java/org/springframework/reactive/io/ByteArrayPublisherInputStreamTests.java @@ -18,6 +18,7 @@ package org.springframework.reactive.io; import java.util.ArrayList; import java.util.List; +import java.util.concurrent.atomic.AtomicBoolean; import org.junit.Before; import org.junit.Test; @@ -77,9 +78,10 @@ public class ByteArrayPublisherInputStreamTests { FileCopyUtils.copy(is, os); Publisher publisher = os.toByteArrayPublisher(); + List result = new ArrayList<>(); + AtomicBoolean complete = new AtomicBoolean(); publisher.subscribe(new Subscriber() { - List result = new ArrayList<>(); @Override public void onSubscribe(Subscription s) { @@ -98,11 +100,16 @@ public class ByteArrayPublisherInputStreamTests { @Override public void onComplete() { - assertArrayEquals(result.get(0), new byte[]{'a', 'b', 'c'}); - assertArrayEquals(result.get(0), new byte[]{'d', 'e'}); + complete.set(true); } }); + while (!complete.get()) { + + } + assertArrayEquals(result.get(0), new byte[]{'a', 'b', 'c'}); + assertArrayEquals(result.get(1), new byte[]{'d', 'e'}); + } } \ No newline at end of file