Skip to content

Commit

Permalink
nixosTests.earlyoom: add a proper OOM test
Browse files Browse the repository at this point in the history
  • Loading branch information
oxalica committed Oct 3, 2024
1 parent f70d853 commit 47916b5
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
2 changes: 0 additions & 2 deletions nixos/modules/services/system/earlyoom.nix
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ let
cfg = config.services.earlyoom;

inherit (lib)
concatStringsSep
escapeShellArg
literalExpression
mkDefault
mkEnableOption
Expand Down
22 changes: 20 additions & 2 deletions nixos/tests/earlyoom.nix
Original file line number Diff line number Diff line change
@@ -1,16 +1,34 @@
import ./make-test-python.nix ({ lib, ... }: {
name = "earlyoom";
meta = {
maintainers = with lib.maintainers; [ ncfavier AndersonTorres ];
maintainers = with lib.maintainers; [ ncfavier AndersonTorres oxalica ];
};

nodes.machine = {
nodes.machine = { pkgs, ... }: {
# Limit VM resource usage.
virtualisation.memorySize = 1024;

services.earlyoom = {
enable = true;
# Use SIGKILL, or `tail` will catch SIGTERM and exit successfully.
freeMemKillThreshold = 90;
};

systemd.services.testbloat = {
description = "Create a lot of memory pressure";
serviceConfig = {
ExecStart = "${pkgs.coreutils}/bin/tail /dev/zero";
};
};
};

testScript = ''
machine.wait_for_unit("earlyoom.service")
with subtest("earlyoom should kill the bad service"):
machine.fail("systemctl start --wait testbloat.service")
assert machine.get_unit_info("testbloat.service")["Result"] == "signal"
output = machine.succeed('journalctl -u earlyoom.service -b0')
assert 'low memory! at or below SIGKILL limits' in output
'';
})

0 comments on commit 47916b5

Please sign in to comment.