1818import java .util .*;
1919import java .util .concurrent .*;
2020
21- import org .junit .Test ;
21+ import org .junit .* ;
2222
2323import io .reactivex .Scheduler .Worker ;
2424import io .reactivex .disposables .CompositeDisposable ;
@@ -109,10 +109,10 @@ public void testStartIdempotence() throws InterruptedException {
109109 System .out .println ("testStartIdempotence >> giving some time" );
110110 Thread .sleep (500 );
111111
112- Set <Thread > rxThreads = new HashSet <Thread >();
112+ Set <Thread > rxThreadsBefore = new HashSet <Thread >();
113113 for (Thread t : Thread .getAllStackTraces ().keySet ()) {
114114 if (t .getName ().startsWith ("Rx" )) {
115- rxThreads .add (t );
115+ rxThreadsBefore .add (t );
116116 System .out .println ("testStartIdempotence >> " + t );
117117 }
118118 }
@@ -121,14 +121,17 @@ public void testStartIdempotence() throws InterruptedException {
121121 System .out .println ("testStartIdempotence >> giving some time again" );
122122 Thread .sleep (500 );
123123
124- Set <Thread > rxThreads2 = new HashSet <Thread >();
124+ Set <Thread > rxThreadsAfter = new HashSet <Thread >();
125125 for (Thread t : Thread .getAllStackTraces ().keySet ()) {
126126 if (t .getName ().startsWith ("Rx" )) {
127- rxThreads2 .add (t );
127+ rxThreadsAfter .add (t );
128128 System .out .println ("testStartIdempotence >>>> " + t );
129129 }
130130 }
131+
132+ // cached threads may get dropped between the two checks
133+ rxThreadsAfter .removeAll (rxThreadsBefore );
131134
132- assertEquals ( rxThreads , rxThreads2 );
135+ Assert . assertTrue ( "Some new threads appeared: " + rxThreadsAfter , rxThreadsAfter . isEmpty () );
133136 }
134137}
0 commit comments