fsmonitor--daemon:: introduce client delay for testing

Define GIT_TEST_FSMONITOR_CLIENT_DELAY as a millisecond delay.

Introduce an artificial delay when processing client requests.
This make the CI/PR test suite a little more stable and avoids
the need to load up test scripts with sleep statements to avoid
racy failures.  This was mostly seen on 1 or 2 core CI build
machines where the test script would create a file and quickly
try to confirm that the daemon had seen it *before* the daemon
had received the kernel event and causing a test failure.

Signed-off-by: Jeff Hostetler <jeffhost@microsoft.com>
This commit is contained in:
Jeff Hostetler
2020-12-18 11:57:05 -05:00
committed by Johannes Schindelin
parent 6cc4f89d0f
commit bbf2a4f276

View File

@@ -150,6 +150,30 @@ static int do_as_client__send_flush(void)
return 0;
}
static int lookup_client_test_delay(void)
{
static int delay_ms = -1;
const char *s;
int ms;
if (delay_ms >= 0)
return delay_ms;
delay_ms = 0;
s = getenv("GIT_TEST_FSMONITOR_CLIENT_DELAY");
if (!s)
return delay_ms;
ms = atoi(s);
if (ms < 0)
return delay_ms;
delay_ms = ms;
return delay_ms;
}
/*
* Requests to and from a FSMonitor Protocol V2 provider use an opaque
* "token" as a virtual timestamp. Clients can request a summary of all
@@ -526,6 +550,18 @@ static int do_handle_client(struct fsmonitor_daemon_state *state,
return SIMPLE_IPC_QUIT;
}
/*
* For testing purposes, introduce an artificial delay in this
* worker to allow the filesystem listener thread to receive
* any fs events that may have been generated by the client
* process on the other end of the pipe/socket. This helps
* make the CI/PR test suite runs a little more predictable
* and hopefully eliminates the need to introduce `sleep`
* commands in the test scripts.
*/
if (state->test_client_delay_ms)
sleep_millisec(state->test_client_delay_ms);
if (!strcmp(command, "flush")) {
/*
* Flush all of our cached data and generate a new token
@@ -1038,7 +1074,7 @@ static int fsmonitor_run_daemon(void)
pthread_mutex_init(&state.main_lock, NULL);
state.error_code = 0;
state.current_token_data = fsmonitor_new_token_data();
state.test_client_delay_ms = 0;
state.test_client_delay_ms = lookup_client_test_delay();
/* Prepare to (recursively) watch the <worktree-root> directory. */
strbuf_init(&state.path_worktree_watch, 0);