@@ -2035,14 +2035,17 @@ else if (mcount == 4) {
20352035 StreamInfo si = jsm .getStreamInfo (rawStream );
20362036 assertEquals (1 , si .getStreamState ().getMsgCount ());
20372037
2038- long safety = 0 ;
2038+ // Bound the wait by time, not by a poll count. How much wall time a fixed number
2039+ // of unthrottled getStreamInfo round trips buys depends entirely on the machine.
2040+ long timeoutAt = System .currentTimeMillis () + 10_000 ;
20392041 long gotZero = -1 ;
2040- while (++ safety < 10000 && errorLatch .getCount () > 0 ) {
2042+ while (System . currentTimeMillis () < timeoutAt && errorLatch .getCount () > 0 ) {
20412043 si = jsm .getStreamInfo (rawStream );
20422044 if (si .getStreamState ().getMsgCount () == 0 ) {
20432045 gotZero = System .currentTimeMillis ();
20442046 break ;
20452047 }
2048+ sleep (10 );
20462049 }
20472050 assertEquals (1 , errorLatch .getCount (), error .get ());
20482051 assertEquals (2 , messages .get ());
@@ -2058,14 +2061,15 @@ else if (mcount == 4) {
20582061 si = jsm .getStreamInfo (rawStream );
20592062 assertEquals (1 , si .getStreamState ().getMsgCount ());
20602063
2061- safety = 0 ;
2064+ timeoutAt = System . currentTimeMillis () + 10_000 ;
20622065 gotZero = -1 ;
2063- while (++ safety < 10000 && errorLatch .getCount () > 0 ) {
2066+ while (System . currentTimeMillis () < timeoutAt && errorLatch .getCount () > 0 ) {
20642067 si = jsm .getStreamInfo (rawStream );
20652068 if (si .getStreamState ().getMsgCount () == 0 ) {
20662069 gotZero = System .currentTimeMillis ();
20672070 break ;
20682071 }
2072+ sleep (10 );
20692073 }
20702074 assertEquals (1 , errorLatch .getCount (), error .get ());
20712075 assertEquals (4 , messages .get ());
@@ -2141,19 +2145,22 @@ else if (mcount == 4) {
21412145 StreamInfo si = jsm .getStreamInfo (rawStream );
21422146 assertEquals (1 , si .getStreamState ().getMsgCount ());
21432147
2144- kv .delete (key );
21452148 long mark = System .currentTimeMillis ();
2149+ kv .delete (key );
21462150 si = jsm .getStreamInfo (rawStream );
21472151 assertEquals (1 , si .getStreamState ().getMsgCount ());
21482152
2149- long safety = 0 ;
2153+ // Bound the wait by time, not by a poll count. How much wall time a fixed number
2154+ // of unthrottled getStreamInfo round trips buys depends entirely on the machine.
2155+ long timeoutAt = System .currentTimeMillis () + 10_000 ;
21502156 long gotZero = -1 ;
2151- while (++ safety < 10000 && errorLatch .getCount () > 0 ) {
2157+ while (System . currentTimeMillis () < timeoutAt && errorLatch .getCount () > 0 ) {
21522158 si = jsm .getStreamInfo (rawStream );
21532159 if (si .getStreamState ().getMsgCount () == 0 ) {
21542160 gotZero = System .currentTimeMillis ();
21552161 break ;
21562162 }
2163+ sleep (10 );
21572164 }
21582165 assertEquals (1 , errorLatch .getCount (), error .get ());
21592166 assertEquals (2 , messages .get ());
@@ -2165,14 +2172,15 @@ else if (mcount == 4) {
21652172 mark = System .currentTimeMillis ();
21662173 kv .purge (key );
21672174
2168- safety = 0 ;
2175+ timeoutAt = System . currentTimeMillis () + 10_000 ;
21692176 gotZero = -1 ;
2170- while (++ safety < 10000 && errorLatch .getCount () > 0 ) {
2177+ while (System . currentTimeMillis () < timeoutAt && errorLatch .getCount () > 0 ) {
21712178 si = jsm .getStreamInfo (rawStream );
21722179 if (si .getStreamState ().getMsgCount () == 0 ) {
21732180 gotZero = System .currentTimeMillis ();
21742181 break ;
21752182 }
2183+ sleep (10 );
21762184 }
21772185 assertEquals (1 , errorLatch .getCount (), error .get ());
21782186 assertEquals (4 , messages .get ());
0 commit comments