2021-09-07 19:44:12 +02:00
|
|
|
import ./make-test-python.nix ({ pkgs, ... }: {
|
|
|
|
name = "invidious";
|
|
|
|
|
|
|
|
meta = with pkgs.lib.maintainers; {
|
|
|
|
maintainers = [ sbruder ];
|
|
|
|
};
|
|
|
|
|
2023-11-06 14:23:24 +01:00
|
|
|
nodes = {
|
|
|
|
postgres-tcp = { config, pkgs, ... }: {
|
|
|
|
services.postgresql = {
|
|
|
|
enable = true;
|
|
|
|
initialScript = pkgs.writeText "init-postgres-with-password" ''
|
2023-11-18 20:15:26 +01:00
|
|
|
CREATE USER invidious WITH PASSWORD 'correct horse battery staple';
|
|
|
|
CREATE DATABASE invidious WITH OWNER invidious;
|
2023-11-06 14:23:24 +01:00
|
|
|
'';
|
|
|
|
enableTCPIP = true;
|
|
|
|
authentication = ''
|
2023-11-18 20:15:26 +01:00
|
|
|
host invidious invidious samenet scram-sha-256
|
2023-11-06 14:23:24 +01:00
|
|
|
'';
|
|
|
|
};
|
2024-03-17 11:54:30 +01:00
|
|
|
networking.firewall.allowedTCPPorts = [ config.services.postgresql.settings.port ];
|
2021-09-07 19:44:12 +02:00
|
|
|
};
|
2024-08-27 07:54:27 +02:00
|
|
|
machine = { lib, pkgs, ... }: {
|
2023-11-06 14:23:24 +01:00
|
|
|
services.invidious = {
|
|
|
|
enable = true;
|
2021-09-07 19:44:12 +02:00
|
|
|
};
|
2023-11-06 14:23:24 +01:00
|
|
|
|
|
|
|
specialisation = {
|
|
|
|
nginx.configuration = {
|
|
|
|
services.invidious = {
|
|
|
|
nginx.enable = true;
|
|
|
|
domain = "invidious.example.com";
|
2021-09-07 19:44:12 +02:00
|
|
|
};
|
2023-11-06 14:23:24 +01:00
|
|
|
services.nginx.virtualHosts."invidious.example.com" = {
|
|
|
|
forceSSL = false;
|
|
|
|
enableACME = false;
|
|
|
|
};
|
|
|
|
networking.hosts."127.0.0.1" = [ "invidious.example.com" ];
|
2021-09-07 19:44:12 +02:00
|
|
|
};
|
2023-11-06 14:34:42 +01:00
|
|
|
nginx-scale.configuration = {
|
|
|
|
services.invidious = {
|
|
|
|
nginx.enable = true;
|
|
|
|
domain = "invidious.example.com";
|
|
|
|
serviceScale = 3;
|
|
|
|
};
|
|
|
|
services.nginx.virtualHosts."invidious.example.com" = {
|
|
|
|
forceSSL = false;
|
|
|
|
enableACME = false;
|
|
|
|
};
|
|
|
|
networking.hosts."127.0.0.1" = [ "invidious.example.com" ];
|
|
|
|
};
|
2023-11-06 17:54:28 +01:00
|
|
|
nginx-scale-ytproxy.configuration = {
|
|
|
|
services.invidious = {
|
|
|
|
nginx.enable = true;
|
|
|
|
http3-ytproxy.enable = true;
|
|
|
|
domain = "invidious.example.com";
|
|
|
|
serviceScale = 3;
|
|
|
|
};
|
|
|
|
services.nginx.virtualHosts."invidious.example.com" = {
|
|
|
|
forceSSL = false;
|
|
|
|
enableACME = false;
|
|
|
|
};
|
|
|
|
networking.hosts."127.0.0.1" = [ "invidious.example.com" ];
|
|
|
|
};
|
2023-11-06 14:23:24 +01:00
|
|
|
postgres-tcp.configuration = {
|
|
|
|
services.invidious = {
|
|
|
|
database = {
|
|
|
|
createLocally = false;
|
|
|
|
host = "postgres-tcp";
|
|
|
|
passwordFile = toString (pkgs.writeText "database-password" "correct horse battery staple");
|
|
|
|
};
|
2021-09-07 19:44:12 +02:00
|
|
|
};
|
2023-11-06 14:23:24 +01:00
|
|
|
};
|
2021-09-07 19:44:12 +02:00
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
testScript = { nodes, ... }: ''
|
|
|
|
def curl_assert_status_code(url, code, form=None):
|
|
|
|
assert int(machine.succeed(f"curl -s -o /dev/null -w %{{http_code}} {'-F ' + form + ' ' if form else '''}{url}")) == code
|
|
|
|
|
|
|
|
|
|
|
|
def activate_specialisation(name: str):
|
2024-08-27 07:54:27 +02:00
|
|
|
machine.succeed(f"${nodes.machine.system.build.toplevel}/specialisation/{name}/bin/switch-to-configuration test >&2")
|
2021-09-07 19:44:12 +02:00
|
|
|
|
|
|
|
|
2024-08-27 07:54:27 +02:00
|
|
|
url = "http://localhost:${toString nodes.machine.services.invidious.port}"
|
|
|
|
port = ${toString nodes.machine.services.invidious.port}
|
2021-09-07 19:44:12 +02:00
|
|
|
|
2023-11-06 14:23:24 +01:00
|
|
|
# start postgres vm now
|
|
|
|
postgres_tcp.start()
|
|
|
|
|
2021-09-07 19:44:12 +02:00
|
|
|
machine.wait_for_open_port(port)
|
|
|
|
curl_assert_status_code(f"{url}/search", 200)
|
|
|
|
|
|
|
|
activate_specialisation("nginx")
|
|
|
|
machine.wait_for_open_port(80)
|
|
|
|
curl_assert_status_code("http://invidious.example.com/search", 200)
|
|
|
|
|
2023-11-06 14:34:42 +01:00
|
|
|
activate_specialisation("nginx-scale")
|
|
|
|
machine.wait_for_open_port(80)
|
|
|
|
# this depends on nginx round-robin behaviour for the upstream servers
|
|
|
|
curl_assert_status_code("http://invidious.example.com/search", 200)
|
|
|
|
curl_assert_status_code("http://invidious.example.com/search", 200)
|
|
|
|
curl_assert_status_code("http://invidious.example.com/search", 200)
|
|
|
|
machine.succeed("journalctl -eu invidious.service | grep -o '200 GET /search'")
|
|
|
|
machine.succeed("journalctl -eu invidious-1.service | grep -o '200 GET /search'")
|
|
|
|
machine.succeed("journalctl -eu invidious-2.service | grep -o '200 GET /search'")
|
|
|
|
|
2023-11-06 17:54:28 +01:00
|
|
|
activate_specialisation("nginx-scale-ytproxy")
|
|
|
|
machine.wait_for_unit("http3-ytproxy.service")
|
|
|
|
machine.wait_for_open_port(80)
|
|
|
|
machine.wait_until_succeeds("ls /run/http3-ytproxy/socket/http-proxy.sock")
|
|
|
|
curl_assert_status_code("http://invidious.example.com/search", 200)
|
|
|
|
# this should error out as no internet connectivity is available in the test
|
|
|
|
curl_assert_status_code("http://invidious.example.com/vi/dQw4w9WgXcQ/mqdefault.jpg", 502)
|
|
|
|
machine.succeed("journalctl -eu http3-ytproxy.service | grep -o 'dQw4w9WgXcQ'")
|
|
|
|
|
2023-11-06 14:23:24 +01:00
|
|
|
postgres_tcp.wait_for_unit("postgresql.service")
|
2021-09-07 19:44:12 +02:00
|
|
|
activate_specialisation("postgres-tcp")
|
|
|
|
machine.wait_for_open_port(port)
|
|
|
|
curl_assert_status_code(f"{url}/search", 200)
|
|
|
|
'';
|
|
|
|
})
|