nixos-module: Test check that termination signal is sent

This commit is contained in:
Robert Hensing 2024-06-24 09:26:53 +02:00
parent 01777136c6
commit 7f6c58f210
3 changed files with 65 additions and 9 deletions

View file

@ -13,10 +13,10 @@
};
# Currently broken; kafka can't reach zookeeper
# nixosModuleWithPodman =
# import ./nixos-virtualization-arion-test/test.nix final {
# virtualisation.arion.backend = "podman-socket";
# };
nixosModuleWithPodman =
import ./nixos-virtualization-arion-test/test.nix final {
virtualisation.arion.backend = "podman-socket";
};
testWithPodman =
nixosTest (import ./arion-test { usePodman = true; pkgs = final; });

View file

@ -1,4 +1,4 @@
{ pkgs, ... }: {
{ lib, pkgs, ... }: {
project.name = "whale";
docker-compose.raw = {
@ -59,4 +59,28 @@
"start-foreground"
];
};
services.stop-probe = {
image.command = [
(lib.getExe (pkgs.writeScriptBin "stop-probe" ''
#!${pkgs.runtimeShell}
touch /diagnostics/stop-probe-started
onSIGTERM() {
echo "Handling SIGTERM"
touch /diagnostics/stop-probe-terminated-cleanly
echo "Bye!"
}
echo "Registering SIGTERM handler"
trap onSIGTERM SIGTERM
sleep 3600
''))
];
service.useHostStore = true;
service.volumes = [
"/tmp/shared:/diagnostics"
];
service.environment = {
"PATH" = lib.makeBinPath [ pkgs.busybox ];
};
};
}

View file

@ -1,6 +1,6 @@
pkgs: module:
pkgs.nixosTest {
pkgs.testers.runNixOSTest ({ lib, ... }:{
name = "test-basic-arion-kafka";
nodes = {
machine = { ... }: {
@ -16,10 +16,13 @@ pkgs.nixosTest {
};
};
};
testScript = ''
testScript = { nodes, ... }: ''
machine.wait_for_unit("sockets.target")
machine.wait_for_unit("arion-whale.service")
${# TODO: make the kafka service work on podman-socket; some networking issue
lib.optionalString (nodes.machine.virtualisation.arion.backend != "podman-socket") ''
machine.succeed("""
(echo "hello"; echo "world") \
| ${pkgs.apacheKafka}/bin/kafka-console-producer.sh \
@ -35,6 +38,35 @@ pkgs.nixosTest {
) | grep --line-buffered hello | { read; kill $(<pid); rm pid; }
) 2>/dev/console
""")
# make sure logs were captured
machine.succeed("""
# Check that messages were logged with field "CONTAINER_NAME" set to "whale-zookeeper-1"
journalctl --output json | ${pkgs.jq}/bin/jq 'select(.CONTAINER_NAME=="whale-zookeeper-1") | .MESSAGE' | grep -F 'org.apache.zookeeper'
""")
''}
machine.wait_until_succeeds("""
journalctl --grep 'Registering SIGTERM handler' >/dev/null
""")
# explore the shared mounts, as they're undocumented
machine.succeed("""
mount >&2
touch /tmp/xchg/this-is-xchg
touch /tmp/shared/this-is-shared
""")
machine.shutdown()
# show what's in machine.shared_dir by running `ls` on the host
dir = machine.shared_dir
import os
print(f'Contents of {dir}:')
os.system(f'ls -l {dir}')
# dir/stop-probe-terminated-cleanly must exist
assert os.path.exists(f'{dir}/stop-probe-terminated-cleanly'), f'{dir}/stop-probe-terminated-cleanly does not exist'
'';
}
})