summaryrefslogtreecommitdiffstats
path: root/nixos/tests/velocity.nix
blob: d448e5fa7255def7c66b0077e492cdb1b7f25658 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
{ lib, pkgs, ... }:
{
  name = "velocity";
  meta.maintainers = [ lib.maintainers.Tert0 ];

  nodes.server =
    { ... }:
    {
      imports =
        let
          mkVelocityService = name: pkg: {
            systemd.sockets.${name} = {
              socketConfig = {
                ListenFIFO = "/run/${name}.stdin";
                Service = "${name}";
              };
            };
            systemd.services.${name} = {
              serviceConfig = {
                ExecStart = "${pkg}/bin/velocity";
                DynamicUser = true;
                StateDirectory = "${name}";
                WorkingDirectory = "/var/lib/${name}";

                Sockets = "${name}.socket";
                StandardInput = "socket";
                StandardOutput = "journal";
                StandardError = "journal";
              };
            };
          };
        in
        [
          (mkVelocityService "velocity-without-native" (
            pkgs.velocity.override { withVelocityNative = false; }
          ))
          (mkVelocityService "velocity-with-native" (pkgs.velocity.override { withVelocityNative = true; }))
        ];

      environment.systemPackages = [ (pkgs.python3.withPackages (p: [ p.mcstatus ])) ];
    };

  testScript = ''
    def test_velocity(name: str, native: bool):
      server.start_job(name)
      server.wait_for_unit(name);
      server.wait_for_open_port(25565)
      server.wait_until_succeeds(f"journalctl -b -u {name} | grep -q 'Booting up Velocity nixpkgs-${pkgs.velocity.version}...'")
      connections_startup_query = "Connections will use epoll channels, libdeflate (.+) compression, OpenSSL 3.x.x (.+) ciphers" if native else "Connections will use epoll channels, Java compression, Java ciphers"
      server.wait_until_succeeds(f"journalctl -b -u {name} | grep -q -E '{connections_startup_query}'")
      server.wait_until_succeeds(f"journalctl -b -u {name} | grep -q 'Done ([0-9]*.[0-9]*s)!'");

      _, status_result = server.execute("python -m mcstatus localhost:25565 status")
      assert "A Velocity Server" in status_result

      server.execute(f"echo stop > /run/{name}.stdin")
      server.wait_for_closed_port(25565);

    test_velocity("velocity-without-native", False)
    test_velocity("velocity-with-native", True)
  '';
}