Skip to content

Commit

Permalink
[MINOR] fix(test): Fix flaky test CoordinatorServerTest#test (#2332)
Browse files Browse the repository at this point in the history
### What changes were proposed in this pull request?

Fix flaky test CoordinatorServerTest#test

### Why are the changes needed?

Make CI stable.

### Does this PR introduce _any_ user-facing change?

No.

### How was this patch tested?

Existing UT.
  • Loading branch information
maobaolong authored Jan 9, 2025
1 parent 3ea5c2c commit 5b7d18c
Showing 1 changed file with 42 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,43 +36,52 @@ public void test() throws Exception {

CoordinatorServer cs1 = new CoordinatorServer(coordinatorConf);
CoordinatorServer cs2 = new CoordinatorServer(coordinatorConf);
cs1.start();

ExitUtils.disableSystemExit();
String expectMessage = "Fail to start jetty http server";
final int expectStatus = 1;
CoordinatorServer cs3 = null;
try {
cs2.start();
} catch (Exception e) {
assertTrue(e.getMessage().startsWith(expectMessage));
assertEquals(expectStatus, ((ExitException) e).getStatus());
} finally {
// Always call stopServer after new CoordinatorServer to shut down ExecutorService
cs2.stopServer();
}
cs1.start();

coordinatorConf.setInteger("rss.jetty.http.port", 9529);
cs2 = new CoordinatorServer(coordinatorConf);
expectMessage = "Fail to start grpc server";
try {
cs2.start();
} catch (Exception e) {
assertEquals(expectMessage, e.getMessage());
assertEquals(expectStatus, ((ExitException) e).getStatus());
ExitUtils.disableSystemExit();
String expectMessage = "Fail to start jetty http server";
final int expectStatus = 1;
try {
cs2.start();
} catch (Exception e) {
assertTrue(e.getMessage().startsWith(expectMessage));
assertEquals(expectStatus, ((ExitException) e).getStatus());
} finally {
// Always call stopServer after new CoordinatorServer to shut down ExecutorService
cs2.stopServer();
}

coordinatorConf.setInteger("rss.jetty.http.port", 9529);
cs3 = new CoordinatorServer(coordinatorConf);
expectMessage = "Fail to start grpc server";
try {
cs3.start();
} catch (Exception e) {
assertEquals(expectMessage, e.getMessage());
assertEquals(expectStatus, ((ExitException) e).getStatus());
} finally {
// Always call stopServer after new CoordinatorServer to shut down ExecutorService
cs2.stopServer();
cs1.stopServer();
}

final Thread t =
new Thread(
null,
() -> {
throw new AssertionError("TestUncaughtException");
},
"testThread");
t.start();
t.join();
} finally {
// Always call stopServer after new CoordinatorServer to shut down ExecutorService
cs2.stopServer();
cs1.stopServer();
cs2.stopServer();
if (cs3 != null) {
cs3.stopServer();
}
}

final Thread t =
new Thread(
null,
() -> {
throw new AssertionError("TestUncaughtException");
},
"testThread");
t.start();
t.join();
}
}

0 comments on commit 5b7d18c

Please sign in to comment.