Skip to content

Commit 433ebb7

Browse files
jfrochesamrose
authored andcommitted
feat: rebase nixos tests
Use extension test library Test postgresql 15 only Add pg_regress tests
1 parent 9c2bd63 commit 433ebb7

File tree

2 files changed

+53
-99
lines changed

2 files changed

+53
-99
lines changed

nix/ext/plv8/default.nix

Lines changed: 26 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
darwin,
1414
patchelf,
1515
buildEnv,
16-
nodejs_20
16+
nodejs_20,
1717
}:
1818

1919
let
@@ -49,19 +49,19 @@ let
4949
inherit hash;
5050
};
5151

52-
patches = [
53-
# Allow building with system v8.
54-
# https://github.com/plv8/plv8/pull/505 (rejected)
55-
./0001-build-Allow-using-V8-from-system-${version}.patch
56-
] ++ lib.optionals (builtins.compareVersions "3.1.10" version >= 0) [
57-
# Apply https://github.com/plv8/plv8/pull/552/ patch to fix extension upgrade problems
58-
./0001-fix-upgrade-related-woes-with-GUC-redefinitions-${version}.patch
59-
];
60-
61-
nativeBuildInputs =
52+
patches =
6253
[
63-
perl
54+
# Allow building with system v8.
55+
# https://github.com/plv8/plv8/pull/505 (rejected)
56+
./0001-build-Allow-using-V8-from-system-${version}.patch
6457
]
58+
++ lib.optionals (builtins.compareVersions "3.1.10" version >= 0) [
59+
# Apply https://github.com/plv8/plv8/pull/552/ patch to fix extension upgrade problems
60+
./0001-fix-upgrade-related-woes-with-GUC-redefinitions-${version}.patch
61+
];
62+
63+
nativeBuildInputs =
64+
[ perl ]
6565
++ lib.optionals stdenv.isDarwin [
6666
clang
6767
xcbuild
@@ -91,9 +91,7 @@ let
9191
"CXX=${clang}/bin/clang++"
9292
"SHLIB_LINK=-L${v8}/lib -lv8_monolith -Wl,-rpath,${v8}/lib"
9393
]
94-
++ lib.optionals (!stdenv.isDarwin) [
95-
"SHLIB_LINK=-lv8"
96-
];
94+
++ lib.optionals (!stdenv.isDarwin) [ "SHLIB_LINK=-lv8" ];
9795

9896
NIX_LDFLAGS = lib.optionals stdenv.isDarwin [
9997
"-L${postgresql}/lib"
@@ -145,9 +143,11 @@ let
145143
install_name_tool -change @rpath/libv8_monolith.dylib ${v8}/lib/libv8_monolith.dylib $out/lib/$LIB_NAME
146144
''}
147145
148-
${lib.optionalString (!stdenv.isDarwin) ''
149-
${patchelf}/bin/patchelf --set-rpath "${v8}/lib:${postgresql}/lib:${stdenv.cc.cc.lib}/lib" $out/lib/$LIB_NAME
150-
''}
146+
${
147+
lib.optionalString (!stdenv.isDarwin) ''
148+
${patchelf}/bin/patchelf --set-rpath "${v8}/lib:${postgresql}/lib:${stdenv.cc.cc.lib}/lib" $out/lib/$LIB_NAME
149+
''
150+
}
151151
else
152152
${lib.optionalString stdenv.isDarwin ''
153153
install_name_tool -add_rpath "${v8}/lib" $out/lib/$LIB_NAME
@@ -156,13 +156,17 @@ let
156156
install_name_tool -change @rpath/libv8_monolith.dylib ${v8}/lib/libv8_monolith.dylib $out/lib/$LIB_NAME
157157
''}
158158
159-
${lib.optionalString (!stdenv.isDarwin) ''
160-
${patchelf}/bin/patchelf --set-rpath "${v8}/lib:${postgresql}/lib:${stdenv.cc.cc.lib}/lib" $out/lib/$LIB_NAME
161-
''}
159+
${
160+
lib.optionalString (!stdenv.isDarwin) ''
161+
${patchelf}/bin/patchelf --set-rpath "${v8}/lib:${postgresql}/lib:${stdenv.cc.cc.lib}/lib" $out/lib/$LIB_NAME
162+
''
163+
}
162164
fi
163165
164166
# plv8 3.2.x removed support for coffeejs and livescript
165-
EXTENSIONS=(${if (builtins.compareVersions "3.1.10" version >= 0) then "plv8 plcoffee plls" else "plv8"})
167+
EXTENSIONS=(${
168+
if (builtins.compareVersions "3.1.10" version >= 0) then "plv8 plcoffee plls" else "plv8"
169+
})
166170
for ext in "''${EXTENSIONS[@]}" ; do
167171
cp $ext--${version}.sql $out/share/postgresql/extension
168172
install -Dm644 $ext.control $out/share/postgresql/extension/$ext--${version}.control

