Skip to content

Commit da78d5c

Browse files
ahus1vietj
authored andcommitted
Stabilize test HttpBandwidthLimitingTest.testDynamicOutboundRateUpdateSharedServers
Only a server that has completed the listening is ready to update the traffic shaping. Closes #5863
1 parent b430d5b commit da78d5c

File tree

2 files changed

+16
-15
lines changed

2 files changed

+16
-15
lines changed

src/main/java/io/vertx/core/net/impl/TCPServerBase.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,9 @@ public void updateTrafficShapingOptions(TrafficShapingOptions options) {
148148
if (options == null) {
149149
throw new IllegalArgumentException("Invalid null value passed for traffic shaping options update");
150150
}
151+
if (!listening) {
152+
throw new IllegalStateException("Listening initialization not completed yet");
153+
}
151154
TCPServerBase server = actualServer;
152155
// Update the traffic shaping options only for the actual/main server
153156
if (server != null && server != this) {
@@ -189,7 +192,6 @@ private synchronized Future<Channel> listen(SocketAddress localAddress, ContextI
189192
}
190193

191194
this.listenContext = context;
192-
this.listening = true;
193195
this.eventLoop = context.nettyEventLoop();
194196

195197
SocketAddress bindAddress;
@@ -285,7 +287,7 @@ private synchronized Future<Channel> listen(SocketAddress localAddress, ContextI
285287
}
286288
listening = false;
287289
});
288-
290+
this.listening = true;
289291
return bindFuture;
290292
} else {
291293
// Server already exists with that host/port - we will use that
@@ -298,6 +300,7 @@ private synchronized Future<Channel> listen(SocketAddress localAddress, ContextI
298300
actualServer.channelBalancer.addWorker(eventLoop, worker);
299301
listenContext.addCloseHook(this);
300302
main.bindFuture.onComplete(promise);
303+
this.listening = true;
301304
return promise.future();
302305
}
303306
}

src/test/java/io/vertx/core/http/HttpBandwidthLimitingTest.java

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -213,28 +213,26 @@ public void testDynamicOutboundRateUpdateSharedServers() throws IOException, Int
213213
public void start(Promise<Void> startPromise) throws Exception
214214
{
215215
HttpServer testServer = serverFactory.apply(vertx);
216-
servers.add(testServer);
217216
testServer.requestHandler(HANDLERS.getFile(sampleF))
218217
.listen(DEFAULT_HTTP_PORT, DEFAULT_HTTP_HOST).onComplete(res -> {
219218
if (res.succeeded()) {
219+
servers.add(testServer);
220220
// Apply traffic shaping options after the server has started
221221
TrafficShapingOptions updatedTrafficOptions = new TrafficShapingOptions()
222222
.setInboundGlobalBandwidth(INBOUND_LIMIT)
223223
.setOutboundGlobalBandwidth(2 * OUTBOUND_LIMIT);
224224

225225
List<Promise<Void>> promises = new ArrayList<>();
226-
for (int i = 0; i < numEventLoops; i++) {
227-
servers.forEach(s -> {
228-
Promise<Void> promise = Promise.promise();
229-
try {
230-
s.updateTrafficShapingOptions(updatedTrafficOptions);
231-
promise.complete();
232-
} catch (Exception e) {
233-
promise.fail(e);
234-
}
235-
promises.add(promise);
236-
});
237-
}
226+
servers.forEach(s -> {
227+
Promise<Void> promise = Promise.promise();
228+
try {
229+
s.updateTrafficShapingOptions(updatedTrafficOptions);
230+
promise.complete();
231+
} catch (Exception e) {
232+
promise.fail(e);
233+
}
234+
promises.add(promise);
235+
});
238236
// Ensure all traffic shaping updates complete before resolving the startPromise
239237
Future.all(promises.stream().map(Promise::future).collect(Collectors.toList()))
240238
.onSuccess(v -> startPromise.complete())

0 commit comments

Comments
 (0)