Skip to content

Commit

Permalink
Fixes #56 - "ready" event not emitted without warmup iterations.
Browse files Browse the repository at this point in the history
Now emitting the event when warmupIterations=0.

Signed-off-by: Simone Bordet <[email protected]>
  • Loading branch information
sbordet committed Feb 2, 2021
1 parent e9518f1 commit e9360fd
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 @@ -1144,8 +1144,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 @@ -1160,6 +1160,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 @@ -1179,7 +1182,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 e9360fd

Please sign in to comment.