From 45dfa2d8640ab94c86ba97d5dc15db87badc67fb Mon Sep 17 00:00:00 2001 From: ridiculousfish Date: Sun, 8 Nov 2015 23:48:32 -0800 Subject: Attempt to fix the sporadic uvar test failures on Linux We identify when the universal variable file has changed out from under us by comparing a bunch of fields from its stat: inode, device, size, high-precision timestamp, generation. Linux aggressively reuses inodes, and the size may be the same by coincidence (which is the case in the tests). Also, Linux officially has nanosecond precision, but in practice it seems to only uses millisecond precision for storing mtimes. Thus if there are three or more updates within a millisecond, every field we check may be the same, and we are vulnerable to the ABA problem. I believe this explains the occasional test failures. The solution is to manually set the nanosecond field of the mtime timestamp to something unlikely to be duplicated, like a random number, or better yet, the current time (with nanosecond precision). This is more in the spirit of the timestamp, and it means we're around a million times less likely to collide. This seems to fix the tests. --- src/fish_tests.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/fish_tests.cpp') diff --git a/src/fish_tests.cpp b/src/fish_tests.cpp index cef1857f..41a0a90f 100644 --- a/src/fish_tests.cpp +++ b/src/fish_tests.cpp @@ -2563,7 +2563,7 @@ static int test_universal_helper(int *x) bool synced = uvars.sync(NULL); if (! synced) { - err(L"Failed to sync universal variables"); + err(L"Failed to sync universal variables after modification"); } fputc('.', stderr); } @@ -2573,7 +2573,7 @@ static int test_universal_helper(int *x) bool synced = uvars.sync(NULL); if (! synced) { - err(L"Failed to sync universal variables"); + err(L"Failed to sync universal variables after deletion"); } fputc('.', stderr); -- cgit v1.2.3