Stabilize Flux.interval emissions in integration tests

After this commit the use of interval in tests is combined with
take(n).onBackpressureBuffer(n) to ensure emissions don't fail if the
fixed rate is exceeded (e.g. on slow CI server).

Tests that verify N number of items followed by verifyOnComplete()
should set the number of emissions to N.

Tests that verify N number of items followed by thenCancel() should
set the number of buffered to an arbitrary number greater than N.
This commit is contained in:
Rossen Stoyanchev
2018-02-06 11:01:19 -05:00
parent 41a4bdea55
commit 1653a32a04
7 changed files with 77 additions and 67 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2016 the original author or authors.
* Copyright 2002-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -17,6 +17,7 @@
package org.springframework.http.server.reactive;
import java.io.File;
import java.time.Duration;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@@ -24,6 +25,7 @@ import org.junit.After;
import org.junit.Before;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import reactor.core.publisher.Flux;
import org.springframework.http.server.reactive.bootstrap.HttpServer;
import org.springframework.http.server.reactive.bootstrap.JettyHttpServer;
@@ -73,4 +75,13 @@ public abstract class AbstractHttpHandlerIntegrationTests {
protected abstract HttpHandler createHttpHandler();
/**
* Return an interval stream of with n number of ticks and buffer the
* emissions to avoid back pressure failures (e.g. on slow CI server).
*/
public static Flux<Long> interval(Duration period, int count) {
return Flux.interval(period).take(count).onBackpressureBuffer(2);
}
}