File tree Expand file tree Collapse file tree
tests/junit-functional/org/jgroups/tests Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -61,11 +61,14 @@ public synchronized Runner start() {
6161 return this ;
6262 }
6363
64- public synchronized Runner stop () {
65- boolean rc =state (State .stopping );
66- if (!rc )
67- return this ;
68- Thread tmp =thread ;
64+ public Runner stop () {
65+ Thread tmp ;
66+ synchronized (this ) {
67+ boolean rc =state (State .stopping );
68+ if (!rc )
69+ return this ;
70+ tmp =thread ;
71+ }
6972 if (tmp != null ) {
7073 tmp .interrupt ();
7174 if (join_timeout > 0 ) {
Original file line number Diff line number Diff line change @@ -81,6 +81,23 @@ public void testStop() throws TimeoutException {
8181 Util .waitUntil (5000 , 100 , () -> runner .state () == stopped );
8282 }
8383
84+ /** Tests https://redhat.atlassian.net/browse/JGRP-3020 */
85+ public void testStop2 () throws TimeoutException {
86+ final long timeout =3000 ;
87+ Runnable fun =() -> Util .sleep (100 );
88+ runner =createRunner (fun , null )
89+ .setJoinTimeout (timeout )
90+ .start ();
91+ Util .waitUntil (2000 , 100 , () -> runner .state () == running );
92+ long start =System .nanoTime ();
93+ runner .stop (); // will block without https://redhat.atlassian.net/browse/JGRP-3020 for join_timeout ms
94+ long time =System .nanoTime () - start ;
95+ long millis =TimeUnit .NANOSECONDS .toMillis (time );
96+ assert millis < 300 // sleep 100ms
97+ : String .format ("expected to block in stop() less than 300 ms, but blocked for %s" , Util .printTime (time ));
98+ System .out .printf ("stop() blocked for %s\n " , Util .printTime (time ));
99+ }
100+
84101 /**
85102 * Tests the ABA problem (https://issues.redhat.com/browse/JGRP-2919)
86103 */
You can’t perform that action at this time.
0 commit comments