Skip to content

Commit bc65f93

Browse files
committed
Improve cancel in SubscriberInputStreamTests
1 parent 38c88e7 commit bc65f93

File tree

1 file changed

+18
-14
lines changed

1 file changed

+18
-14
lines changed

spring-web/src/test/java/org/springframework/http/client/SubscriberInputStreamTests.java

+18-14
Original file line numberDiff line numberDiff line change
@@ -133,21 +133,24 @@ void chunkSize() throws Exception {
133133
}
134134

135135
@Test
136-
void cancel() throws InterruptedException, IOException {
137-
CountDownLatch latch = new CountDownLatch(1);
136+
void cancel() throws Exception {
137+
CountDownLatch latch1 = new CountDownLatch(1);
138+
CountDownLatch latch2 = new CountDownLatch(1);
138139

139140
Flow.Publisher<byte[]> publisher = new OutputStreamPublisher<>(
140141
out -> {
141-
assertThatIOException().isThrownBy(() -> {
142-
out.write(FOO);
143-
out.flush();
144-
out.write(BAR);
145-
out.flush();
146-
out.write(BAZ);
147-
out.flush();
148-
}).withMessage("Subscription has been terminated");
149-
latch.countDown();
150-
142+
assertThatIOException()
143+
.isThrownBy(() -> {
144+
out.write(FOO);
145+
out.flush();
146+
out.write(BAR);
147+
out.flush();
148+
latch1.countDown();
149+
out.write(BAZ);
150+
out.flush();
151+
})
152+
.withMessage("Subscription has been terminated");
153+
latch2.countDown();
151154
}, this.byteMapper, this.executor, null);
152155

153156
List<byte[]> discarded = new ArrayList<>();
@@ -158,10 +161,11 @@ void cancel() throws InterruptedException, IOException {
158161

159162
assertThat(is.read(chunk)).isEqualTo(3);
160163
assertThat(chunk).containsExactly(FOO);
161-
}
162164

163-
latch.await();
165+
latch1.await();
166+
}
164167

168+
latch2.await();
165169
assertThat(discarded).containsExactly("bar".getBytes(UTF_8));
166170
}
167171

0 commit comments

Comments
 (0)