Read-only mirrors. Development, issues and pull requests are on GitHub.

summaryrefslogtreecommitdiffhomepage
path: root/tests
diff options
context:
space:
mode:
authorLeitwolf112026-10-24 17:43:17 +0300
committerLeitwolf112026-10-24 17:43:17 +0300
commit622188f9c08e4af35941c146979883ed4882410e (patch)
tree415fe5d48a5b48650bba3747beaf245d727c4f61 /tests
parent906a47a04fe0be9e7e6769d8cae59b4b1d286460 (diff)
downloadcatch3-622188f9c08e4af35941c146979883ed4882410e.tar.gz
Do not write the history without its lock
History::Commit went on writing when the lock was still held by another run after ten seconds, so two runs that finished together could replace each other's record. It now returns an error instead, which the runner reports as a history that was not saved. The wait is a parameter, so the new unit test can hold the lock and see the commit refused.
Diffstat (limited to 'tests')
-rw-r--r--tests/Progmasoft/RunnerUnits.tests.cpp27
1 files changed, 27 insertions, 0 deletions
diff --git a/tests/Progmasoft/RunnerUnits.tests.cpp b/tests/Progmasoft/RunnerUnits.tests.cpp
index 9f71a08e..29e832a5 100644
--- a/tests/Progmasoft/RunnerUnits.tests.cpp
+++ b/tests/Progmasoft/RunnerUnits.tests.cpp
@@ -15,6 +15,7 @@
#include <catch2/catch_test_macros.hpp>
#include <catch2/matchers/catch_matchers_string.hpp>
+#include <chrono>
#include <filesystem>
#include <set>
#include <thread>
@@ -264,6 +265,32 @@ TEST_CASE("History quarantines flaky tests and releases them", "[progmasoft][run
std::filesystem::remove_all(directory, error);
}
+TEST_CASE("A history held by another run is left alone",
+ "[progmasoft][runner][history]")
+{
+ std::error_code error;
+ const auto directory = std::filesystem::temp_directory_path(error) /
+ ("catch3-history-" + Runner::UniqueName());
+ const auto file = Runner::HistoryFile(directory, "locked");
+ RunResult run;
+ TestResult test;
+ test.id = "test";
+ test.outcome = Outcome::kPassed;
+ run.tests.push_back(test);
+ {
+ const Runner::FileLock held{file, std::chrono::seconds(1)};
+ REQUIRE(held.Held());
+ auto blocked = Runner::History::Commit(
+ file, run, {}, {}, {}, std::chrono::milliseconds(50));
+ REQUIRE_FALSE(blocked);
+ CHECK_THAT(blocked.GetError().Message(),
+ ContainsSubstring("holds the lock"));
+ CHECK_FALSE(std::filesystem::exists(file));
+ }
+ CHECK(Runner::History::Commit(file, run, {}, {}, {}));
+ std::filesystem::remove_all(directory, error);
+}
+
TEST_CASE("Runs that finish together all reach the history",
"[progmasoft][runner][history]")
{