Skip to content

Commit ca2c2c8

Browse files
committed
Add regression test for writer invocation lock scope
Signed-off-by: l2yuPa <jeungwon28@gmail.com>
1 parent 752a019 commit ca2c2c8

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

spring-web/src/test/java/org/springframework/http/server/reactive/ChannelSendOperatorTests.java

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import java.util.ArrayList;
2222
import java.util.Arrays;
2323
import java.util.List;
24+
import java.util.concurrent.CountDownLatch;
2425
import java.util.concurrent.Executors;
2526
import java.util.concurrent.TimeUnit;
2627

@@ -216,6 +217,44 @@ void errorInWriteFunction() {
216217
.verify(Duration.ofMillis(5000));
217218
}
218219

220+
@Test
221+
void writeFunctionIsNotInvokedUnderMonitorLock() {
222+
ChannelSendOperator<String> operator = new ChannelSendOperator<>(
223+
Mono.just("one"),
224+
publisher -> {
225+
CountDownLatch acquired = new CountDownLatch(1);
226+
Thread t = new Thread(() -> {
227+
synchronized (publisher) {
228+
acquired.countDown();
229+
}
230+
});
231+
t.start();
232+
233+
try {
234+
if (!acquired.await(1, TimeUnit.SECONDS)) {
235+
throw new IllegalStateException("writeFunction appears to be invoked under monitor lock");
236+
}
237+
}
238+
catch (InterruptedException ex) {
239+
Thread.currentThread().interrupt();
240+
throw new IllegalStateException(ex);
241+
}
242+
finally {
243+
try {
244+
t.join(1_000);
245+
}
246+
catch (InterruptedException ex) {
247+
Thread.currentThread().interrupt();
248+
}
249+
}
250+
251+
return Mono.empty();
252+
});
253+
254+
StepVerifier.create(operator)
255+
.expectComplete()
256+
.verify(Duration.ofSeconds(2));
257+
}
219258

220259
private Mono<Void> sendOperator(Publisher<String> source){
221260
return new ChannelSendOperator<>(source, writer::send);

0 commit comments

Comments
 (0)