Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import io.reactivex.rxjava4.disposables.StreamerCancellation;
import io.reactivex.rxjava4.exceptions.Exceptions;
import io.reactivex.rxjava4.functions.*;
import io.reactivex.rxjava4.internal.util.ExceptionHelper;

public record StreamableUsing<T, R>(
Supplier<? extends R> resourceSupplier,
Expand Down Expand Up @@ -80,11 +81,14 @@ static final class UsingStreamer<T, R> implements Streamer<T> {
cleanup = null;
c.run();
} catch (Throwable ex) {
Exceptions.throwIfFatal(e);
cf.completeExceptionally(ex);
return;
Exceptions.throwIfFatal(ex);
e = ExceptionHelper.unwrapAndCombine(e, ex);
}
if (e != null) {
cf.completeExceptionally(e);
} else {
cf.complete(null);
}
cf.complete(null);
});
return cf;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,4 +87,29 @@ public void resourceCleanerCrash() throws Throwable {
.awaitDone(5, TimeUnit.SECONDS)
.assertFailure(TestException.class, 5, 6, 7, 8, 9);
}

@Test
public void upstreamFinishCrash() {
var resource = new AtomicReference<Integer>();

Streamable.using(() -> 1, _ -> StreamableFailingFinish.MAIN_COMPLETES, resource::set)
.test()
.awaitDone(5, TimeUnit.SECONDS)
.assertFailure(TestException.class)
.assertError(e -> e.getMessage().equals("StreamableFailingFinish.finish()"));

assertEquals(1, resource.get(), "resource cleanup mismatch");
}

@Test
public void upstreamFinishAndResourceCleanerCrash() {
var cleanerError = new TestException("resourceCleaner");

Streamable.using(() -> 1, _ -> StreamableFailingFinish.MAIN_COMPLETES, _ -> { throw cleanerError; })
.test()
.awaitDone(5, TimeUnit.SECONDS)
.assertFailure(TestException.class)
.assertError(e -> e.getMessage().equals("StreamableFailingFinish.finish()"))
.assertError(e -> e.getSuppressed().length == 1 && e.getSuppressed()[0] == cleanerError);
}
}
Loading