File tree Expand file tree Collapse file tree 1 file changed +44
-0
lines changed
rxjava-core/src/test/java/rx/subscriptions Expand file tree Collapse file tree 1 file changed +44
-0
lines changed Original file line number Diff line number Diff line change @@ -163,4 +163,48 @@ public void run() {
163
163
t .join ();
164
164
}
165
165
}
166
+
167
+ @ Test
168
+ public void concurrentSetSubscriptionShouldNotInterleave ()
169
+ throws InterruptedException {
170
+ final int count = 10 ;
171
+ final List <Subscription > subscriptions = new ArrayList <Subscription >();
172
+
173
+ final CountDownLatch start = new CountDownLatch (1 );
174
+ final CountDownLatch end = new CountDownLatch (count );
175
+
176
+ final List <Thread > threads = new ArrayList <Thread >();
177
+ for (int i = 0 ; i < count ; i ++) {
178
+ final Subscription subscription = mock (Subscription .class );
179
+ subscriptions .add (subscription );
180
+
181
+ final Thread t = new Thread () {
182
+ @ Override
183
+ public void run () {
184
+ try {
185
+ start .await ();
186
+ serialSubscription .setSubscription (subscription );
187
+ } catch (InterruptedException e ) {
188
+ fail (e .getMessage ());
189
+ } finally {
190
+ end .countDown ();
191
+ }
192
+ }
193
+ };
194
+ t .start ();
195
+ threads .add (t );
196
+ }
197
+
198
+ start .countDown ();
199
+ end .await ();
200
+ serialSubscription .unsubscribe ();
201
+
202
+ for (final Subscription subscription : subscriptions ) {
203
+ verify (subscription ).unsubscribe ();
204
+ }
205
+
206
+ for (final Thread t : threads ) {
207
+ t .join ();
208
+ }
209
+ }
166
210
}
You can’t perform that action at this time.
0 commit comments