Skip to content

Commit

Permalink
[test] Speed up TestControllerClient#testControllerClientWithInvalidU…
Browse files Browse the repository at this point in the history
…rls (#1395)

This test is validating that as long as at least one of the hosts in the Controller urls is healthy, the "ControllerClient" won't see a "ConnectException". However, the "ControllerClient" will randomize the controller order in every request, it is not deterministic that a single run will ever attempt to communicate with the unavailable controller. Our tests are also configured to retry failing tests multiple times, and if any of them passes, it assumes the test is good. So, regressions in this logic could get missed by our team. To prevent this, the test runs the test for 100 iterations.

However, this leads to a case where the test is running for 13 minutes on CI hosts. To speed up the test, we do two things:
1. Reduce the number of iterations to 50
2. Parallelize the loop to concurrently attempt multiple times
  • Loading branch information
nisargthakkar authored Dec 14, 2024
1 parent e27379d commit ed335b8
Showing 1 changed file with 4 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import java.io.IOException;
import java.net.ConnectException;
import java.util.Optional;
import java.util.stream.IntStream;
import org.testng.Assert;
import org.testng.annotations.Test;

Expand Down Expand Up @@ -170,9 +171,9 @@ public void testControllerClientWithInvalidUrls() throws IOException {
discoResponseInvalidControllers.getError());

// When only some controllers are missing, the ConnectException should never be bubbled up. Since this behavior is
// triggered from Java libs, and we randomise the controller list to do some load balancing, the best way to
// triggered from Java libs, and we randomize the controller list to do some load balancing, the best way to
// validate is to try multiple invocations
for (int i = 0; i < 100; i++) {
IntStream.rangeClosed(1, 50).parallel().forEach(i -> {
D2ServiceDiscoveryResponse discoResponsePartialValidController = ControllerClient
.discoverCluster(nonExistentControllerUrl1 + "," + validControllerUrl, storeName, Optional.empty(), 1);
Assert.assertFalse(discoResponsePartialValidController.isError());
Expand Down Expand Up @@ -217,7 +218,7 @@ public void testControllerClientWithInvalidUrls() throws IOException {
1);
Assert.assertTrue(errorDiscoResponseInvalidAndLegacy.isError());
Assert.assertEquals(errorDiscoResponseInvalidAndLegacy.getErrorType(), ErrorType.BAD_REQUEST);
}
});

try (ControllerClient controllerClient =
ControllerClientFactory.getControllerClient(clusterName, validControllerUrl, Optional.empty())) {
Expand Down

0 comments on commit ed335b8

Please sign in to comment.