Add new failing tests on start / stop sequences.

They fail because reaction don't correctly order stop commands after
This commit is contained in:
ppom 2025-08-06 12:00:00 +02:00
commit c824583613
No known key found for this signature in database
2 changed files with 104 additions and 0 deletions

41
tests/start_stop.jsonnet Normal file
View file

@ -0,0 +1,41 @@
local echo(message) = ['sh', '-c', 'echo %s >> ./log' % message];
{
patterns: {
num: {
regex: '[0-9]+',
},
},
start: [
echo('start 1'),
echo('start 2'),
],
stop: [
echo('stop 1'),
echo('stop 2'),
],
streams: {
s1: {
cmd: ['sh', '-c', 'seq 2 | while read i; do echo runtime $i; sleep 0.1; done'],
filters: {
f1: {
regex: [
'^runtime <num>$',
],
actions: {
one: {
cmd: echo('runtime <num>'),
},
two: {
cmd: echo('after <num>'),
after: '1s',
onexit: true,
},
},
},
},
},
},
}

63
tests/start_stop.rs Normal file
View file

@ -0,0 +1,63 @@
use std::{path::Path, time::Duration};
use assert_cmd::Command;
use assert_fs::{prelude::*, TempDir};
use predicates::prelude::predicate;
#[test]
#[ignore = "currently failing"] // FIXME
fn start_stop() {
let tmp_dir = assert_fs::TempDir::new().unwrap();
run_reaction(&tmp_dir);
// Expected output
let output = [
"start 1",
"start 2",
"runtime 1",
"runtime 2",
"after 1",
"after 2",
"stop 1",
"stop 2",
"",
];
tmp_dir.child("log").assert(&output.join("\n"));
tmp_dir.child("log").write_str("").unwrap();
// Second run
run_reaction(&tmp_dir);
// Expected output
let output = [
"start 1",
"start 2",
"runtime 1",
"runtime 2",
"runtime 1",
"runtime 2",
"after 1",
"after 2",
"after 1",
"after 2",
"stop 1",
"stop 2",
"",
];
tmp_dir.child("log").assert(&output.join("\n"));
}
fn run_reaction(tmp_dir: &TempDir) {
tmp_dir
.child("config.jsonnet")
.write_file(Path::new("tests/start_stop.jsonnet"))
.unwrap();
let mut cmd = Command::cargo_bin("reaction").unwrap();
cmd.args(["start", "--socket", "./s", "--config", "./config.jsonnet"]);
cmd.current_dir(tmp_dir.path());
cmd.timeout(Duration::from_secs(5));
// Expected exit 1: all stream exited
cmd.assert().code(predicate::eq(1));
}