Skip to content

Commit

Permalink
[test](fe-ut) fix unstable MysqlServerTest
Browse files Browse the repository at this point in the history
  • Loading branch information
morningman committed Nov 23, 2023
1 parent 3be12f7 commit 840b48b
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

import org.apache.doris.qe.ConnectContext;
import org.apache.doris.qe.ConnectScheduler;
import org.apache.doris.utframe.TestWithFeService;

import mockit.Delegate;
import mockit.Expectations;
Expand All @@ -31,7 +32,6 @@

import java.io.IOException;
import java.net.InetSocketAddress;
import java.net.ServerSocket;
import java.nio.channels.SocketChannel;

public class MysqlServerTest {
Expand Down Expand Up @@ -79,10 +79,7 @@ public Boolean answer() throws Throwable {

@Test
public void testNormal() throws IOException, InterruptedException {
ServerSocket socket = new ServerSocket(0);
int port = socket.getLocalPort();
socket.close();

int port = TestWithFeService.findValidPort();
MysqlServer server = new MysqlServer(port, scheduler);
Assert.assertTrue(server.start());

Expand All @@ -108,9 +105,7 @@ public void testNormal() throws IOException, InterruptedException {

@Test
public void testBindFail() throws IOException {
ServerSocket socket = new ServerSocket(0);
int port = socket.getLocalPort();
socket.close();
int port = TestWithFeService.findValidPort();
MysqlServer server = new MysqlServer(port, scheduler);
Assert.assertTrue(server.start());
MysqlServer server1 = new MysqlServer(port, scheduler);
Expand All @@ -121,9 +116,7 @@ public void testBindFail() throws IOException {

@Test
public void testSubFail() throws IOException, InterruptedException {
ServerSocket socket = new ServerSocket(0);
int port = socket.getLocalPort();
socket.close();
int port = TestWithFeService.findValidPort();
MysqlServer server = new MysqlServer(port, badScheduler);
Assert.assertTrue(server.start());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -495,7 +495,7 @@ protected void cleanDorisFeDir() {
}
}

protected int findValidPort() {
public static int findValidPort() {
int port = 0;
while (true) {
try (ServerSocket socket = new ServerSocket(0)) {
Expand Down

0 comments on commit 840b48b

Please sign in to comment.