-
-
Notifications
You must be signed in to change notification settings - Fork 14.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: phanirithvij <[email protected]>
- Loading branch information
1 parent
85fa07b
commit 8b294f1
Showing
2 changed files
with
74 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
import ./make-test-python.nix ( | ||
{ pkgs, lib, ... }: | ||
|
||
{ | ||
name = "swapspace"; | ||
|
||
meta = with pkgs.lib.maintainers; { | ||
maintainers = [ | ||
Luflosi | ||
phanirithvij | ||
]; | ||
}; | ||
|
||
nodes.machine = { | ||
virtualisation.memorySize = 256; | ||
systemd.oomd.extraConfig.DefaultMemoryPressureDurationSec = "1s"; | ||
|
||
services.swapspace = { | ||
enable = true; | ||
extraArgs = [ "-v" ]; | ||
settings = { | ||
# test outside /var/lib/swapspace | ||
swappath = "/root/swamp"; | ||
cooldown = 1; | ||
}; | ||
}; | ||
|
||
# adopted from systemd-oomd test | ||
systemd.slices.workload = { | ||
description = "Test slice for memory pressure kills"; | ||
sliceConfig = { | ||
MemoryAccounting = true; | ||
ManagedOOMMemoryPressure = "kill"; | ||
ManagedOOMMemoryPressureLimit = "90%"; | ||
}; | ||
}; | ||
|
||
systemd.services.testbloat = { | ||
description = "Create a lot of memory pressure"; | ||
serviceConfig = { | ||
Slice = "workload.slice"; | ||
MemoryHigh = "128M"; | ||
ExecStart = "${pkgs.coreutils}/bin/tail /dev/zero"; | ||
}; | ||
}; | ||
}; | ||
|
||
testScript = '' | ||
machine.wait_for_unit("multi-user.target") | ||
machine.wait_for_unit("swapspace.service") | ||
print(machine.succeed("systemctl status swapspace.service")) | ||
print(machine.succeed("swapon --show")) | ||
swamp = False | ||
with subtest("OOMd should kill the bad service"): | ||
machine.succeed("systemctl start testbloat.service") | ||
# wait for a maximum of 45sec | ||
for i in range(1, 11): | ||
status = machine.get_unit_info("testbloat.service")["Result"] | ||
out = machine.succeed("swapon --show") | ||
print(out) | ||
swamp = "/swamp" in out | ||
if status == "oom-kill": | ||
break | ||
machine.sleep(i) | ||
print(machine.succeed("swapspace -e -s /root/swamp")) | ||
assert machine.succeed("swapon --show") == "" | ||
assert swamp | ||
''; | ||
} | ||
) |