Skip to content

Wrap InterruptedException with an unchecked exception in TestSubscriber#awaitValueCount(). #4453

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 1, 2016
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
10 changes: 7 additions & 3 deletions src/main/java/rx/observers/TestSubscriber.java
Original file line number Diff line number Diff line change
Expand Up @@ -355,13 +355,17 @@ private void assertItem(T expected, int i) {
* @param timeout the time to wait for the events
* @param unit the time unit of waiting
* @return true if the expected number of onNext events happened
* @throws InterruptedException if the sleep is interrupted
* @throws RuntimeException if the sleep is interrupted
* @since (if this graduates from Experimental/Beta to supported, replace this parenthetical with the release number)
*/
@Experimental
public final boolean awaitValueCount(int expected, long timeout, TimeUnit unit) throws InterruptedException {
public final boolean awaitValueCount(int expected, long timeout, TimeUnit unit) {
while (timeout != 0 && valueCount < expected) {
unit.sleep(1);
try {
unit.sleep(1);
} catch (InterruptedException e) {
throw new IllegalStateException("Interrupted", e);
}
timeout--;
}
return valueCount >= expected;
Expand Down
4 changes: 2 additions & 2 deletions src/test/java/rx/observers/TestSubscriberTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -750,7 +750,7 @@ public void completionCount() {
}

@Test
public void awaitValueCount() throws Exception {
public void awaitValueCount() {
TestSubscriber<Integer> ts = TestSubscriber.create();

Observable.range(1, 5).delay(100, TimeUnit.MILLISECONDS)
Expand All @@ -763,7 +763,7 @@ public void awaitValueCount() throws Exception {
}

@Test
public void awaitValueCountFails() throws Exception {
public void awaitValueCountFails() {
TestSubscriber<Integer> ts = TestSubscriber.create();

Observable.range(1, 2).delay(100, TimeUnit.MILLISECONDS)
Expand Down