Skip to content

Commit

Permalink
Improve virtual time scheduler:
Browse files Browse the repository at this point in the history
- always check current timed task on schedule with delay
- only create one worker for direct scheduling
  • Loading branch information
Stephane Maldini committed Jan 3, 2018
1 parent 7249011 commit 4ce8488
Showing 1 changed file with 57 additions and 1 deletion.
58 changes: 57 additions & 1 deletion src/test/java/reactor/ipc/netty/http/server/HttpServerTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 =
Expand Down Expand Up @@ -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.<Void>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();
}

}
}

0 comments on commit 4ce8488

Please sign in to comment.