Skip to content

Instantly share code, notes, and snippets.

@BacLuc
Created October 16, 2020 11:51
Show Gist options
  • Save BacLuc/c29adc3817b2ce0640a04306073f7669 to your computer and use it in GitHub Desktop.
Save BacLuc/c29adc3817b2ce0640a04306073f7669 to your computer and use it in GitHub Desktop.
@Test
public void cancel_task() throws InterruptedException {
LocalDateTime start = LocalDateTime.now();
Action action = () -> {
try {
Thread.sleep(1000);
} catch (InterruptedException ignored) {
}
};
Scheduler scheduler = Schedulers.from(Executors.newSingleThreadExecutor());
TestObserver<Void> test = Completable.fromAction(action).subscribeOn(scheduler).test();
Thread.sleep(50);
test.dispose();
test.assertNoErrors();
assertThat(start.plus(500, ChronoUnit.MILLIS).isAfter(LocalDateTime.now()), CoreMatchers.is(true));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment