2022-05-02 17:50:57 +00:00
|
|
|
use strict;
|
|
|
|
use warnings;
|
|
|
|
use Setup;
|
|
|
|
use Test2::V0;
|
|
|
|
use Hydra::Helper::Exec;
|
|
|
|
|
2022-05-02 19:26:26 +00:00
|
|
|
# Ensure that `systemd-run` is
|
|
|
|
# - Available in the PATH/envionment
|
|
|
|
# - Accessable to the user executing it
|
|
|
|
# - Capable of using the command switches we use in our test
|
2022-05-02 19:13:59 +00:00
|
|
|
my $sd_res;
|
2022-05-02 18:40:13 +00:00
|
|
|
eval {
|
2022-05-02 19:13:59 +00:00
|
|
|
($sd_res) = captureStdoutStderr(3, (
|
2022-05-02 18:40:13 +00:00
|
|
|
"systemd-run",
|
|
|
|
"--user",
|
|
|
|
"--collect",
|
|
|
|
"--scope",
|
|
|
|
"--property",
|
|
|
|
"MemoryMax=25M",
|
|
|
|
"--",
|
|
|
|
"true"
|
|
|
|
));
|
|
|
|
} or do {
|
2022-05-02 19:26:26 +00:00
|
|
|
# The command failed to execute, likely because `systemd-run` is not present
|
|
|
|
# in `PATH`
|
2022-05-02 19:13:59 +00:00
|
|
|
skip_all("`systemd-run` failed when invoked in this environment");
|
2022-05-02 18:40:13 +00:00
|
|
|
};
|
2022-05-02 19:26:26 +00:00
|
|
|
if ($sd_res != 0) {
|
|
|
|
# `systemd-run` executed but `sytemd-run` failed to call `true` and return
|
|
|
|
# successfully
|
|
|
|
skip_all("`systemd-run` returned non-zero when executing `true` (expected 0)");
|
|
|
|
}
|
2022-05-02 18:08:50 +00:00
|
|
|
|
2022-05-02 19:14:46 +00:00
|
|
|
my $ctx = test_context();
|
|
|
|
|
2022-05-02 19:26:26 +00:00
|
|
|
# Contain the memory usage to 25 MegaBytes using `systemd-run`
|
|
|
|
# Run `hydra-eval-jobs` on test job that will purposefully consume all memory
|
|
|
|
# available
|
2022-05-02 18:40:13 +00:00
|
|
|
my ($res, $stdout, $stderr) = captureStdoutStderr(60, (
|
|
|
|
"systemd-run",
|
|
|
|
"--user",
|
|
|
|
"--collect",
|
|
|
|
"--scope",
|
|
|
|
"--property",
|
|
|
|
"MemoryMax=25M",
|
|
|
|
"--",
|
|
|
|
"hydra-eval-jobs",
|
|
|
|
"-I", "/dev/zero",
|
2022-05-02 19:14:46 +00:00
|
|
|
"-I", $ctx->jobsdir,
|
|
|
|
($ctx->jobsdir . "/oom.nix")
|
2022-05-02 18:40:13 +00:00
|
|
|
));
|
2022-05-02 17:50:57 +00:00
|
|
|
|
2022-05-02 19:14:46 +00:00
|
|
|
isnt($res, 0, "`hydra-eval-jobs` exits non-zero");
|
2022-05-02 17:50:57 +00:00
|
|
|
ok(utf8::decode($stderr), "Stderr output is UTF8-clean");
|
|
|
|
like(
|
2022-05-02 18:40:13 +00:00
|
|
|
$stderr,
|
2022-05-02 19:26:26 +00:00
|
|
|
# Assert error log contains messages added in PR
|
|
|
|
# https://github.com/NixOS/hydra/pull/1203
|
2022-05-02 18:40:13 +00:00
|
|
|
qr/^child process \(\d+?\) killed by signal=9$/m,
|
|
|
|
"The stderr record includes a relevant error message"
|
2022-05-02 17:50:57 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
done_testing;
|