From e35f4a04cc627a59cbc8e91fc6bc7c5fd0f2c831 Mon Sep 17 00:00:00 2001 From: Philip Withnall Date: Mon, 6 Mar 2023 18:25:42 +0000 Subject: [PATCH] tests: Change the time function used in the bookmark tests MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The current comparison has been seen to fail on vs2017-x86 (https://gitlab.gnome.org/pwithnall/glib/-/jobs/2643197): ``` not ok /bookmarks/deprecated - GLib:ERROR:../glib/tests/bookmarkfile.c:921:test_deprecated: assertion failed (t >= now): (1678122080 >= 1678122081) ``` I guess this is caused by a mismatch between the system clock as used by `time (NULL)` and `g_get_real_time ()` (which is ultimately what `g_bookmark_file_set_added()` uses) on Windows. Attempt to fix that by using `g_get_real_time()` in the test harness too, so the clock being used is consistent. If that doesn’t work, my next guess is that some of the code in `test_deprecated()` is being reordered by the compiler. But that shouldn’t happen, because the `time()` call has side-effects, and `g_bookmark_file_set_added()` has side-effects, so they shouldn’t be reordered with respect to each other. And certainly not so that the latter one (in code order) ends up being called 1s after the other. Signed-off-by: Philip Withnall --- glib/tests/bookmarkfile.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/glib/tests/bookmarkfile.c b/glib/tests/bookmarkfile.c index b96e58503..d3038796a 100644 --- a/glib/tests/bookmarkfile.c +++ b/glib/tests/bookmarkfile.c @@ -911,7 +911,7 @@ test_deprecated (void) G_GNUC_BEGIN_IGNORE_DEPRECATIONS - now = time (NULL); + now = g_get_real_time () / G_USEC_PER_SEC; file = g_bookmark_file_new (); /* added */