at 23.11-pre 1.5 kB view raw
1import ./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 10 11 backend http_server 12 mode http 13 server httpd [::1]:8000 14 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 ) 44 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 ''; 53})