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 test_JetStreamInfoAlternates flapper #775

Merged
merged 1 commit into from
Jul 27, 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
55 changes: 13 additions & 42 deletions test/test.c
Original file line number Diff line number Diff line change
Expand Up @@ -30199,43 +30199,6 @@ void test_JetStreamInfoWithSubjects(void)
JS_TEARDOWN;
}

static natsStatus
_checkJSClusterReady(const char *url)
{
natsStatus s = NATS_OK;
natsConnection *nc = NULL;
jsCtx *js = NULL;
jsErrCode jerr= 0;
int i;
jsOptions jo;

jsOptions_Init(&jo);
jo.Wait = 1000;

s = natsConnection_ConnectTo(&nc, url);
IFOK(s, natsConnection_JetStream(&js, nc, &jo));
for (i=0; (s == NATS_OK) && (i<10); i++)
{
jsStreamInfo *si = NULL;

s = js_GetStreamInfo(&si, js, "CHECK_CLUSTER", &jo, &jerr);
if (jerr == JSStreamNotFoundErr)
{
nats_clearLastError();
s = NATS_OK;
break;
}
if ((s != NATS_OK) && (i < 9))
{
s = NATS_OK;
nats_Sleep(500);
}
}
jsCtx_Destroy(js);
natsConnection_Destroy(nc);
return s;
}

void test_JetStreamInfoAlternates(void)
{
char datastore1[256] = {'\0'};
Expand All @@ -30251,6 +30214,7 @@ void test_JetStreamInfoAlternates(void)
jsStreamConfig sc;
jsStreamSource ss;
natsStatus s;
int i;

ENSURE_JS_VERSION(2, 9, 0);

Expand All @@ -30271,10 +30235,6 @@ void test_JetStreamInfoAlternates(void)
CHECK_SERVER_STARTED(pid1);
testCond(true);

test("Check cluster: ");
s = _checkJSClusterReady("nats://127.0.0.1:4224");
testCond(s == NATS_OK);

test("Connect: ");
s = natsConnection_ConnectTo(&nc, NATS_DEFAULT_URL);
testCond(s == NATS_OK);
Expand All @@ -30288,7 +30248,18 @@ void test_JetStreamInfoAlternates(void)
sc.Name = "TEST";
sc.Subjects = (const char*[1]){"foo"};
sc.SubjectsLen = 1;
s = js_AddStream(NULL, js, &sc, NULL, NULL);
// We will try up to 10 times to create the stream. It may fail if the cluster
// is not ready to accept the request.
for (i=0; (s == NATS_OK) && (i < 10); i++)
{
s = js_AddStream(NULL, js, &sc, NULL, NULL);
if ((s != NATS_OK) && (i < 9))
{
nats_clearLastError();
s = NATS_OK;
nats_Sleep(100);
}
}
testCond(s == NATS_OK);

test("Create mirror: ");
Expand Down
Loading