aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authortv <tv@krebsco.de>2026-11-30 13:13:44 +0000
committertv <tv@krebsco.de>2026-11-30 14:59:15 +0000
commitac214a023e3d823a8231c365656cfa27703f27d5 (patch)
tree551ca7e87e2dce128b23732d28100edd84861ffc /tests
parenta0f22c88d54d351b060c2d0d9f0a8cbf5f412ba2 (diff)
enstate: reactions after applying, and after a switch
After applying, units are restarted or reloaded, and started if they aren't running: they may have failed for want of their views. That happens with the store's lock released: a unit restarted may want the one that runs --migrate, which waits for the lock. After a switch, --migrate runs from the unit that units using views are ordered after, so only running units react, without waiting for them (--no-block try-restart, try-reload-or-restart).
Diffstat (limited to 'tests')
-rw-r--r--tests/common/mod.rs24
-rw-r--r--tests/migrations.rs5
-rw-r--r--tests/receptor.rs4
3 files changed, 27 insertions, 6 deletions
diff --git a/tests/common/mod.rs b/tests/common/mod.rs
index 751d809..f1f3f74 100644
--- a/tests/common/mod.rs
+++ b/tests/common/mod.rs
@@ -73,17 +73,33 @@ impl Host {
pub fn apply(&self, schema: &(Schema, Vec<u8>), dir: &Path) -> Plan {
let submission = Submission::load(dir).unwrap();
let store = self.store();
- let _lock = store.lock().unwrap();
+ let lock = store.lock().unwrap();
plan::plan(&schema.0, &store, &submission)
.unwrap()
- .apply(&store, &schema.1, &self.systemctl())
+ .apply(&store, &schema.1, &self.systemctl(), lock)
.unwrap()
}
- /// A systemctl that writes down what it was asked.
+ /// A systemctl that writes down what it was asked, and whether the store's lock
+ /// was free then.
pub fn systemctl(&self) -> PathBuf {
let log = self.root.join("systemctl.log");
- PathBuf::from(self.program("systemctl", &format!("echo \"$*\" >> {}", log.display())))
+ let lock = self.root.join("state/lock");
+ let locks = self.root.join("locks.log");
+ PathBuf::from(self.program(
+ "systemctl",
+ &format!(
+ "echo \"$*\" >> {log}\nif flock -n {lock} true; then echo free; else echo held; fi >> {locks}",
+ log = log.display(),
+ lock = lock.display(),
+ locks = locks.display(),
+ ),
+ ))
+ }
+
+ /// Whether the lock was free each time systemctl ran.
+ pub fn locks(&self) -> String {
+ std::fs::read_to_string(self.root.join("locks.log")).unwrap_or_default()
}
pub fn reactions(&self) -> String {
diff --git a/tests/migrations.rs b/tests/migrations.rs
index 7b78b8e..b91972c 100644
--- a/tests/migrations.rs
+++ b/tests/migrations.rs
@@ -61,7 +61,10 @@ fn a_renamed_slot_and_a_rollback() {
);
assert_eq!(host.view("retiolum.key", "retiolum.key").unwrap(), b"K");
assert!(host.view("tinc.key", "tinc.key").is_none());
- assert!(host.reactions().contains("restart tincr.service"));
+ assert!(
+ host.reactions()
+ .contains("--no-block try-restart tincr.service")
+ );
let stored = host.store().current("secrets").unwrap().unwrap();
assert_eq!(stored.id, first);
assert_eq!(stored.schema, s1.1);
diff --git a/tests/receptor.rs b/tests/receptor.rs
index 034e2a8..843eaa6 100644
--- a/tests/receptor.rs
+++ b/tests/receptor.rs
@@ -70,8 +70,10 @@ fn apply_rotate_and_nothing_to_change() {
// A unit both restarted and reloaded is restarted.
assert_eq!(
host.reactions(),
- "restart svc.service\nreload other.service\n"
+ "restart svc.service\nreload-or-restart other.service\n"
);
+ // With the lock released: a unit restarted may want the one that runs --migrate.
+ assert_eq!(host.locks(), "free\nfree\n");
// The same again changes nothing: no new snapshot, no reactions.
let again = host.submission(