use of reactor.core.publisher.Signal in project reactor-core by reactor.
the class FluxTests method endLessTimer.
/**
* This test case demonstrates a silent failure of {@link Flux#interval(Duration)}
* when a resolution is specified that
* is less than the backing {@link Timer} class.
*
* @throws InterruptedException - on failure.
* @throws TimeoutException - on failure. <p> by @masterav10 : https://github.com/reactor/reactor/issues/469
*/
@Test
@Ignore
public void endLessTimer() throws InterruptedException, TimeoutException {
int tasks = 50;
// XXX: Fails when less than 100
long delayMS = 50;
Phaser barrier = new Phaser(tasks + 1);
List<Long> times = new ArrayList<>();
// long localTime = System.currentTimeMillis(); for java 7
long localTime = Instant.now().toEpochMilli();
long elapsed = System.nanoTime();
Disposable ctrl = Flux.interval(Duration.ofMillis(delayMS)).log("test").map((signal) -> {
return TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - elapsed);
}).doOnNext((elapsedMillis) -> {
times.add(localTime + elapsedMillis);
barrier.arrive();
}).subscribe();
barrier.awaitAdvanceInterruptibly(barrier.arrive(), tasks * delayMS + 1000, TimeUnit.MILLISECONDS);
ctrl.dispose();
Assert.assertEquals(tasks, times.size());
for (int i = 1; i < times.size(); i++) {
Long prev = times.get(i - 1);
Long time = times.get(i);
Assert.assertTrue(prev > 0);
Assert.assertTrue(time > 0);
Assert.assertTrue("was " + (time - prev), time - prev <= delayMS * 1.2);
}
}
Aggregations