nix/ext/tests/plv8.nix

Lines changed: 27 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# we don't use the default nixos test because we don't support plv8 with pg 17
12
{ self, pkgs }:
23
let
34
pname = "plv8";
@@ -35,12 +36,13 @@ let
3536
};
3637
in
3738
pkg;
39+
psql_15 = postgresqlWithExtension self.packages.${pkgs.system}.postgresql_15;
3840
in
3941
self.inputs.nixpkgs.lib.nixos.runTest {
4042
name = pname;
4143
hostPkgs = pkgs;
4244
nodes.server =
43-
{ config, ... }:
45+
{ ... }:
4446
{
4547
virtualisation = {
4648
forwardPorts = [
@@ -59,98 +61,46 @@ self.inputs.nixpkgs.lib.nixos.runTest {
5961
enable = true;
6062
package = postgresqlWithExtension self.packages.${pkgs.system}.postgresql_15;
6163
};
62-
63-
specialisation.postgresql17.configuration = {
64-
services.postgresql = {
65-
package = lib.mkForce (postgresqlWithExtension self.packages.${pkgs.system}.postgresql_17);
66-
};
67-
68-
systemd.services.postgresql-migrate = {
69-
serviceConfig = {
70-
Type = "oneshot";
71-
RemainAfterExit = true;
72-
User = "postgres";
73-
Group = "postgres";
74-
StateDirectory = "postgresql";
75-
WorkingDirectory = "${builtins.dirOf config.services.postgresql.dataDir}";
76-
};
77-
script =
78-
let
79-
oldPostgresql = postgresqlWithExtension self.packages.${pkgs.system}.postgresql_15;
80-
newPostgresql = postgresqlWithExtension self.packages.${pkgs.system}.postgresql_17;
81-
oldDataDir = "${builtins.dirOf config.services.postgresql.dataDir}/${oldPostgresql.psqlSchema}";
82-
newDataDir = "${builtins.dirOf config.services.postgresql.dataDir}/${newPostgresql.psqlSchema}";
83-
in
84-
''
85-
if [[ ! -d ${newDataDir} ]]; then
86-
install -d -m 0700 -o postgres -g postgres "${newDataDir}"
87-
${newPostgresql}/bin/initdb -D "${newDataDir}"
88-
${newPostgresql}/bin/pg_upgrade --old-datadir "${oldDataDir}" --new-datadir "${newDataDir}" \
89-
--old-bindir "${oldPostgresql}/bin" --new-bindir "${newPostgresql}/bin"
90-
else
91-
echo "${newDataDir} already exists"
92-
fi
93-
'';
94-
};
95-
96-
systemd.services.postgresql = {
97-
after = [ "postgresql-migrate.service" ];
98-
requires = [ "postgresql-migrate.service" ];
99-
};
100-
};
101-
10264
};
10365
testScript =
104-
{ nodes, ... }:
105-
let
106-
pg17-configuration = "${nodes.server.system.build.toplevel}/specialisation/postgresql17";
107-
in
66+
{ ... }:
10867
''
68+
from pathlib import Path
10969
versions = {
11070
"15": [${lib.concatStringsSep ", " (map (s: ''"${s}"'') (versions "15"))}],
111-
"17": [${lib.concatStringsSep ", " (map (s: ''"${s}"'') (versions "17"))}],
11271
}
72+
extension_name = "${pname}"
73+
support_upgrade = False
74+
ext_has_background_worker = ${
75+
if (installedExtension "15") ? hasBackgroundWorker then "True" else "False"
76+
}
77+
sql_test_directory = Path("${../../tests}")
78+
pg_regress_test_name = "${(installedExtension "15").pgRegressTestName or pname}"
11379
114-
def run_sql(query):
115-
return server.succeed(f"""sudo -u postgres psql -t -A -F\",\" -c \"{query}\" """).strip()
116-
117-
def check_upgrade_path(pg_version):
118-
with subtest("Check ${pname} upgrade path"):
119-
firstVersion = versions[pg_version][0]
120-
server.succeed("sudo -u postgres psql -c 'DROP EXTENSION IF EXISTS ${pname};'")
121-
run_sql(f"""CREATE EXTENSION ${pname} WITH VERSION '{firstVersion}' CASCADE;""")
122-
installed_version = run_sql(r"""SELECT extversion FROM pg_extension WHERE extname = '${pname}';""")
123-
assert installed_version == firstVersion, f"Expected ${pname} version {firstVersion}, but found {installed_version}"
124-
for version in versions[pg_version][1:]:
125-
server.succeed("sudo -u postgres psql -c 'DROP EXTENSION IF EXISTS ${pname};'")
126-
run_sql(f"""CREATE EXTENSION ${pname} WITH VERSION '{version}' CASCADE;""")
127-
installed_version = run_sql(r"""SELECT extversion FROM pg_extension WHERE extname = '${pname}';""")
128-
assert installed_version == version, f"Expected ${pname} version {version}, but found {installed_version}"
80+
${builtins.readFile ./lib.py}
12981
13082
start_all()
13183
13284
server.wait_for_unit("multi-user.target")
13385
server.wait_for_unit("postgresql.service")
13486
135-
check_upgrade_path("15")
87+
test = PostgresExtensionTest(server, extension_name, versions, sql_test_directory, support_upgrade)
88+
89+
with subtest("Check upgrade path with postgresql 15"):
90+
test.check_upgrade_path("15")
13691
137-
with subtest("Check ${pname} latest extension version"):
138-
server.succeed("sudo -u postgres psql -c 'DROP EXTENSION ${pname};'")
139-
server.succeed("sudo -u postgres psql -c 'CREATE EXTENSION ${pname} CASCADE;'")
140-
installed_extensions=run_sql(r"""SELECT extname, extversion FROM pg_extension;""")
141-
latestVersion = versions["15"][-1]
142-
assert f"${pname},{latestVersion}" in installed_extensions
92+
with subtest("Check pg_regress with postgresql 15 after extension upgrade"):
93+
test.check_pg_regress(Path("${psql_15}/lib/pgxs/src/test/regress/pg_regress"), "15", pg_regress_test_name)
14394
144-
with subtest("switch to postgresql 17"):
145-
server.succeed(
146-
"${pg17-configuration}/bin/switch-to-configuration test >&2"
147-
)
95+
last_version = None
96+
with subtest("Check the install of the last version of the extension"):
97+
last_version = test.check_install_last_version("15")
14898
149-
with subtest("Check ${pname} latest extension version after upgrade"):
150-
installed_extensions=run_sql(r"""SELECT extname, extversion FROM pg_extension;""")
151-
latestVersion = versions["17"][-1]
152-
assert f"${pname},{latestVersion}" in installed_extensions
99+
if ext_has_background_worker:
100+
with subtest("Test switch_${pname}_version"):
101+
test.check_switch_extension_with_background_worker(Path("${psql_15}/lib/${pname}.so"), "15")
153102
154-
check_upgrade_path("17")
103+
with subtest("Check pg_regress with postgresql 15 after installing the last version"):
104+
test.check_pg_regress(Path("${psql_15}/lib/pgxs/src/test/regress/pg_regress"), "15", pg_regress_test_name)
155105
'';
156106
}

0 commit comments

Comments
 (0)