File tree Expand file tree Collapse file tree 2 files changed +22
-6
lines changed
main/java/io/reactivex/rxjava3/internal/operators/single
test/java/io/reactivex/rxjava3/internal/operators/single Expand file tree Collapse file tree 2 files changed +22
-6
lines changed Original file line number Diff line number Diff line change @@ -113,11 +113,7 @@ public void onError(Throwable e) {
113113
114114 @ Override
115115 public void run () {
116- Disposable d = get ();
117- if (d != DisposableHelper .DISPOSED && compareAndSet (d , DisposableHelper .DISPOSED )) {
118- if (d != null ) {
119- d .dispose ();
120- }
116+ if (DisposableHelper .dispose (this )) {
121117 SingleSource <? extends T > other = this .other ;
122118 if (other == null ) {
123119 downstream .onError (new TimeoutException (timeoutMessage (timeout , unit )));
Original file line number Diff line number Diff line change 2828import io .reactivex .rxjava3 .functions .Action ;
2929import io .reactivex .rxjava3 .observers .TestObserver ;
3030import io .reactivex .rxjava3 .plugins .RxJavaPlugins ;
31- import io .reactivex .rxjava3 .schedulers .TestScheduler ;
31+ import io .reactivex .rxjava3 .schedulers .* ;
3232import io .reactivex .rxjava3 .subjects .*;
3333import io .reactivex .rxjava3 .testsupport .TestHelper ;
3434
@@ -255,4 +255,24 @@ protected void subscribeActual(@NonNull SingleObserver<? super @NonNull Integer>
255255
256256 assertTrue (d .isDisposed ());
257257 }
258+
259+ @ Test
260+ public void timeoutWithZero () throws InterruptedException {
261+ int n = 10_000 ;
262+ Scheduler sch = Schedulers .single ();
263+ for (int i = 0 ; i < n ; i ++) {
264+ final int y = i ;
265+ final CountDownLatch latch = new CountDownLatch (1 );
266+ Disposable d = Single .never ()
267+ .timeout (0 , TimeUnit .NANOSECONDS , sch )
268+ .subscribe (v -> {}, e -> {
269+ //System.out.println("timeout " + y);
270+ latch .countDown ();
271+ });
272+ if (!latch .await (2 , TimeUnit .SECONDS )) {
273+ System .out .println (d + " " + sch );
274+ throw new IllegalStateException ("Timeout did not work at y = " + y );
275+ }
276+ }
277+ }
258278}
You can’t perform that action at this time.
0 commit comments