aboutsummaryrefslogtreecommitdiff
path: root/tests/reqstress.c
diff options
context:
space:
mode:
authorGarrett D'Amore <garrett@damore.org>2018-05-09 10:24:35 -0700
committerGarrett D'Amore <garrett@damore.org>2018-05-09 12:49:52 -0700
commite0beb13b066d27ce32347a1c18c9d441828dc553 (patch)
treeeff76caf075f8a191a82d22b8b47d0245e43b9cd /tests/reqstress.c
parent25e801be9c4889b8df48cce842bbf2e2628d38db (diff)
downloadnng-e0beb13b066d27ce32347a1c18c9d441828dc553.tar.gz
nng-e0beb13b066d27ce32347a1c18c9d441828dc553.tar.bz2
nng-e0beb13b066d27ce32347a1c18c9d441828dc553.zip
fixes #423 desire tunable stress time and pressure in stress tests
Use -p STRESSPRESSURE=<count> (default 32) and -p STRESSTIME=<sec> to affect stress run. Pressure should be a number [2,x] where x is determined by the number of threads and file descriptors your platform can handle. Modern platforms should be able to handle at least 100.
Diffstat (limited to 'tests/reqstress.c')
-rw-r--r--tests/reqstress.c36
1 files changed, 26 insertions, 10 deletions
diff --git a/tests/reqstress.c b/tests/reqstress.c
index 81249946..f2ee502d 100644
--- a/tests/reqstress.c
+++ b/tests/reqstress.c
@@ -150,13 +150,17 @@ req_client(void *arg)
nng_msleep(rand() % 10);
- if (((rv = nng_msg_alloc(&msg, 0)) != 0) ||
- ((rv = nng_msg_append(msg, buf, strlen(buf) + 1)) != 0)) {
+ if ((rv = nng_msg_alloc(&msg, 0)) != 0) {
error(c, "alloc fail", rv);
return;
}
-
+ if ((rv = nng_msg_append(msg, buf, strlen(buf) + 1)) != 0) {
+ nng_msg_free(msg);
+ error(c, "append fail", rv);
+ return;
+ }
if ((rv = nng_sendmsg(req, msg, 0)) != 0) {
+ nng_msg_free(msg);
error(c, "sendmsg", rv);
return;
}
@@ -169,6 +173,7 @@ req_client(void *arg)
if (strcmp(nng_msg_body(msg), buf) != 0) {
error(c, "mismatched message", NNG_EINTERNAL);
+ nng_msg_free(msg);
return;
}
@@ -226,7 +231,22 @@ reqrep_test(int ntests)
}
Main({
- int i;
+ int i;
+ int tmo;
+ char *str;
+
+ atexit(nng_fini);
+
+ if (((str = ConveyGetEnv("STRESSTIME")) == NULL) ||
+ ((tmo = atoi(str)) < 1)) {
+ tmo = 30;
+ }
+ // We have to keep this relatively low by default because some
+ // platforms don't support large numbers of threads.
+ if (((str = ConveyGetEnv("STRESSPRESSURE")) == NULL) ||
+ ((ncases = atoi(str)) < 1)) {
+ ncases = 32;
+ }
// Each run should truly be random.
srand((int) time(NULL));
@@ -235,10 +255,6 @@ Main({
// subsequent runs.
next_port += (rand() % 100) * 100;
- // We have to keep this relatively low because some platforms
- // don't support large numbers of threads.
- ncases = 32;
-
i = ncases;
cases = calloc(ncases, sizeof(test_case));
@@ -251,8 +267,8 @@ Main({
i -= x;
}
- dprintf("WAITING for 30 sec...\n");
- nng_msleep(30000); // sleep 30 sec
+ dprintf("WAITING for %d sec...\n", tmo);
+ nng_msleep(tmo * 1000); // sleep 30 sec
nng_closeall();
Test("Req/Rep Stress", {