Skip to content

Commit

Permalink
Team feedback: ignore allowReconnect
Browse files Browse the repository at this point in the history
  • Loading branch information
levb committed May 6, 2024
1 parent 5884592 commit c1fcc61
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 16 deletions.
6 changes: 0 additions & 6 deletions src/conn.c
Expand Up @@ -3435,12 +3435,6 @@ natsConnection_Reconnect(natsConnection *nc)
return nats_setDefaultError(NATS_CONNECTION_CLOSED);
}

if (!nc->opts->allowReconnect)
{
natsConn_Unlock(nc);
return nats_setDefaultError(NATS_ILLEGAL_STATE);
}

natsSock_Close(nc->sockCtx.fd);

natsConn_Unlock(nc);
Expand Down
18 changes: 8 additions & 10 deletions test/test.c
Expand Up @@ -20227,11 +20227,8 @@ test_ForcedReconnect(void)
testCond(s == NATS_OK);

test("Send a message to foo: ");
s = natsMsg_Create(&msg, "foo", NULL, "bar", 3);
IFOK(s, natsConnection_PublishMsg(nc, msg));
IFOK(s, natsConnection_PublishString(nc, "foo", "bar"));
testCond(s == NATS_OK);
natsMsg_Destroy(msg);
msg = NULL;

test("Receive the message: ");
s = natsSubscription_NextMsg(&msg, sub, 1000);
Expand All @@ -20252,24 +20249,25 @@ test_ForcedReconnect(void)
testCond(s == NATS_OK);

test("Send a message to foo: ");
s = natsMsg_Create(&msg, "foo", NULL, "bar", 3);
IFOK(s, natsConnection_PublishMsg(nc, msg));
IFOK(s, natsConnection_PublishString(nc, "foo", "bar"));
testCond(s == NATS_OK);
natsMsg_Destroy(msg);
msg = NULL;

test("Receive the message: ");
s = natsSubscription_NextMsg(&msg, sub, 1000);
testCond((s == NATS_OK) && (msg != NULL));
natsMsg_Destroy(msg);
msg = NULL;

test("Reconect on errors if allowReconnect is not set: ");
test("Reconnect again with allowReconnect false, the call succeeds: ");
natsMutex_Lock(nc->mu);
nc->opts->allowReconnect = false;
natsMutex_Unlock(nc->mu);
s = natsConnection_Reconnect(nc);
testCond(s == NATS_ILLEGAL_STATE);
testCond(s == NATS_OK);

test("But the connection is closed: ");
s = natsSubscription_NextMsg(&msg, sub, 1000);
testCond((s == NATS_CONNECTION_CLOSED) && (msg == NULL));

natsConnection_Close(nc);
test("Reconect on a close connection errors: ");
Expand Down

0 comments on commit c1fcc61

Please sign in to comment.