nixos/h2o: wait for open ports in tests

Hydra can sometimes timeout here. It’s a better practice anyhow.
This commit is contained in:
โทสฺตัล 2025-03-21 19:03:57 +07:00
parent 5f5d8946f6
commit b828ba3247
3 changed files with 24 additions and 9 deletions

View file

@ -110,27 +110,34 @@ import ../../make-test-python.nix (
};
};
testScript = # python
testScript =
let
portStrHTTP = builtins.toString port.HTTP;
portStrTLS = builtins.toString port.TLS;
in
# python
''
server.wait_for_unit("h2o.service")
server.wait_for_open_port(${portStrHTTP})
server.wait_for_open_port(${portStrTLS})
http_hello_world_body = server.succeed("curl --fail-with-body 'http://${domain.HTTP}:${builtins.toString port.HTTP}/hello_world.txt'")
http_hello_world_body = server.succeed("curl --fail-with-body 'http://${domain.HTTP}:${portStrHTTP}/hello_world.txt'")
assert "${sawatdi_chao_lok}" in http_hello_world_body
tls_hello_world_head = server.succeed("curl -v --head --compressed --http2 --tlsv1.3 --fail-with-body 'https://${domain.TLS}:${builtins.toString port.TLS}/hello_world.rst'").lower()
tls_hello_world_head = server.succeed("curl -v --head --compressed --http2 --tlsv1.3 --fail-with-body 'https://${domain.TLS}:${portStrTLS}/hello_world.rst'").lower()
assert "http/2 200" in tls_hello_world_head
assert "server: h2o" in tls_hello_world_head
assert "content-type: text/x-rst" in tls_hello_world_head
tls_hello_world_body = server.succeed("curl -v --http2 --tlsv1.3 --compressed --fail-with-body 'https://${domain.TLS}:${builtins.toString port.TLS}/hello_world.rst'")
tls_hello_world_body = server.succeed("curl -v --http2 --tlsv1.3 --compressed --fail-with-body 'https://${domain.TLS}:${portStrTLS}/hello_world.rst'")
assert "${sawatdi_chao_lok}" in tls_hello_world_body
tls_hello_world_head_redirected = server.succeed("curl -v --head --fail-with-body 'http://${domain.TLS}:${builtins.toString port.HTTP}/hello_world.rst'").lower()
assert "redirected" in tls_hello_world_head_redirected
server.fail("curl --location --max-redirs 0 'http://${domain.TLS}:${builtins.toString port.HTTP}/hello_world.rst'")
server.fail("curl --location --max-redirs 0 'http://${domain.TLS}:${portStrHTTP}/hello_world.rst'")
tls_hello_world_body_redirected = server.succeed("curl -v --location --fail-with-body 'http://${domain.TLS}:${builtins.toString port.HTTP}/hello_world.rst'")
tls_hello_world_body_redirected = server.succeed("curl -v --location --fail-with-body 'http://${domain.TLS}:${portStrHTTP}/hello_world.rst'")
assert "${sawatdi_chao_lok}" in tls_hello_world_body_redirected
'';
}

View file

@ -50,14 +50,19 @@ import ../../make-test-python.nix (
};
};
testScript = # python
testScript =
let
portStr = builtins.toString port;
in
# python
''
server.wait_for_unit("h2o.service")
server.wait_for_open_port(${portStr})
hello_world = server.succeed("curl --fail-with-body http://${domain}:${builtins.toString port}/hello_world")
hello_world = server.succeed("curl --fail-with-body http://${domain}:${portStr}/hello_world")
assert "${sawatdi_chao_lok}" in hello_world
file_handler = server.succeed("curl --fail-with-body http://${domain}:${builtins.toString port}/file_handler")
file_handler = server.succeed("curl --fail-with-body http://${domain}:${portStr}/file_handler")
assert "FILE_HANDLER" in file_handler
'';
}

View file

@ -87,6 +87,7 @@ import ../../make-test-python.nix (
curl_max_tls1_2_old_cipher ="curl -v --tlsv1.0 --tls-max 1.2 --ciphers 'ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA256:DHE-RSA-AES128-SHA256' 'https://${domain}:${portStr}/'"
server_modern.wait_for_unit("h2o.service")
server_modern.wait_for_open_port(${portStr})
modern_response = server_modern.succeed(curl_basic)
assert "Hello, modern!" in modern_response
modern_head = server_modern.succeed(curl_head)
@ -94,6 +95,7 @@ import ../../make-test-python.nix (
server_modern.fail(curl_max_tls1_2)
server_intermediate.wait_for_unit("h2o.service")
server_intermediate.wait_for_open_port(${portStr})
intermediate_response = server_intermediate.succeed(curl_basic)
assert "Hello, intermediate!" in intermediate_response
intermediate_head = server_modern.succeed(curl_head)
@ -103,6 +105,7 @@ import ../../make-test-python.nix (
server_intermediate.fail(curl_max_tls1_2_old_cipher)
server_old.wait_for_unit("h2o.service")
server_old.wait_for_open_port(${portStr})
old_response = server_old.succeed(curl_basic)
assert "Hello, old!" in old_response
old_head = server_modern.succeed(curl_head)