blob: 8b7c4ec0ca1598177d36e6bd53837c65787302c0 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
|
# The following was modified from ./earlyoom.nix
{ lib, pkgs, ... }:
{
name = "nohang";
meta = {
maintainers = with lib.maintainers; [
Dev380
];
};
nodes.machine =
{ pkgs, ... }:
{
# Limit VM resource usage.
virtualisation.memorySize = 1024;
services.nohang.enable = true;
# disable other oom killers just in case
systemd.oomd.enable = false;
systemd.services.testbloat = {
description = "Create a lot of memory pressure";
serviceConfig = {
ExecStart = "${lib.getExe' pkgs.coreutils "tail"} /dev/zero";
};
};
};
# SIGTERM may be given so tail /dev/zero may or may not succeed
# The output will have have something like "Sending SIGTERM to /nix/store/87fc"
# with the truncated path so we'll check for that in the test
testScript = ''
machine.wait_for_unit("nohang.service")
with subtest("nohang should kill the bad service"):
machine.execute("systemctl start --wait testbloat.service")
signal_type = None
match machine.get_unit_info("testbloat.service")["Result"]:
case "signal":
signal_type = "SIGKILL"
case "success":
signal_type = "SIGTERM"
output = machine.succeed('journalctl -u nohang.service -b0')
if not f'[ OK ] Sending {signal_type}' in output:
raise Exception(f"'[ OK ] Sending {signal_type}' not in output")
if not 'The victim' in output:
raise Exception("'The victim' not in output")
if not 'Memory status after implementing a corrective action:' in output:
raise Exception("'Memory status after implementing a corrective action:' not in output")
if not 'FINISHING implement_corrective_action()' in output:
raise Exception("'FINISHING implement_corrective_action()' not in output")
if not f"{signal_type} to {'${pkgs.coreutils}'[:len('/nix/store/1234')]}: 1" in output:
raise Exception(f"'{signal_type} to {'${pkgs.coreutils}'[:len('/nix/store/1234')]}: 1' not in output")
'';
}
|