@@ -34528,7 +34528,15 @@ static microError *
3452834528_microHandleRequestNoisy42(microRequest *req)
3452934529{
3453034530 if ((rand() % 10) == 0)
34531+ {
34532+ struct threadArg *arg = (struct threadArg*) microService_GetState(req->Service);
34533+
34534+ natsMutex_Lock(arg->m);
34535+ arg->sum++;
34536+ natsMutex_Unlock(arg->m);
34537+
3453134538 return micro_Errorf("Unexpected error!");
34539+ }
3453234540
3453334541 // Happy Path.
3453434542 // Random delay between 5-10ms
@@ -35169,6 +35177,7 @@ void test_MicroBasics(void)
3516935177 nats_JSON *md = NULL;
3517035178 int num_requests = 0;
3517135179 int num_errors = 0;
35180+ char *lastErr = NULL;
3517235181 int n;
3517335182 nats_JSON **array;
3517435183 int array_len;
@@ -35260,6 +35269,7 @@ void test_MicroBasics(void)
3526035269 if (s == NATS_TIMEOUT)
3526135270 {
3526235271 testCond(i == NUM_MICRO_SERVICES);
35272+ nats_clearLastError();
3526335273 break;
3526435274 }
3526535275 testCond(NATS_OK == s);
@@ -35338,6 +35348,7 @@ void test_MicroBasics(void)
3533835348 if (s == NATS_TIMEOUT)
3533935349 {
3534035350 testCond(i == NUM_MICRO_SERVICES);
35351+ nats_clearLastError();
3534135352 break;
3534235353 }
3534335354 testCond(NATS_OK == s);
@@ -35372,6 +35383,7 @@ void test_MicroBasics(void)
3537235383 if (s == NATS_TIMEOUT)
3537335384 {
3537435385 testCond(i == NUM_MICRO_SERVICES);
35386+ nats_clearLastError();
3537535387 break;
3537635388 }
3537735389 testCond(NATS_OK == s);
@@ -35399,6 +35411,14 @@ void test_MicroBasics(void)
3539935411 testCond(NATS_OK == s);
3540035412 num_errors += n;
3540135413
35414+ test("Ensure second endpoint last_error is set if num_errors is positive: ");
35415+ lastErr = NULL;
35416+ s = nats_JSONGetStr(array[1], "last_error", &lastErr);
35417+ testCond((s == NATS_OK) && (((n == 0) && nats_IsStringEmpty(lastErr)) ||
35418+ ((n > 0) && (strcmp(lastErr, "Unexpected error!") == 0))));
35419+ free(lastErr);
35420+ lastErr = NULL;
35421+
3540235422 test("Ensure second endpoint has average_processing_time as a positive number: ");
3540335423 int64_t avg = 0;
3540435424 s = nats_JSONGetLong(array[1], "average_processing_time", &avg);
@@ -35411,7 +35431,11 @@ void test_MicroBasics(void)
3541135431 test("Check that STATS total request counts add up (50): ");
3541235432 testCond(num_requests == 50);
3541335433 test("Check that STATS total error count is positive, depends on how many instances: ");
35414- testCond(num_errors > 0);
35434+ natsMutex_Lock(arg.m);
35435+ // The arg.sum value is incremented when the service handler returns an error.
35436+ s = (arg.sum == num_errors ? NATS_OK : NATS_ERR);
35437+ natsMutex_Unlock(arg.m);
35438+ testCond(s == NATS_OK);
3541535439
3541635440 natsSubscription_Destroy(sub);
3541735441 natsInbox_Destroy(inbox);
0 commit comments