2023-03-30 22:05:00 +00:00
|
|
|
{ system ? builtins.currentSystem
|
|
|
|
, config ? {}
|
|
|
|
, pkgs ? import ../.. { inherit system config; }
|
2024-05-15 15:35:15 +00:00
|
|
|
, package ? null
|
2023-03-30 22:05:00 +00:00
|
|
|
}:
|
|
|
|
|
|
|
|
with import ../lib/testing-python.nix { inherit system pkgs; };
|
|
|
|
|
|
|
|
let
|
|
|
|
inherit (pkgs) lib;
|
|
|
|
packages = builtins.attrNames (import ../../pkgs/servers/sql/postgresql pkgs);
|
|
|
|
|
2024-05-15 15:35:15 +00:00
|
|
|
mkJitTestFromName = name:
|
|
|
|
mkJitTest pkgs.${name};
|
|
|
|
|
|
|
|
mkJitTest = package: makeTest {
|
|
|
|
name = package.name;
|
2023-03-30 22:05:00 +00:00
|
|
|
meta.maintainers = with lib.maintainers; [ ma27 ];
|
|
|
|
nodes.machine = { pkgs, lib, ... }: {
|
|
|
|
services.postgresql = {
|
2024-05-15 15:35:15 +00:00
|
|
|
inherit package;
|
2023-03-30 22:05:00 +00:00
|
|
|
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.service")
|
|
|
|
|
|
|
|
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"
|
|
|
|
)
|
|
|
|
assert "JIT:" in output
|
|
|
|
assert "jit result = 15" in output
|
|
|
|
|
|
|
|
machine.shutdown()
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
in
|
2024-05-15 15:35:15 +00:00
|
|
|
if package == null then
|
|
|
|
lib.genAttrs packages mkJitTestFromName
|
|
|
|
else
|
|
|
|
mkJitTest package
|