Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed flappers and test_SSLHandshakeFirst by skipping if server is < 2.10.0 #784

Merged
merged 2 commits into from
Aug 8, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 17 additions & 10 deletions test/test.c
Original file line number Diff line number Diff line change
Expand Up @@ -7847,7 +7847,7 @@ void test_AssignSubToDispatch(void)
{
testf("%d subs over %d threads: Verify that the dispatchers have been assigned: ", tc->numSubs, tc->expectedDispatchers);
for (i = 0; (s == NATS_OK) && (i < tc->numSubs); i++)
{
{
natsSub_Lock(subs[i]);
if (subs[i]->dispatcher != &pool->dispatchers[i % tc->expectedDispatchers])
s = NATS_ERR;
Expand Down Expand Up @@ -18352,7 +18352,7 @@ void test_GetClientID(void)
testCond(true);
return;
}
pid1 = _startServer("nats://127.0.0.1:4222", "-cluster nats://127.0.0.1:6222 -cluster_name abc", true);
pid1 = _startServer("nats://127.0.0.1:4222", "-a 127.0.0.1 -p 4222 -cluster nats://127.0.0.1:6222 -cluster_name abc", true);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kozlovic is this (extra server flags) a windows-specific fix?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not really. When we just specify the port, the server uses 0.0.0.0 for the TCP listen address, which then can resolve to multiple IPs that are sent to the client through gossip protocol. What I have seen (in my Windows VM, and probably what is happening on Windows CI) is that the server would return multiple addresses (say 192.168.x.y but also 10.5.x.y, etc..), which "interfere" with the tests expectations. On Linux or other CIs that we are running it on, there was probably nothing returned (maybe it is 127.0.0.1).
So the "fix" is not really Windows specific. It is simply making the test more deterministic.

CHECK_SERVER_STARTED(pid1);

test("Create nc1: ");
Expand All @@ -18371,7 +18371,7 @@ void test_GetClientID(void)
testCond((s == NATS_OK) && (cid != 0));

test("Wait for discovered callback: ");
pid2 = _startServer("nats://127.0.0.1:4223", "-p 4223 -cluster nats://127.0.0.1:6223 -cluster_name abc -routes nats://127.0.0.1:6222", true);
pid2 = _startServer("nats://127.0.0.1:4223", "-a 127.0.0.1 -p 4223 -cluster nats://127.0.0.1:6223 -cluster_name abc -routes nats://127.0.0.1:6222", true);
CHECK_SERVER_STARTED(pid2);

natsMutex_Lock(arg.m);
Expand Down Expand Up @@ -21289,6 +21289,16 @@ void test_SSLHandshakeFirst(void)
natsOptions *opts = NULL;
natsPid serverPid = NATS_INVALID_PID;

if (!serverVersionAtLeast(2, 10, 0))
{
char txt[200];

snprintf(txt, sizeof(txt), "Skipping since requires server version of at least 2.10.0, got %s: ", serverVersion);
test(txt);
testCond(true);
return;
}

serverPid = _startServer("nats://127.0.0.1:4443", "-config tlsfirst.conf", true);
CHECK_SERVER_STARTED(serverPid);

Expand Down Expand Up @@ -21411,18 +21421,15 @@ void test_SSLReconnectWithAuthError(void)
IFOK(s, natsOptions_SetTimeout(opts, 250));
IFOK(s, natsOptions_SetMaxReconnect(opts, 1000));
IFOK(s, natsOptions_SetReconnectWait(opts, 100));
IFOK(s, natsOptions_SetReconnectJitter(opts, 0, 0));
IFOK(s, natsOptions_SetClosedCB(opts, _closedCb, (void*) &args));
IFOK(s, natsOptions_SetServers(opts, (const char*[2]){"tls://user:pwd@127.0.0.1:4443", "tls://bad:pwd@127.0.0.1:4444"}, 2));
IFOK(s, natsOptions_SetNoRandomize(opts, true));
IFOK(s, natsOptions_SetIgnoreDiscoveredServers(opts, true));
if (opts == NULL)
FAIL("Unable to create reconnect options!");

pid1 = _startServer("nats://127.0.0.1:4443", "-p 4443 -cluster_name abc -cluster nats://127.0.0.1:6222 -tls -tlscert certs/server-cert.pem -tlskey certs/server-key.pem -tlscacert certs/ca.pem -user user -pass pwd", true);
pid1 = _startServer("nats://127.0.0.1:4443", "-a 127.0.0.1 -p 4443 -cluster_name abc -cluster nats://127.0.0.1:6222 -tls -tlscert certs/server-cert.pem -tlskey certs/server-key.pem -tlscacert certs/ca.pem -user user -pass pwd", true);
CHECK_SERVER_STARTED(pid1);

pid2 = _startServer("nats://127.0.0.1:4444", "-p 4444 -cluster_name abc -cluster nats://127.0.0.1:6223 -routes nats://127.0.0.1:6222 -tls -tlscert certs/server-cert.pem -tlskey certs/server-key.pem -tlscacert certs/ca.pem -user user -pass pwd", true);
pid2 = _startServer("nats://127.0.0.1:4444", "-a 127.0.0.1 -p 4444 -cluster_name abc -cluster nats://127.0.0.1:6223 -routes nats://127.0.0.1:6222 -tls -tlscert certs/server-cert.pem -tlskey certs/server-key.pem -tlscacert certs/ca.pem -user user -pass pwd", true);
CHECK_SERVER_STARTED(pid2);

test("Connect to server1: ");
Expand Down Expand Up @@ -21636,7 +21643,7 @@ void test_ReconnectImplicitUserInfo(void)
"}\n"\
"no_auth_user: b\n");
test("Start server1: ");
snprintf(cmdLine, sizeof(cmdLine), "-cluster_name \"local\" -cluster nats://127.0.0.1:6222 -c %s", conf);
snprintf(cmdLine, sizeof(cmdLine), "-a 127.0.0.1 -p 4222 -cluster_name \"local\" -cluster nats://127.0.0.1:6222 -c %s", conf);
pid1 = _startServer("nats://127.0.0.1:4222", cmdLine, true);
CHECK_SERVER_STARTED(pid1);
testCond(true);
Expand All @@ -21652,7 +21659,7 @@ void test_ReconnectImplicitUserInfo(void)
testCond(s == NATS_OK);

test("Start server2: ");
snprintf(cmdLine, sizeof(cmdLine), "-p 4223 -cluster_name \"local\" -cluster nats://127.0.0.1:6223 -routes nats://127.0.0.1:6222 -c %s", conf);
snprintf(cmdLine, sizeof(cmdLine), "-a 127.0.0.1 -p 4223 -cluster_name \"local\" -cluster nats://127.0.0.1:6223 -routes nats://127.0.0.1:6222 -c %s", conf);
pid2 = _startServer("nats://127.0.0.1:4223", cmdLine, true);
CHECK_SERVER_STARTED(pid2);
testCond(true);
Expand Down