3
0
Fork 0
forked from mirrors/nixpkgs
nixpkgs/nixos/tests/haproxy.nix

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

54 lines
1.5 KiB
Nix
Raw Normal View History

import ./make-test-python.nix ({ pkgs, ...}: {
2018-06-08 21:30:24 +01:00
name = "haproxy";
nodes = {
machine = { ... }: {
2018-06-08 21:30:24 +01:00
services.haproxy = {
enable = true;
config = ''
defaults
timeout connect 10s
backend http_server
mode http
server httpd [::1]:8000
frontend http
bind *:80
mode http
http-request use-service prometheus-exporter if { path /metrics }
2018-06-08 21:30:24 +01:00
use_backend http_server
'';
};
services.httpd = {
enable = true;
virtualHosts.localhost = {
documentRoot = pkgs.writeTextDir "index.txt" "We are all good!";
adminAddr = "notme@yourhost.local";
listen = [{
ip = "::1";
port = 8000;
}];
};
2018-06-08 21:30:24 +01:00
};
};
};
testScript = ''
start_all()
machine.wait_for_unit("multi-user.target")
machine.wait_for_unit("haproxy.service")
machine.wait_for_unit("httpd.service")
2020-09-15 23:38:02 +01:00
assert "We are all good!" in machine.succeed("curl -fk http://localhost:80/index.txt")
assert "haproxy_process_pool_allocated_bytes" in machine.succeed(
2020-09-15 23:38:02 +01:00
"curl -fk http://localhost:80/metrics"
)
with subtest("reload"):
machine.succeed("systemctl reload haproxy")
# wait some time to ensure the following request hits the reloaded haproxy
machine.sleep(5)
assert "We are all good!" in machine.succeed(
2020-09-15 23:38:02 +01:00
"curl -fk http://localhost:80/index.txt"
)
2018-06-08 21:30:24 +01:00
'';
})