File tree Expand file tree Collapse file tree 1 file changed +39
-0
lines changed
spring-web/src/test/java/org/springframework/http/server/reactive Expand file tree Collapse file tree 1 file changed +39
-0
lines changed Original file line number Diff line number Diff line change 2121import java .util .ArrayList ;
2222import java .util .Arrays ;
2323import java .util .List ;
24+ import java .util .concurrent .CountDownLatch ;
2425import java .util .concurrent .Executors ;
2526import 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 );
You can’t perform that action at this time.
0 commit comments