lol

nixos/tests/systemd-oomd: fix and follows upstream tests

The current test triggers the kernel OOM killer and doesn't work well.

oxalica 9fca212c 7002a549

+36 -19
+36 -19
nixos/tests/systemd-oomd.nix
··· 3 3 { 4 4 name = "systemd-oomd"; 5 5 6 + # This test is a simplified version of systemd's testsuite-55. 7 + # https://github.com/systemd/systemd/blob/v251/test/units/testsuite-55.sh 6 8 nodes.machine = { pkgs, ... }: { 7 - systemd.oomd.extraConfig.DefaultMemoryPressureDurationSec = "1s"; # makes the test faster 8 - # Kill cgroups when more than 1% pressure is encountered 9 - systemd.slices."-".sliceConfig = { 10 - ManagedOOMMemoryPressure = "kill"; 11 - ManagedOOMMemoryPressureLimit = "1%"; 9 + # Limit VM resource usage. 10 + virtualisation.memorySize = 1024; 11 + systemd.oomd.extraConfig.DefaultMemoryPressureDurationSec = "1s"; 12 + 13 + systemd.slices.workload = { 14 + description = "Test slice for memory pressure kills"; 15 + sliceConfig = { 16 + MemoryAccounting = true; 17 + ManagedOOMMemoryPressure = "kill"; 18 + ManagedOOMMemoryPressureLimit = "10%"; 19 + }; 12 20 }; 13 - # A service to bring the system under memory pressure 14 - systemd.services.testservice = { 15 - serviceConfig.ExecStart = "${pkgs.coreutils}/bin/tail /dev/zero"; 21 + 22 + systemd.services.testbloat = { 23 + description = "Create a lot of memory pressure"; 24 + serviceConfig = { 25 + Slice = "workload.slice"; 26 + MemoryHigh = "5M"; 27 + ExecStart = "${pkgs.coreutils}/bin/tail /dev/zero"; 28 + }; 16 29 }; 17 - # Do not kill the backdoor 18 - systemd.services.backdoor.serviceConfig.ManagedOOMMemoryPressure = "auto"; 19 30 20 - virtualisation.memorySize = 1024; 31 + systemd.services.testchill = { 32 + description = "No memory pressure"; 33 + serviceConfig = { 34 + Slice = "workload.slice"; 35 + MemoryHigh = "3M"; 36 + ExecStart = "${pkgs.coreutils}/bin/sleep infinity"; 37 + }; 38 + }; 21 39 }; 22 40 23 41 testScript = '' 24 - # Start the system 42 + # Start the system. 25 43 machine.wait_for_unit("multi-user.target") 26 44 machine.succeed("oomctl") 27 45 28 - # Bring the system into memory pressure 29 - machine.succeed("echo 0 > /proc/sys/vm/panic_on_oom") # NixOS tests kill the VM when the OOM killer is invoked - override this 30 - machine.succeed("systemctl start testservice") 46 + machine.succeed("systemctl start testchill.service") 47 + with subtest("OOMd should kill the bad service"): 48 + machine.fail("systemctl start --wait testbloat.service") 49 + assert machine.get_unit_info("testbloat.service")["Result"] == "oom-kill" 31 50 32 - # Wait for oomd to kill something 33 - # Matches these lines: 34 - # systemd-oomd[508]: Killed /system.slice/systemd-udevd.service due to memory pressure for / being 3.26% > 1.00% for > 1s with reclaim activity 35 - machine.wait_until_succeeds("journalctl -b | grep -q 'due to memory pressure for'") 51 + with subtest("Service without memory pressure should be untouched"): 52 + machine.require_unit_state("testchill.service", "active") 36 53 ''; 37 54 })