From 4ce84880d5b31c98913e39c93f7f170c53d37d69 Mon Sep 17 00:00:00 2001 From: Stephane Maldini Date: Tue, 2 Jan 2018 16:57:27 -0800 Subject: [PATCH] Improve virtual time scheduler: - always check current timed task on schedule with delay - only create one worker for direct scheduling --- .../netty/http/server/HttpServerTests.java | 58 ++++++++++++++++++- 1 file changed, 57 insertions(+), 1 deletion(-) diff --git a/src/test/java/reactor/ipc/netty/http/server/HttpServerTests.java b/src/test/java/reactor/ipc/netty/http/server/HttpServerTests.java index 2ba6574618..6e3f611696 100644 --- a/src/test/java/reactor/ipc/netty/http/server/HttpServerTests.java +++ b/src/test/java/reactor/ipc/netty/http/server/HttpServerTests.java @@ -65,6 +65,7 @@ import reactor.core.publisher.Flux; import reactor.core.publisher.FluxSink; import reactor.core.publisher.Mono; +import reactor.core.scheduler.Schedulers; import reactor.ipc.netty.ByteBufFlux; import reactor.ipc.netty.FutureMono; import reactor.ipc.netty.NettyContext; @@ -256,7 +257,7 @@ public void sendFileAsync() throws IOException, URISyntaxException { byte[] fileBytes = Files.readAllBytes(largeFile); for (int i = 0; i < 1000; i++) { Files.write(tempFile, fileBytes, StandardOpenOption.APPEND); - }; + } ByteBufAllocator allocator = ByteBufAllocator.DEFAULT; AsynchronousFileChannel channel = @@ -830,4 +831,59 @@ public void testConnectionCloseOnServerError() throws Exception { r.dispose(); server.dispose(); } + + final int numberOfTests = 1000; + + @Test + public void deadlockWhenRedirectsToSameUrl(){ + redirectTests("/login"); + } + + @Test + public void okWhenRedirectsToOther(){ + redirectTests("/other"); + } + + public void redirectTests(String url) { + NettyContext server = HttpServer.create(9999) + .newHandler((req, res) -> { + if (req.uri() + .contains("/login") && req.method() + .equals(HttpMethod.POST)) { + return Mono.fromRunnable(() -> { + res.header("Location", + "http://localhost:9999" + + url).status(HttpResponseStatus.FOUND); + }) + .publishOn(Schedulers.elastic()); + } + else { + return Mono.fromRunnable(() -> { + }) + .publishOn(Schedulers.elastic()) + .then(res.status(200) + .sendHeaders() + .then()); + } + }) + .block(Duration.ofSeconds(300)); + + PoolResources pool = PoolResources.fixed("test", 1); + + HttpClient client = + HttpClient.create(ops -> ops.connectAddress(() -> server.address()) + .poolResources(pool)); + + try { + Flux.range(0, this.numberOfTests) + .concatMap(i -> client.post("/login", r -> r.followRedirect()) + .flatMap(r -> r.receive() + .then())) + .blockLast(); + } + finally { + server.dispose(); + } + + } }