Skip to content

Commit

Permalink
Merge pull request #57 from jetty-project/issue_56_no_ready_for_no_wa…
Browse files Browse the repository at this point in the history
…rmup

Fixes #56 - "ready" event not emitted without warmup iterations.
  • Loading branch information
sbordet authored Feb 2, 2021
2 parents 102cbdf + e9360fd commit f06cec1
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1192,8 +1192,8 @@ private class WarmupCallback extends Callback.Nested {
public WarmupCallback(Callback callback, int warmupIterations) {
super(callback);
latch = new CountDownLatch(warmupIterations == 0 ? 0 : 1);
counter = warmupIterations == 0 ? Callback.from(NOOP::succeeded, callback::failed) :
new CountingCallback(Callback.from(this::success, this::failure), warmupIterations);
// If there are no warmup iterations, the callback will never be invoked.
counter = warmupIterations == 0 ? NOOP : new CountingCallback(Callback.from(this::success, this::failure), warmupIterations);
}

@Override
Expand All @@ -1208,6 +1208,9 @@ public void failed(Throwable x) {

public void join() {
try {
if (counter == NOOP) {
fireReadyEvent();
}
latch.await();
} catch (InterruptedException x) {
throw new RuntimeException(x);
Expand All @@ -1227,7 +1230,8 @@ private void success() {
LOGGER.debug("awaiting barrier for ready listener");
}
awaitBarrier();
// Do not succeed the nested callback, as these are just warmup iterations.
// Do not forward success the nested callback,
// as these are just warmup iterations.
} finally {
latch.countDown();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -505,6 +505,27 @@ public void testReadyEvent() throws Exception {
Assert.assertEquals(threads * count, resources.get());
}

@Test
public void testReadyEventWithoutWarmup() throws Exception {
startServer(new TestHandler());

int threads = 2;
int count = 30;
CountDownLatch readyLatch = new CountDownLatch(1);
LoadGenerator loadGenerator = LoadGenerator.builder()
.port(connector.getLocalPort())
.httpClientTransportBuilder(clientTransportBuilder)
.threads(threads)
.iterationsPerThread(count)
.resourceRate(0)
.listener((LoadGenerator.ReadyListener)g -> readyLatch.countDown())
.build();

loadGenerator.begin().get();

Assert.assertTrue(readyLatch.await(5, TimeUnit.SECONDS));
}

private enum TransportType {
H1C, H2C
}
Expand Down

0 comments on commit f06cec1

Please sign in to comment.