Skip to content

Commit

Permalink
nixos-module: Test check that termination signal is sent
Browse files Browse the repository at this point in the history
  • Loading branch information
roberth committed Jun 24, 2024
1 parent 8ee5d2f commit 6b1c8bd
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 23 deletions.
20 changes: 4 additions & 16 deletions nixos-module.nix
Original file line number Diff line number Diff line change
Expand Up @@ -42,22 +42,10 @@ let
cfg.docker.client.package
];
environment.ARION_PREBUILT = config.settings.out.dockerComposeYaml;
serviceConfig.Type = "oneshot";
serviceConfig.RemainAfterExit = true;
serviceConfig.ExecStart = [
(lib.getExe (pkgs.writeScriptBin "nixos-arion-start" ''
#!${pkgs.runtimeShell}
echo 1>&2 "starting arion project: $ARION_PREBUILT"
arion --prebuilt-file "$ARION_PREBUILT" up --detach
''))
];
serviceConfig.ExecStop = [
(lib.getExe (pkgs.writeScriptBin "nixos-arion-stop" ''
#!${pkgs.runtimeShell}
echo 1>&2 "stopping arion project: $ARION_PREBUILT"
arion --prebuilt-file "$ARION_PREBUILT" down
''))
];
script = ''
echo 1>&2 "docker compose file: $ARION_PREBUILT"
arion --prebuilt-file "$ARION_PREBUILT" up
'';
};
};
};
Expand Down
8 changes: 4 additions & 4 deletions tests/flake-module.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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; });
Expand Down
15 changes: 12 additions & 3 deletions tests/nixos-virtualization-arion-test/test.nix
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
pkgs: module:

pkgs.nixosTest {
pkgs.testers.runNixOSTest ({ lib, ... }:{
name = "test-basic-arion-kafka";
nodes = {
machine = { ... }: {
Expand All @@ -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 \
Expand All @@ -42,6 +45,12 @@ pkgs.nixosTest {
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
Expand All @@ -60,4 +69,4 @@ pkgs.nixosTest {
assert os.path.exists(f'{dir}/stop-probe-terminated-cleanly'), f'{dir}/stop-probe-terminated-cleanly does not exist'
'';
}
})

0 comments on commit 6b1c8bd

Please sign in to comment.