]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
test: skip verification for racy test cases
authorYu Watanabe <watanabe.yu+github@gmail.com>
Sun, 27 Jul 2025 12:42:12 +0000 (21:42 +0900)
committerLuca Boccassi <luca.boccassi@gmail.com>
Mon, 4 Aug 2025 15:27:43 +0000 (16:27 +0100)
FORMAT_LIFETIME() internally calls now(), hence we cannot provide any
reliable verifications for finite lifetime.

(cherry picked from commit 7292d676d0514150572fcc15ac68b26d900b12a7)

src/network/test-networkd-address.c

index a40c571483a84267f4d0e51af07b7ea96ca7853b..c7757f98f5702191a5660bc6aff39f17398d69ea 100644 (file)
@@ -7,8 +7,9 @@
 static void test_FORMAT_LIFETIME_one(usec_t lifetime, const char *expected) {
         const char *t = FORMAT_LIFETIME(lifetime);
 
-        log_debug(USEC_FMT " → \"%s\" (expected \"%s\")", lifetime, t, expected);
-        assert_se(streq(t, expected));
+        log_debug(USEC_FMT " → \"%s\" (expected \"%s\")", lifetime, t, strna(expected));
+        if (expected)
+                ASSERT_STREQ(t, expected);
 }
 
 TEST(FORMAT_LIFETIME) {
@@ -17,9 +18,11 @@ TEST(FORMAT_LIFETIME) {
         now_usec = now(CLOCK_BOOTTIME);
 
         test_FORMAT_LIFETIME_one(now_usec, "for 0");
-        test_FORMAT_LIFETIME_one(usec_add(now_usec, 2 * USEC_PER_SEC - 1), "for 1s");
-        test_FORMAT_LIFETIME_one(usec_add(now_usec, 3 * USEC_PER_WEEK + USEC_PER_SEC - 1), "for 3w");
         test_FORMAT_LIFETIME_one(USEC_INFINITY, "forever");
+
+        /* These two are necessarily racy, especially for slow test environment. */
+        test_FORMAT_LIFETIME_one(usec_add(now_usec, 2 * USEC_PER_SEC - 1), NULL);
+        test_FORMAT_LIFETIME_one(usec_add(now_usec, 3 * USEC_PER_WEEK + USEC_PER_SEC - 1), NULL);
 }
 
 DEFINE_TEST_MAIN(LOG_DEBUG);