Skip to content

Commit

Permalink
Update test to link traffic-shaping updates to existing promise
Browse files Browse the repository at this point in the history
  • Loading branch information
arjunashok committed Jan 10, 2025
1 parent d953175 commit 23b4f45
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions src/test/java/io/vertx/core/http/HttpBandwidthLimitingTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicLong;
import java.util.function.Function;
import java.util.stream.Collectors;

import io.vertx.core.AbstractVerticle;
import io.vertx.core.DeploymentOptions;
Expand Down Expand Up @@ -225,10 +226,23 @@ public void start(Promise<Void> startPromise) throws Exception
.setInboundGlobalBandwidth(INBOUND_LIMIT)
.setOutboundGlobalBandwidth(2 * OUTBOUND_LIMIT);

List<Promise<Void>> promises = new ArrayList<>();
for (int i = 0; i < numEventLoops; i++) {
servers.forEach(s -> s.updateTrafficShapingOptions(updatedTrafficOptions));
servers.forEach(s -> {
Promise<Void> promise = Promise.promise();
try {
s.updateTrafficShapingOptions(updatedTrafficOptions);
promise.complete();
} catch (Exception e) {
promise.fail(e);
}
promises.add(promise);
});
}
startPromise.complete();
// Ensure all traffic shaping updates complete before resolving the startPromise
Future.all(promises.stream().map(Promise::future).collect(Collectors.toList()))
.onSuccess(v -> startPromise.complete())
.onFailure(startPromise::fail);
} else {
startPromise.fail(res.cause());
}
Expand Down Expand Up @@ -257,7 +271,6 @@ public void start(Promise<Void> startPromise) throws Exception
}
}));
awaitLatch(waitForResponse);

long elapsedMillis = TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - startTime.get());
Assert.assertTrue(elapsedMillis < expectedUpperBoundTimeMillis(totalReceivedLength.get(), OUTBOUND_LIMIT));
}
Expand Down

0 comments on commit 23b4f45

Please sign in to comment.