1 import ./make-test-python.nix ({ pkgs, ... }: {
4 meta = with pkgs.lib.maintainers; {
5 maintainers = [ sbruder ];
9 postgres-tcp = { config, pkgs, ... }: {
10 services.postgresql = {
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;
18 host invidious invidious samenet scram-sha-256
21 networking.firewall.allowedTCPPorts = [ config.services.postgresql.settings.port ];
23 machine = { config, lib, pkgs, ... }: {
24 services.invidious = {
29 nginx.configuration = {
30 services.invidious = {
32 domain = "invidious.example.com";
34 services.nginx.virtualHosts."invidious.example.com" = {
38 networking.hosts."127.0.0.1" = [ "invidious.example.com" ];
40 nginx-scale.configuration = {
41 services.invidious = {
43 domain = "invidious.example.com";
46 services.nginx.virtualHosts."invidious.example.com" = {
50 networking.hosts."127.0.0.1" = [ "invidious.example.com" ];
52 nginx-scale-ytproxy.configuration = {
53 services.invidious = {
55 http3-ytproxy.enable = true;
56 domain = "invidious.example.com";
59 services.nginx.virtualHosts."invidious.example.com" = {
63 networking.hosts."127.0.0.1" = [ "invidious.example.com" ];
65 postgres-tcp.configuration = {
66 services.invidious = {
68 createLocally = false;
69 host = "postgres-tcp";
70 passwordFile = toString (pkgs.writeText "database-password" "correct horse battery staple");
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
83 def activate_specialisation(name: str):
84 machine.succeed(f"${nodes.machine.config.system.build.toplevel}/specialisation/{name}/bin/switch-to-configuration test >&2")
87 url = "http://localhost:${toString nodes.machine.config.services.invidious.port}"
88 port = ${toString nodes.machine.config.services.invidious.port}
90 # start postgres vm now
93 machine.wait_for_open_port(port)
94 curl_assert_status_code(f"{url}/search", 200)
96 activate_specialisation("nginx")
97 machine.wait_for_open_port(80)
98 curl_assert_status_code("http://invidious.example.com/search", 200)
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'")
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'")
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)