Release NixOS 23.11
[NixPkgs.git] / nixos / tests / haproxy.nix
blob555474d7f2999a4724afb42e528b0fe1149eb2d5
1 import ./make-test-python.nix ({ pkgs, ...}: {
2   name = "haproxy";
3   nodes = {
4     machine = { ... }: {
5       services.haproxy = {
6         enable = true;
7         config = ''
8           defaults
9             timeout connect 10s
11           backend http_server
12             mode http
13             server httpd [::1]:8000
15           frontend http
16             bind *:80
17             mode http
18             http-request use-service prometheus-exporter if { path /metrics }
19             use_backend http_server
20         '';
21       };
22       services.httpd = {
23         enable = true;
24         virtualHosts.localhost = {
25           documentRoot = pkgs.writeTextDir "index.txt" "We are all good!";
26           adminAddr = "notme@yourhost.local";
27           listen = [{
28             ip = "::1";
29             port = 8000;
30           }];
31         };
32       };
33     };
34   };
35   testScript = ''
36     start_all()
37     machine.wait_for_unit("multi-user.target")
38     machine.wait_for_unit("haproxy.service")
39     machine.wait_for_unit("httpd.service")
40     assert "We are all good!" in machine.succeed("curl -fk http://localhost:80/index.txt")
41     assert "haproxy_process_pool_allocated_bytes" in machine.succeed(
42         "curl -fk http://localhost:80/metrics"
43     )
45     with subtest("reload"):
46         machine.succeed("systemctl reload haproxy")
47         # wait some time to ensure the following request hits the reloaded haproxy
48         machine.sleep(5)
49         assert "We are all good!" in machine.succeed(
50             "curl -fk http://localhost:80/index.txt"
51         )
52   '';