Skip to content

Commit

Permalink
libflux/test: Fix race in stat watcher test
Browse files Browse the repository at this point in the history
Stat watcher test can be racy, where a append + unlink can occur
in between polling stat() checks.  Thus the test that sees a file
size change can be missed.

Add a STAT_WAIT state, which will ensure the unlink does not occur
until after the file size change has been seen.

Fixes #997
  • Loading branch information
chu11 committed Jun 4, 2019
1 parent 1dff1c4 commit 71a8537
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/common/libflux/test/reactor.c
Original file line number Diff line number Diff line change
Expand Up @@ -1310,7 +1310,7 @@ struct stat_ctx {
char *path;
int stat_size;
int stat_nlink;
enum { STAT_APPEND, STAT_UNLINK } state;
enum { STAT_APPEND, STAT_WAIT, STAT_UNLINK } state;
};
static void stat_cb (flux_reactor_t *r, flux_watcher_t *w,
int revents, void *arg)
Expand All @@ -1328,6 +1328,7 @@ static void stat_cb (flux_reactor_t *r, flux_watcher_t *w,
diag ("%s: size: old=%ld new=%ld", __FUNCTION__,
(long)old.st_size, (long)new.st_size);
ctx->stat_size++;
ctx->state = STAT_UNLINK;
}
}
}
Expand All @@ -1339,7 +1340,7 @@ static void stattimer_cb (flux_reactor_t *r, flux_watcher_t *w,
if (ctx->state == STAT_APPEND) {
if (write (ctx->fd, "hello\n", 6) < 0 || close (ctx->fd) < 0)
flux_reactor_stop_error (r);
ctx->state = STAT_UNLINK;
ctx->state = STAT_WAIT;
} else if (ctx->state == STAT_UNLINK) {
if (unlink (ctx->path) < 0)
flux_reactor_stop_error (r);
Expand Down

0 comments on commit 71a8537

Please sign in to comment.