1import ./make-test-python.nix (
2 { lib, ... }:
3 {
4 name = "earlyoom";
5 meta = {
6 maintainers = with lib.maintainers; [
7 ncfavier
8 oxalica
9 ];
10 };
11
12 nodes.machine =
13 { pkgs, ... }:
14 {
15 # Limit VM resource usage.
16 virtualisation.memorySize = 1024;
17
18 services.earlyoom = {
19 enable = true;
20 # Use SIGKILL, or `tail` will catch SIGTERM and exit successfully.
21 freeMemKillThreshold = 90;
22 };
23
24 systemd.services.testbloat = {
25 description = "Create a lot of memory pressure";
26 serviceConfig = {
27 ExecStart = "${pkgs.coreutils}/bin/tail /dev/zero";
28 };
29 };
30 };
31
32 testScript = ''
33 machine.wait_for_unit("earlyoom.service")
34
35 with subtest("earlyoom should kill the bad service"):
36 machine.fail("systemctl start --wait testbloat.service")
37 assert machine.get_unit_info("testbloat.service")["Result"] == "signal"
38 output = machine.succeed('journalctl -u earlyoom.service -b0')
39 assert 'low memory! at or below SIGKILL limits' in output
40 '';
41 }
42)