From 8f6b8bc6b9956e0347d147512aa8c310563af2ce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Guido=20G=C3=BCnther?= Date: Mon, 13 Oct 2025 10:11:06 +0200 Subject: [PATCH] application: Actually test for write ahead log MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit While the test was correct and checked if there is only `record.db` in a given dir (and no other files) it wouldn't tell us whether the file wasn't there or there were additional files found. Hence replace the test by assertions that tell use exactly what failed easing debugging in CI. Fixes: e4bd4580 ("tests: Add application shutdown tests") Signed-off-by: Guido Günther Part-of: --- tests/test-application.c | 52 +++++++++++++++++++++------------------- 1 file changed, 27 insertions(+), 25 deletions(-) diff --git a/tests/test-application.c b/tests/test-application.c index 8a90d04..74d8bb0 100644 --- a/tests/test-application.c +++ b/tests/test-application.c @@ -11,6 +11,29 @@ #include #include + +#define calls_assert_in_dir(file, dir) G_STMT_START { \ + g_autofree char *__p = g_build_path ("/", dir, file, NULL); \ + g_autoptr (GFile) __f = g_file_new_for_path (__p); \ + if (!g_file_query_exists (__f, NULL)) { \ + g_autofree char *__msg = \ + g_strdup_printf ("File %s does not exist", __p); \ + g_assertion_message (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, __msg); \ + } \ +} G_STMT_END + + +#define calls_assert_not_in_dir(file, dir) G_STMT_START { \ + g_autofree char *__p = g_build_path ("/", dir, file, NULL); \ + g_autoptr (GFile) __f = g_file_new_for_path (__p); \ + if (g_file_query_exists (__f, NULL)) { \ + g_autofree char *__msg = \ + g_strdup_printf ("File %s must not exist", __p); \ + g_assertion_message (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, __msg); \ + } \ +} G_STMT_END + + static gboolean on_idle_quit (gpointer user_data) { @@ -96,29 +119,6 @@ test_application_shutdown_sigterm (void) } -static gboolean -dir_contains (const char *dir, - const char *file, - gboolean only_file) -{ - g_autoptr (GDir) tmp_dir = g_dir_open (dir, 0, NULL); - const char *tmp_file; - gboolean found = FALSE; - uint n = 0; - - while ((tmp_file = g_dir_read_name (tmp_dir))) { - if (g_strcmp0 (tmp_file, file) == 0) - found = TRUE; - n++; - } - - if (only_file) - return found && n == 1; - - return found; -} - - int main (int argc, char *argv[]) @@ -143,8 +143,10 @@ main (int argc, status = g_test_run (); - /* assert there is no dangling write-ahead-log */ - g_assert_true (dir_contains (rec_dir, "records.db", TRUE)); + /* Check that sqlite db is there but no stale write ahead logs */ + calls_assert_in_dir ("records.db", rec_dir); + calls_assert_not_in_dir ("records.db-wal", rec_dir); + calls_assert_not_in_dir ("records.db-shm", rec_dir); g_rmdir (rec_dir);