Skip to content

Commit

Permalink
temporarily run just the Micro tests
Browse files Browse the repository at this point in the history
added a sleep to try fixing Test_MicroServiceStopsWhenServerStops

MALLOC->CALLOC

more debugging in CI

fixed the dotted subject leak

fixed monitoring msg leak

temp: Sleep-wait for the service to stop

run all of the tests again
  • Loading branch information
levb committed Apr 17, 2023
1 parent 63ede6a commit 659afcb
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 10 deletions.
4 changes: 4 additions & 0 deletions src/micro.c
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,10 @@ bool micro_service_is_stopping(microService *m)
stopping = m->is_stopping;
natsMutex_Unlock(m->mu);

if (stopping)
printf("<>/<> still stopping\n");
else
printf("<>/<> stopped\n");
return stopping;
}

Expand Down
4 changes: 2 additions & 2 deletions src/micro_error.c
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ micro_Errorf(int code, const char *format, ...)
va_end(args2);
return &_errorInvalidFormat;
}
buf = NATS_MALLOC(len + 1);
buf = NATS_CALLOC(1, len + 1);
if (buf == NULL)
{
va_end(args2);
Expand Down Expand Up @@ -145,7 +145,7 @@ microError_Wrapf(microError *err, const char *format, ...)
{
len2 = strlen(err->description) + 2; // ": "
}
buf = NATS_MALLOC(len1 + len2 + 1);
buf = NATS_CALLOC(1, len1 + len2 + 1);
if (buf == NULL)
{
return &_errorOutOfMemory;
Expand Down
9 changes: 6 additions & 3 deletions src/micro_monitoring.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ micro_init_monitoring(microService *m)
{
microError *err = NULL;

m->monitoring_subs = NATS_CALLOC(MICRO_MONITORING_SUBS_CAP, sizeof(natsSubscription*));
m->monitoring_subs = NATS_CALLOC(MICRO_MONITORING_SUBS_CAP, sizeof(natsSubscription *));
if (m->monitoring_subs == NULL)
return micro_ErrorOutOfMemory;
m->monitoring_subs_len = 0;
Expand Down Expand Up @@ -75,6 +75,7 @@ handle_ping(natsConnection *nc, natsSubscription *sub, natsMsg *msg, void *closu
microRequest_Respond(req, &err, natsBuf_Data(buf), natsBuf_Len(buf));

micro_destroy_request(req);
natsMsg_Destroy(msg);
natsBuf_Destroy(buf);
}

Expand All @@ -98,6 +99,7 @@ handle_info(natsConnection *nc, natsSubscription *sub, natsMsg *msg, void *closu
microRequest_Respond(req, &err, natsBuf_Data(buf), natsBuf_Len(buf));

natsBuf_Destroy(buf);
natsMsg_Destroy(msg);
microServiceInfo_Destroy(info);
}

Expand Down Expand Up @@ -138,6 +140,7 @@ handle_stats(natsConnection *nc, natsSubscription *sub, natsMsg *msg, void *clos
MICRO_CALL(err, micro_new_request(&req, m, NULL, msg));
MICRO_DO(err, h(req));
MICRO_DO(err, micro_destroy_request(req));
natsMsg_Destroy(msg);
}

static microError *
Expand All @@ -159,7 +162,7 @@ new_dotted_subject(char **new_subject, int count, ...)
}
va_end(args);

result = NATS_MALLOC(len + 1);
result = NATS_CALLOC(len + 1, 1);
if (result == NULL)
{
return micro_ErrorInvalidArg;
Expand Down Expand Up @@ -217,6 +220,7 @@ add_internal_handler(microService *m, const char *verb, const char *kind,
return err;

s = natsConnection_Subscribe(&sub, m->nc, subj, handler, m);
NATS_FREE(subj);
if (s != NATS_OK)
{
microService_Stop(m);
Expand Down Expand Up @@ -377,4 +381,3 @@ marshal_stats(natsBuffer **new_buf, microServiceStats *stats)
return microError_Wrapf(micro_ErrorFromStatus(s), "failed to marshal service info");
}
}

11 changes: 6 additions & 5 deletions test/test.c
Original file line number Diff line number Diff line change
Expand Up @@ -32288,14 +32288,12 @@ test_MicroServiceStopsOnClosedConn(void)
testCond(NATS_OK == natsConnection_Drain(nc));
natsConnection_Close(nc);

while (micro_service_is_stopping(m))
{
nats_Sleep(1);
}
test("<>/<> Wait for the service to stop: ");
testCond((nats_Sleep(100), true));

test("Test microservice is stopped: ");
testCond(microService_IsStopped(m));


microService_Destroy(m);
natsOptions_Destroy(opts);
natsConnection_Destroy(nc);
Expand Down Expand Up @@ -32341,6 +32339,9 @@ test_MicroServiceStopsWhenServerStops(void)
test("Stop the server: ");
testCond((_stopServer(serverPid), true));

test("<>/<> Wait for the service to stop: ");
testCond((nats_Sleep(100), true));

test("Test microservice is not running: ");
testCond(microService_IsStopped(m))

Expand Down

0 comments on commit 659afcb

Please sign in to comment.