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