Files
nixpkgs/nixos/tests/postgresql/postgresql-jit.nix
T
Maximilian Bosch a6bbde82dc nixos/tests/postgresql: switch to unittest-style assertions
This has the benefit that we don't have to write ad-hoc code anymore for
showing the different, `unittest` takes care of that for us already.
2025-12-22 12:56:11 +01:00

55 lines
1.3 KiB
Nix

{
pkgs,
makeTest,
genTests,
}:
let
inherit (pkgs) lib;
makeTestFor =
package:
makeTest {
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;
}