at 24.11-pre 4.6 kB view raw
1import ./make-test-python.nix ({ pkgs, ... }: { 2 name = "invidious"; 3 4 meta = with pkgs.lib.maintainers; { 5 maintainers = [ sbruder ]; 6 }; 7 8 nodes = { 9 postgres-tcp = { config, pkgs, ... }: { 10 services.postgresql = { 11 enable = true; 12 initialScript = pkgs.writeText "init-postgres-with-password" '' 13 CREATE USER invidious WITH PASSWORD 'correct horse battery staple'; 14 CREATE DATABASE invidious WITH OWNER invidious; 15 ''; 16 enableTCPIP = true; 17 authentication = '' 18 host invidious invidious samenet scram-sha-256 19 ''; 20 }; 21 networking.firewall.allowedTCPPorts = [ config.services.postgresql.settings.port ]; 22 }; 23 machine = { config, lib, pkgs, ... }: { 24 services.invidious = { 25 enable = true; 26 }; 27 28 specialisation = { 29 nginx.configuration = { 30 services.invidious = { 31 nginx.enable = true; 32 domain = "invidious.example.com"; 33 }; 34 services.nginx.virtualHosts."invidious.example.com" = { 35 forceSSL = false; 36 enableACME = false; 37 }; 38 networking.hosts."127.0.0.1" = [ "invidious.example.com" ]; 39 }; 40 nginx-scale.configuration = { 41 services.invidious = { 42 nginx.enable = true; 43 domain = "invidious.example.com"; 44 serviceScale = 3; 45 }; 46 services.nginx.virtualHosts."invidious.example.com" = { 47 forceSSL = false; 48 enableACME = false; 49 }; 50 networking.hosts."127.0.0.1" = [ "invidious.example.com" ]; 51 }; 52 nginx-scale-ytproxy.configuration = { 53 services.invidious = { 54 nginx.enable = true; 55 http3-ytproxy.enable = true; 56 domain = "invidious.example.com"; 57 serviceScale = 3; 58 }; 59 services.nginx.virtualHosts."invidious.example.com" = { 60 forceSSL = false; 61 enableACME = false; 62 }; 63 networking.hosts."127.0.0.1" = [ "invidious.example.com" ]; 64 }; 65 postgres-tcp.configuration = { 66 services.invidious = { 67 database = { 68 createLocally = false; 69 host = "postgres-tcp"; 70 passwordFile = toString (pkgs.writeText "database-password" "correct horse battery staple"); 71 }; 72 }; 73 }; 74 }; 75 }; 76 }; 77 78 testScript = { nodes, ... }: '' 79 def curl_assert_status_code(url, code, form=None): 80 assert int(machine.succeed(f"curl -s -o /dev/null -w %{{http_code}} {'-F ' + form + ' ' if form else '''}{url}")) == code 81 82 83 def activate_specialisation(name: str): 84 machine.succeed(f"${nodes.machine.config.system.build.toplevel}/specialisation/{name}/bin/switch-to-configuration test >&2") 85 86 87 url = "http://localhost:${toString nodes.machine.config.services.invidious.port}" 88 port = ${toString nodes.machine.config.services.invidious.port} 89 90 # start postgres vm now 91 postgres_tcp.start() 92 93 machine.wait_for_open_port(port) 94 curl_assert_status_code(f"{url}/search", 200) 95 96 activate_specialisation("nginx") 97 machine.wait_for_open_port(80) 98 curl_assert_status_code("http://invidious.example.com/search", 200) 99 100 activate_specialisation("nginx-scale") 101 machine.wait_for_open_port(80) 102 # this depends on nginx round-robin behaviour for the upstream servers 103 curl_assert_status_code("http://invidious.example.com/search", 200) 104 curl_assert_status_code("http://invidious.example.com/search", 200) 105 curl_assert_status_code("http://invidious.example.com/search", 200) 106 machine.succeed("journalctl -eu invidious.service | grep -o '200 GET /search'") 107 machine.succeed("journalctl -eu invidious-1.service | grep -o '200 GET /search'") 108 machine.succeed("journalctl -eu invidious-2.service | grep -o '200 GET /search'") 109 110 activate_specialisation("nginx-scale-ytproxy") 111 machine.wait_for_unit("http3-ytproxy.service") 112 machine.wait_for_open_port(80) 113 machine.wait_until_succeeds("ls /run/http3-ytproxy/socket/http-proxy.sock") 114 curl_assert_status_code("http://invidious.example.com/search", 200) 115 # this should error out as no internet connectivity is available in the test 116 curl_assert_status_code("http://invidious.example.com/vi/dQw4w9WgXcQ/mqdefault.jpg", 502) 117 machine.succeed("journalctl -eu http3-ytproxy.service | grep -o 'dQw4w9WgXcQ'") 118 119 postgres_tcp.wait_for_unit("postgresql.service") 120 activate_specialisation("postgres-tcp") 121 machine.wait_for_open_port(port) 122 curl_assert_status_code(f"{url}/search", 200) 123 ''; 124})