nixpkgs/nixos/tests/systemd-oomd.nix
Silvan Mosberger 4f0dadbf38 treewide: format all inactive Nix files
After final improvements to the official formatter implementation,
this commit now performs the first treewide reformat of Nix files using it.
This is part of the implementation of RFC 166.

Only "inactive" files are reformatted, meaning only files that
aren't being touched by any PR with activity in the past 2 months.
This is to avoid conflicts for PRs that might soon be merged.
Later we can do a full treewide reformat to get the rest,
which should not cause as many conflicts.

A CI check has already been running for some time to ensure that new and
already-formatted files are formatted, so the files being reformatted here
should also stay formatted.

This commit was automatically created and can be verified using

    nix-build a08b3a4d19.tar.gz \
      --argstr baseRev b32a094368
    result/bin/apply-formatting $NIXPKGS_PATH
2024-12-10 20:26:33 +01:00

59 lines
1.8 KiB
Nix

import ./make-test-python.nix (
{ pkgs, ... }:
{
name = "systemd-oomd";
# This test is a simplified version of systemd's testsuite-55.
# https://github.com/systemd/systemd/blob/v251/test/units/testsuite-55.sh
nodes.machine =
{ pkgs, ... }:
{
# Limit VM resource usage.
virtualisation.memorySize = 1024;
systemd.oomd.extraConfig.DefaultMemoryPressureDurationSec = "1s";
systemd.slices.workload = {
description = "Test slice for memory pressure kills";
sliceConfig = {
MemoryAccounting = true;
ManagedOOMMemoryPressure = "kill";
ManagedOOMMemoryPressureLimit = "10%";
};
};
systemd.services.testbloat = {
description = "Create a lot of memory pressure";
serviceConfig = {
Slice = "workload.slice";
MemoryHigh = "5M";
ExecStart = "${pkgs.coreutils}/bin/tail /dev/zero";
};
};
systemd.services.testchill = {
description = "No memory pressure";
serviceConfig = {
Slice = "workload.slice";
MemoryHigh = "3M";
ExecStart = "${pkgs.coreutils}/bin/sleep infinity";
};
};
};
testScript = ''
# Start the system.
machine.wait_for_unit("multi-user.target")
machine.succeed("oomctl")
machine.succeed("systemctl start testchill.service")
with subtest("OOMd should kill the bad service"):
machine.fail("systemctl start --wait testbloat.service")
assert machine.get_unit_info("testbloat.service")["Result"] == "oom-kill"
with subtest("Service without memory pressure should be untouched"):
machine.require_unit_state("testchill.service", "active")
'';
}
)