Created
October 16, 2020 11:51
-
-
Save BacLuc/c29adc3817b2ce0640a04306073f7669 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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