feat(wait): a run's end, for the background beside a detached run
A run launched detached, as the prepush skill says, tells the session nothing when it ends: a round finished unread for hours. `crafter-review wait --artifact <artifact> --hash <hash>`, the two values of the run line, follows the hash's run lock. A full run holds it until it ends; taking it, the run now clears the last run's identity there, and it names itself with its run number once it has one. When a run the wait has seen hold or take the lock lets it go, the wait reads the identity - under its own instant shared hold, so never a rewrite in flight - prints the summary of the final dump of the run the identity names and exits with the code its verdict maps to, as run's does: 2 when there is no final dump or no run number, 3 with the message of a preflight check that stopped the run after it took the lock, which the run adds to the identity. A wait that sees no run within --appear (120 s by default) exits 3. Every probe of the lock, a test or dry run's too, takes it shared for an instant, and the run lock is tried for 200 ms before another driver counts as its holder. A wait only reads: one that is stopped is started again and the run goes on. freeze prints the wait line before the run line, and the skill and the process start the wait in the background, then launch the run detached. Released as 1.2.0.
This commit is contained in:
parent
ad33242609
commit
4318c7d8f2
15 changed files with 607 additions and 33 deletions
|
|
@ -10,8 +10,10 @@
|
|||
// stand until it dies; two drivers recording into one memory file are two
|
||||
// runs of this binary (`--record`).
|
||||
|
||||
#include <fcntl.h>
|
||||
#include <signal.h>
|
||||
#include <stdlib.h>
|
||||
#include <sys/file.h>
|
||||
#include <unistd.h>
|
||||
import std;
|
||||
import Crafter.Review;
|
||||
|
|
@ -436,6 +438,27 @@ namespace {
|
|||
Check("run lock: another hash is free; nobody holds an untaken one", takes("ffff0000") && !State::LockHolder(gd, "commits", "00000000"));
|
||||
f.reset();
|
||||
Check("run lock: released on close (the kernel releases it on death the same way)", !State::LockHolder(gd, "commits", "abcd1234") && takes("abcd1234"));
|
||||
{
|
||||
// Taken again, the lock no longer names the last run.
|
||||
const State::RunLock again(gd, "commits", "abcd1234");
|
||||
const std::optional<Json> holder = State::LockHolder(gd, "commits", "abcd1234");
|
||||
Check("run lock: taken again, it clears the last run's identity - its holder reads as not named yet", holder && *holder == Json::object(),
|
||||
holder ? holder->dump() : std::string("no holder"));
|
||||
}
|
||||
{
|
||||
// A probe takes the lock shared for an instant: another prober's
|
||||
// is no holder, and a starting run waits it out.
|
||||
const std::int32_t probe = open(State::LockPath(gd, "commits", "abcd1234").c_str(), O_RDONLY | O_CLOEXEC);
|
||||
const bool shared = probe >= 0 && flock(probe, LOCK_SH | LOCK_NB) == 0;
|
||||
const bool seenFree = !State::LockHolder(gd, "commits", "abcd1234");
|
||||
std::jthread release([probe] {
|
||||
std::this_thread::sleep_for(50ms);
|
||||
close(probe);
|
||||
});
|
||||
const bool started = takes("abcd1234");
|
||||
release.join();
|
||||
Check("run lock: a probe's instant shared lock is no holder to another probe, and a starting run waits it out", shared && seenFree && started);
|
||||
}
|
||||
|
||||
// unit-state merge-on-write
|
||||
const fs::path sp = td / "unit-state.json";
|
||||
|
|
|
|||
Loading…
Reference in a new issue