From bc65f93467b6ada44292452b2164d24a267e314e Mon Sep 17 00:00:00 2001 From: rstoyanchev Date: Thu, 31 Oct 2024 10:05:18 +0000 Subject: [PATCH] Improve cancel in SubscriberInputStreamTests --- .../client/SubscriberInputStreamTests.java | 32 +++++++++++-------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/spring-web/src/test/java/org/springframework/http/client/SubscriberInputStreamTests.java b/spring-web/src/test/java/org/springframework/http/client/SubscriberInputStreamTests.java index 3fed1deda40..31e7d096c12 100644 --- a/spring-web/src/test/java/org/springframework/http/client/SubscriberInputStreamTests.java +++ b/spring-web/src/test/java/org/springframework/http/client/SubscriberInputStreamTests.java @@ -133,21 +133,24 @@ class SubscriberInputStreamTests { } @Test - void cancel() throws InterruptedException, IOException { - CountDownLatch latch = new CountDownLatch(1); + void cancel() throws Exception { + CountDownLatch latch1 = new CountDownLatch(1); + CountDownLatch latch2 = new CountDownLatch(1); Flow.Publisher publisher = new OutputStreamPublisher<>( out -> { - assertThatIOException().isThrownBy(() -> { - out.write(FOO); - out.flush(); - out.write(BAR); - out.flush(); - out.write(BAZ); - out.flush(); - }).withMessage("Subscription has been terminated"); - latch.countDown(); - + assertThatIOException() + .isThrownBy(() -> { + out.write(FOO); + out.flush(); + out.write(BAR); + out.flush(); + latch1.countDown(); + out.write(BAZ); + out.flush(); + }) + .withMessage("Subscription has been terminated"); + latch2.countDown(); }, this.byteMapper, this.executor, null); List discarded = new ArrayList<>(); @@ -158,10 +161,11 @@ class SubscriberInputStreamTests { assertThat(is.read(chunk)).isEqualTo(3); assertThat(chunk).containsExactly(FOO); - } - latch.await(); + latch1.await(); + } + latch2.await(); assertThat(discarded).containsExactly("bar".getBytes(UTF_8)); }