Skip to content

Commit

Permalink
[BugFix] fix FE UT http port conflict when running in parallel (#34865)
Browse files Browse the repository at this point in the history
Signed-off-by: Kevin Cai <caixiaohua@starrocks.com>
  • Loading branch information
kevincai authored Nov 13, 2023
1 parent 6226db5 commit 4982697
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,15 @@ public abstract class StarRocksHttpTestCase {
@Mocked
private static EditLog editLog;

public static int detectUsableSocketPort() {
try (ServerSocket socket = new ServerSocket(0)) {
socket.setReuseAddress(true);
return socket.getLocalPort();
} catch (Exception e) {
throw new IllegalStateException("Could not find a free TCP/IP port");
}
}

public static OlapTable newTable(String name) {
GlobalStateMgr.getCurrentInvertedIndex().clear();
Column k1 = new Column("k1", Type.BIGINT);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
public class TransactionLoadActionOnSharedDataClusterTest extends StarRocksHttpTestCase {

private static HttpServer beServer;
private static int TEST_HTTP_PORT = 0;

@Override
@Before
Expand All @@ -58,7 +59,7 @@ public RunMode getCurrentRunMode() {
ComputeNode computeNode = new ComputeNode(1234, "localhost", 8040);
computeNode.setBePort(9300);
computeNode.setAlive(true);
computeNode.setHttpPort(9737);
computeNode.setHttpPort(TEST_HTTP_PORT);
GlobalStateMgr.getCurrentSystemInfo().addComputeNode(computeNode);
new MockUp<GlobalStateMgr>() {
@Mock
Expand All @@ -79,7 +80,8 @@ public static void close() {

@BeforeClass
public static void initBeServer() throws IllegalArgException, InterruptedException {
beServer = new HttpServer(9737);
TEST_HTTP_PORT = detectUsableSocketPort();
beServer = new HttpServer(TEST_HTTP_PORT);
BaseAction ac = new BaseAction(beServer.getController()) {

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,15 @@
public class TransactionLoadActionTest extends StarRocksHttpTestCase {

private static HttpServer beServer;
private static int TEST_HTTP_PORT = 0;

@Override
@Before
public void setUp() {
Backend backend4 = new Backend(1234, "localhost", 8040);
backend4.setBePort(9300);
backend4.setAlive(true);
backend4.setHttpPort(9737);
backend4.setHttpPort(TEST_HTTP_PORT);
backend4.setDisks(new ImmutableMap.Builder<String, DiskInfo>().put("1", new DiskInfo("")).build());
GlobalStateMgr.getCurrentSystemInfo().addBackend(backend4);
new MockUp<GlobalStateMgr>() {
Expand All @@ -73,7 +74,9 @@ public static void close() {

@BeforeClass
public static void initBeServer() throws IllegalArgException, InterruptedException {
beServer = new HttpServer(9737);
TEST_HTTP_PORT = detectUsableSocketPort();

beServer = new HttpServer(TEST_HTTP_PORT);
BaseAction ac = new BaseAction(beServer.getController()) {

@Override
Expand Down

0 comments on commit 4982697

Please sign in to comment.