Skip to content

Commit

Permalink
Attempt to fix timing test CI failure.
Browse files Browse the repository at this point in the history
* Reduce sleep time from 3s to 1s. No need to sleep so long.
* Relax tolerances so we can be pretty sure the server has awakened when
  we make the next attempt.
* Protect against an unlikely edge case where nanosleep returns early
  because we're interrupted.

Signed-off-by: michael-grunder <[email protected]>
  • Loading branch information
michael-grunder committed Aug 12, 2024
1 parent e861276 commit 7a4d64b
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions tests/client_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,9 @@ static void millisleep(int ms) {
Sleep(ms);
#else
struct timespec ts = { ms / 1000, (ms % 1000) * 1000000 };
nanosleep(&ts, NULL);

while (nanosleep(&ts, &ts) == EINTR)
;
#endif
}

Expand Down Expand Up @@ -1319,15 +1321,13 @@ static void test_blocking_connection_timeouts(struct config config) {
valkeyContext *c;
valkeyReply *reply;
ssize_t s;
const char *sleep_cmd = "DEBUG SLEEP 3\r\n";
struct timeval tv;
const char *sleep_cmd = "DEBUG SLEEP 1\r\n";
struct timeval tv = {.tv_sec = 0, .tv_usec = 10000};

c = do_connect(config);
test("Successfully completes a command when the timeout is not exceeded: ");
reply = valkeyCommand(c,"SET foo fast");
freeReplyObject(reply);
tv.tv_sec = 0;
tv.tv_usec = 10000;
valkeySetTimeout(c, tv);
reply = valkeyCommand(c, "GET foo");
test_cond(reply != NULL && reply->type == VALKEY_REPLY_STRING && memcmp(reply->str, "fast", 4) == 0);
Expand All @@ -1345,8 +1345,6 @@ static void test_blocking_connection_timeouts(struct config config) {
sdsfree(c->obuf);
c->obuf = sdsempty();

tv.tv_sec = 0;
tv.tv_usec = 10000;
valkeySetTimeout(c, tv);
reply = valkeyCommand(c, "GET foo");
#ifndef _WIN32
Expand All @@ -1359,7 +1357,7 @@ static void test_blocking_connection_timeouts(struct config config) {
freeReplyObject(reply);

// wait for the DEBUG SLEEP to complete so that the server is unblocked for the following tests
millisleep(3000);
millisleep(1100);
} else {
test_skipped();
}
Expand Down

0 comments on commit 7a4d64b

Please sign in to comment.