summaryrefslogtreecommitdiffstats
path: root/nixos/tests/postgresql/postgresql-jit.nix
blob: de62b355d62ba66d72777b408299f84e665d9ca6 (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
{
  runTest,
  genTests,
  ...
}:

let
  makeTestFor =
    package:
    runTest (
      { lib, pkgs, ... }:
      {
        name = "postgresql-jit-${package.name}";
        meta.maintainers = with lib.maintainers; [ ma27 ];

        nodes.machine =
          { pkgs, ... }:
          {
            services.postgresql = {
              inherit package;
              enable = true;
              enableJIT = true;
              initialScript = pkgs.writeText "init.sql" ''
                create table demo (id int);
                insert into demo (id) select generate_series(1, 5);
              '';
            };
          };

        testScript = ''
          machine.start()
          machine.wait_for_unit("postgresql.target")

          with subtest("JIT is enabled"):
              machine.succeed("sudo -u postgres psql <<<'show jit;' | grep 'on'")

          with subtest("Test JIT works fine"):
              output = machine.succeed(
                  "cat ${pkgs.writeText "test.sql" ''
                    set jit_above_cost = 1;
                    EXPLAIN ANALYZE SELECT CONCAT('jit result = ', SUM(id)) FROM demo;
                    SELECT CONCAT('jit result = ', SUM(id)) from demo;
                  ''} | sudo -u postgres psql"
              )
              t.assertIn("JIT:", output)
              t.assertIn("jit result = 15", output)

          machine.shutdown()
        '';
      }
    );
in
genTests {
  inherit makeTestFor;
}