18
18
import java .util .*;
19
19
import java .util .concurrent .*;
20
20
21
- import org .junit .Test ;
21
+ import org .junit .* ;
22
22
23
23
import io .reactivex .Scheduler .Worker ;
24
24
import io .reactivex .disposables .CompositeDisposable ;
@@ -109,10 +109,10 @@ public void testStartIdempotence() throws InterruptedException {
109
109
System .out .println ("testStartIdempotence >> giving some time" );
110
110
Thread .sleep (500 );
111
111
112
- Set <Thread > rxThreads = new HashSet <Thread >();
112
+ Set <Thread > rxThreadsBefore = new HashSet <Thread >();
113
113
for (Thread t : Thread .getAllStackTraces ().keySet ()) {
114
114
if (t .getName ().startsWith ("Rx" )) {
115
- rxThreads .add (t );
115
+ rxThreadsBefore .add (t );
116
116
System .out .println ("testStartIdempotence >> " + t );
117
117
}
118
118
}
@@ -121,14 +121,17 @@ public void testStartIdempotence() throws InterruptedException {
121
121
System .out .println ("testStartIdempotence >> giving some time again" );
122
122
Thread .sleep (500 );
123
123
124
- Set <Thread > rxThreads2 = new HashSet <Thread >();
124
+ Set <Thread > rxThreadsAfter = new HashSet <Thread >();
125
125
for (Thread t : Thread .getAllStackTraces ().keySet ()) {
126
126
if (t .getName ().startsWith ("Rx" )) {
127
- rxThreads2 .add (t );
127
+ rxThreadsAfter .add (t );
128
128
System .out .println ("testStartIdempotence >>>> " + t );
129
129
}
130
130
}
131
+
132
+ // cached threads may get dropped between the two checks
133
+ rxThreadsAfter .removeAll (rxThreadsBefore );
131
134
132
- assertEquals ( rxThreads , rxThreads2 );
135
+ Assert . assertTrue ( "Some new threads appeared: " + rxThreadsAfter , rxThreadsAfter . isEmpty () );
133
136
}
134
137
}
0 commit comments