Skip to content

Commit 58bb6a8

Browse files
committed
tests: avoid some ci test problems
1 parent f1c8024 commit 58bb6a8

6 files changed

Lines changed: 26 additions & 12 deletions

File tree

‎.github/workflows/build-and-test.yml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ jobs:
3737
- if: startsWith(matrix.container, 'fedora')
3838
name: fedora-deps
3939
run: |
40-
dnf install -y git make gcc-c++ meson ninja-build pkgconf-pkg-config xapian-core-devel glib2-devel gmime30-devel cli11-devel fmt-devel expected-devel guile30-devel cld2-devel emacs texinfo
40+
dnf install -y git make gcc-c++ glibc-gconv-extra gnupg2 meson ninja-build pkgconf-pkg-config xapian-core-devel glib2-devel gmime30-devel cli11-devel fmt-devel expected-devel guile30-devel cld2-devel emacs texinfo
4141
4242
- if: startsWith(matrix.container, 'debian')
4343
name: debian-deps

‎lib/message/test-mu-message.cc‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
** Copyright (C) 2023-2025 Dirk-Jan C. Binnema <djcb@djcbsoftware.nl>
2+
** Copyright (C) 2023-2026 Dirk-Jan C. Binnema <djcb@djcbsoftware.nl>
33
**
44
** This program is free software; you can redistribute it and/or modify it
55
** under the terms of the GNU General Public License as published by the

‎lib/mu-query-xapianizer.cc‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -462,7 +462,10 @@ test_xapian()
462462
{
463463
allow_warnings();
464464

465-
auto&& testhome{unwrap(make_temp_dir())};
465+
// tempdir must outlive the store; the store's dtor still writes
466+
// to the database.
467+
TempDir tempdir;
468+
const auto& testhome{tempdir.path()};
466469
auto&& dbpath{runtime_path(RuntimePath::XapianDb, testhome)};
467470
auto&& store{unwrap(Store::make_new(dbpath, join_paths(testhome, "test-maildir")))};
468471

@@ -514,8 +517,6 @@ test_xapian()
514517
assert_valid_result(xq);
515518
assert_equal(xq->get_description(), test.second);
516519
}
517-
518-
assert_valid_result(remove_directory(testhome));
519520
}
520521

521522
int

‎lib/tests/test-mu-store.cc‎

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -348,12 +348,13 @@ World!
348348
// g_message(">>> %s", (*term).c_str());
349349

350350
// last-change is recorded as part of a commit.
351+
const auto before_commit{::time({})};
351352
store->xapian_db().request_commit(true/*force*/);
352353

353354
const auto stats{store->statistics()};
354355
g_assert_cmpuint(stats.size,==,store->size());
355356
g_assert_cmpuint(stats.last_index,==,0);
356-
g_assert_cmpuint(stats.last_change,>=,::time({}));
357+
g_assert_cmpuint(stats.last_change,>=,before_commit);
357358
}
358359

359360

@@ -557,7 +558,10 @@ test_store_circular_symlink()
557558

558559
mu_test_skip_valgrind_return();
559560

560-
auto testhome{unwrap(make_temp_dir())};
561+
// tempdir must outlive the store; the store's dtor still writes
562+
// to the database.
563+
TempDir tempdir;
564+
const auto& testhome{tempdir.path()};
561565
auto dbpath{runtime_path(RuntimePath::XapianDb, testhome)};
562566

563567
/* create a writable copy */
@@ -580,8 +584,6 @@ test_store_circular_symlink()
580584
}
581585
// there will be a lot of dups....
582586
g_assert_false(store.empty());
583-
584-
assert_valid_result(remove_directory(testhome));
585587
}
586588

587589
static void

‎lib/utils/mu-test-utils.cc‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,8 @@ black_hole(void)
9090
void
9191
Mu::mu_test_init(int *argc, char ***argv)
9292
{
93-
TempDir temp_dir;
93+
// static, so it lives until exit (and gets cleaned up then)
94+
static TempDir temp_dir;
9495

9596
g_unsetenv("XAPIAN_CJK_NGRAM");
9697
g_setenv("MU_TEST", "yes", TRUE);

‎lib/utils/mu-utils-file.cc‎

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,9 +127,19 @@ Mu::remove_directory(const std::string& path)
127127
if (!check_dir(path, false, true))
128128
return Err(Error::Code::File, "not a writable directory: {}", path);
129129

130+
// some other process may remove entries while we're at it (e.g. a
131+
// gpg-agent cleaning up its sockets when its homedir disappears), so
132+
// retry a few times when we hit ENOENT.
130133
std::error_code err{};
131-
const auto n{std::filesystem::remove_all(path, err)};
132-
if (err)
134+
std::uintmax_t n{};
135+
for (auto attempt = 0; attempt != 5; ++attempt) {
136+
err.clear();
137+
n = std::filesystem::remove_all(path, err);
138+
if (err != std::errc::no_such_file_or_directory)
139+
break;
140+
}
141+
if (err && (err != std::errc::no_such_file_or_directory ||
142+
std::filesystem::exists(path)))
133143
return Err(Error::Code::File, "failed to remove {}: {}",
134144
path, err.message());
135145

0 commit comments

Comments
 (0)