File tree Expand file tree Collapse file tree
soul-common/src/test/java/org/dromara/soul/common/utils Expand file tree Collapse file tree Original file line number Diff line number Diff line change 3535 */
3636public final class UpstreamCheckUtilsTest {
3737
38+ private volatile int port = -1 ;
39+
3840 @ Test
3941 public void testBlank () {
4042 assertFalse (UpstreamCheckUtils .checkUrl ("" ));
@@ -56,17 +58,22 @@ public void testSocketConnect() {
5658 Runnable runnable = () -> {
5759 ServerSocket serverSocket ;
5860 try {
59- serverSocket = new ServerSocket (13098 );
61+ serverSocket = new ServerSocket (0 );
62+ port = serverSocket .getLocalPort ();
6063 Socket socket = serverSocket .accept ();
6164 socket .close ();
6265 } catch (IOException e ) {
6366 e .printStackTrace ();
6467 }
6568 };
6669 new Thread (runnable ).start ();
67- Thread .sleep (100 );
68- assertTrue (UpstreamCheckUtils .checkUrl ("127.0.0.1:13098" ));
69- assertFalse (UpstreamCheckUtils .checkUrl ("http://127.0.0.1:13099" ));
70- assertTrue (UpstreamCheckUtils .checkUrl ("http://127.0.0.1:13098" ));
70+
71+ while (port == -1 ) {
72+ Thread .yield ();
73+ }
74+
75+ assertTrue (UpstreamCheckUtils .checkUrl ("127.0.0.1:" + port ));
76+ assertFalse (UpstreamCheckUtils .checkUrl ("http://127.0.0.1:" + (port == 0 ? port + 1 : port - 1 )));
77+ assertTrue (UpstreamCheckUtils .checkUrl ("http://127.0.0.1:" + port ));
7178 }
7279}
You can’t perform that action at this time.
0 commit comments