From a4a591f51d9e0aa7f6b8c27e74700425aa67191f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jean-Fran=C3=A7ois=20Roche?= Date: Mon, 3 Nov 2025 22:17:30 +0100 Subject: [PATCH 1/2] feat: test extensions with OrioleDB Make sure that pg_regress and upgrade paths work correctly when using OrioleDB --- nix/ext/tests/default.nix | 82 ++++++++++- nix/ext/tests/http.nix | 165 +++++++++++++++++---- nix/ext/tests/index_advisor.nix | 248 ++++++++++++++++++++++++++++++++ 3 files changed, 460 insertions(+), 35 deletions(-) create mode 100644 nix/ext/tests/index_advisor.nix diff --git a/nix/ext/tests/default.nix b/nix/ext/tests/default.nix index cf4518f60..41b105274 100644 --- a/nix/ext/tests/default.nix +++ b/nix/ext/tests/default.nix @@ -19,14 +19,17 @@ let postgresqlWithExtension = postgresql: let - majorVersion = lib.versions.major postgresql.version; + majorVersion = + if postgresql.isOrioleDB then "orioledb-17" else lib.versions.major postgresql.version; pkg = pkgs.buildEnv { name = "postgresql-${majorVersion}-${pname}"; paths = [ postgresql postgresql.lib (installedExtension majorVersion) - ]; + ] + ++ lib.optional (postgresql.isOrioleDB + ) self.legacyPackages.${pkgs.system}.psql_orioledb-17.exts.orioledb; passthru = { inherit (postgresql) version psqlSchema; lib = pkg; @@ -50,7 +53,10 @@ let in pkg; psql_15 = postgresqlWithExtension self.packages.${pkgs.stdenv.hostPlatform.system}.postgresql_15; - psql_17 = postgresqlWithExtension self.packages.${pkgs.stdenv.hostPlatform.system}.postgresql_17; + psql_17 = postgresqlWithExtension self.packages.${pkgs.system}.postgresql_17; + orioledb_17 = + postgresqlWithExtension + self.packages.${pkgs.stdenv.hostPlatform.system}.postgresql_orioledb-17; in self.inputs.nixpkgs.lib.nixos.runTest { name = pname; @@ -139,17 +145,71 @@ let requires = [ "postgresql-migrate.service" ]; }; }; + + specialisation.orioledb17.configuration = { + services.postgresql = { + package = lib.mkForce (postgresqlWithExtension self.packages.${pkgs.system}.postgresql_orioledb-17); + settings = lib.mkForce ( + ((installedExtension "17").defaultSettings or { }) + // { + jit = "off"; + shared_preload_libraries = [ + "orioledb" + ] + ++ (lib.toList ((installedExtension "17").defaultSettings.shared_preload_libraries or [ ])); + default_table_access_method = "orioledb"; + } + ); + initdbArgs = [ + "--allow-group-access" + "--locale-provider=icu" + "--encoding=UTF-8" + "--icu-locale=en_US.UTF-8" + ]; + initialScript = pkgs.writeText "init-postgres-with-orioledb" '' + CREATE EXTENSION orioledb CASCADE; + ''; + }; + + systemd.services.postgresql-migrate = { + # we don't support migrating from postgresql 17 to orioledb-17 so we just reinit the datadir + serviceConfig = { + Type = "oneshot"; + RemainAfterExit = true; + User = "postgres"; + Group = "postgres"; + StateDirectory = "postgresql"; + WorkingDirectory = "${builtins.dirOf config.services.postgresql.dataDir}"; + }; + script = + let + newPostgresql = postgresqlWithExtension self.packages.${pkgs.system}.postgresql_orioledb-17; + in + '' + set -x + systemctl cat postgresql.service + rm -rf ${builtins.dirOf config.services.postgresql.dataDir}/${newPostgresql.psqlSchema} + ''; + }; + + systemd.services.postgresql = { + after = [ "postgresql-migrate.service" ]; + requires = [ "postgresql-migrate.service" ]; + }; + }; }; testScript = { nodes, ... }: let pg17-configuration = "${nodes.server.system.build.toplevel}/specialisation/postgresql17"; + orioledb17-configuration = "${nodes.server.system.build.toplevel}/specialisation/orioledb17"; in '' from pathlib import Path versions = { "15": [${lib.concatStringsSep ", " (map (s: ''"${s}"'') (versions "15"))}], "17": [${lib.concatStringsSep ", " (map (s: ''"${s}"'') (versions "17"))}], + "orioledb-17": [${lib.concatStringsSep ", " (map (s: ''"${s}"'') (versions "orioledb-17"))}], } extension_name = "${pname}" support_upgrade = True @@ -192,7 +252,7 @@ let with subtest("switch to postgresql 17"): server.succeed( - f"{pg17_configuration}/bin/switch-to-configuration test >&2" + "${pg17-configuration}/bin/switch-to-configuration test >&2" ) with subtest("Check last version of the extension after postgresql upgrade"): @@ -209,6 +269,19 @@ let with subtest("Check pg_regress with postgresql 17 after installing the last version"): test.check_pg_regress(Path("${psql_17}/lib/pgxs/src/test/regress/pg_regress"), "17", pg_regress_test_name) + + with subtest("switch to orioledb 17"): + server.succeed( + "${orioledb17-configuration}/bin/switch-to-configuration test >&2" + ) + installed_extensions=test.run_sql("""SELECT extname FROM pg_extension WHERE extname = 'orioledb';""") + assert "orioledb" in installed_extensions + + with subtest("Check upgrade path with orioledb 17"): + test.check_upgrade_path("orioledb-17") + + with subtest("Check pg_regress with orioledb 17 after installing the last version"): + test.check_pg_regress(Path("${orioledb_17}/lib/pgxs/src/test/regress/pg_regress"), "orioledb-17", pg_regress_test_name) ''; }; in @@ -226,7 +299,6 @@ builtins.listToAttrs ( }) [ "hypopg" - "index_advisor" "pg_cron" "pg_graphql" "pg_hashids" diff --git a/nix/ext/tests/http.nix b/nix/ext/tests/http.nix index fab6a0d20..6c74ed2ea 100644 --- a/nix/ext/tests/http.nix +++ b/nix/ext/tests/http.nix @@ -11,14 +11,17 @@ let postgresqlWithExtension = postgresql: let - majorVersion = lib.versions.major postgresql.version; + majorVersion = + if postgresql.isOrioleDB then "orioledb-17" else lib.versions.major postgresql.version; pkg = pkgs.buildEnv { name = "postgresql-${majorVersion}-${pname}"; paths = [ postgresql postgresql.lib (installedExtension majorVersion) - ]; + ] + ++ lib.optional (postgresql.isOrioleDB + ) self.legacyPackages.${pkgs.system}.psql_orioledb-17.exts.orioledb; passthru = { inherit (postgresql) version psqlSchema; installedExtensions = [ (installedExtension majorVersion) ]; @@ -41,6 +44,9 @@ let }; in pkg; + psql_15 = postgresqlWithExtension self.packages.${pkgs.system}.postgresql_15; + psql_17 = postgresqlWithExtension self.packages.${pkgs.system}.postgresql_17; + orioledb_17 = postgresqlWithExtension self.packages.${pkgs.system}.postgresql_orioledb-17; in self.inputs.nixpkgs.lib.nixos.runTest { name = pname; @@ -64,6 +70,20 @@ self.inputs.nixpkgs.lib.nixos.runTest { services.postgresql = { enable = true; package = postgresqlWithExtension self.packages.${pkgs.stdenv.hostPlatform.system}.postgresql_15; + initialScript = pkgs.writeText "init-postgres" '' + CREATE TABLE IF NOT EXISTS test_config (key TEXT PRIMARY KEY, value TEXT); + INSERT INTO test_config (key, value) VALUES ('http_mock_port', '8880') ON CONFLICT (key) DO UPDATE SET value = EXCLUDED.value; + ''; + }; + + systemd.services.http-mock-server = { + wantedBy = [ "multi-user.target" ]; + serviceConfig = { + Type = "simple"; + }; + script = '' + ${pkgs.python3}/bin/python3 ${../../tests/http-mock-server.py} + ''; }; specialisation.postgresql17.configuration = { @@ -110,59 +130,144 @@ self.inputs.nixpkgs.lib.nixos.runTest { requires = [ "postgresql-migrate.service" ]; }; }; + + specialisation.orioledb17.configuration = { + services.postgresql = { + package = lib.mkForce (postgresqlWithExtension self.packages.${pkgs.system}.postgresql_orioledb-17); + settings = lib.mkForce ( + ((installedExtension "17").defaultSettings or { }) + // { + jit = "off"; + shared_preload_libraries = [ + "orioledb" + ] + ++ (lib.toList ((installedExtension "17").defaultSettings.shared_preload_libraries or [ ])); + default_table_access_method = "orioledb"; + } + ); + initdbArgs = [ + "--allow-group-access" + "--locale-provider=icu" + "--encoding=UTF-8" + "--icu-locale=en_US.UTF-8" + ]; + initialScript = lib.mkForce ( + pkgs.writeText "init-postgres-with-orioledb" '' + CREATE EXTENSION orioledb CASCADE; + CREATE TABLE IF NOT EXISTS test_config (key TEXT PRIMARY KEY, value TEXT); + INSERT INTO test_config (key, value) VALUES ('http_mock_port', '8880') ON CONFLICT (key) DO UPDATE SET value = EXCLUDED.value; + '' + ); + }; + + systemd.services.postgresql-migrate = { + # we don't support migrating from postgresql 17 to orioledb-17 so we just reinit the datadir + serviceConfig = { + Type = "oneshot"; + RemainAfterExit = true; + User = "postgres"; + Group = "postgres"; + StateDirectory = "postgresql"; + WorkingDirectory = "${builtins.dirOf config.services.postgresql.dataDir}"; + }; + script = + let + newPostgresql = postgresqlWithExtension self.packages.${pkgs.system}.postgresql_orioledb-17; + in + '' + set -x + systemctl cat postgresql.service + rm -rf ${builtins.dirOf config.services.postgresql.dataDir}/${newPostgresql.psqlSchema} + ''; + }; + + systemd.services.postgresql = { + after = [ "postgresql-migrate.service" ]; + requires = [ "postgresql-migrate.service" ]; + }; + }; }; testScript = { nodes, ... }: let pg17-configuration = "${nodes.server.system.build.toplevel}/specialisation/postgresql17"; + orioledb17-configuration = "${nodes.server.system.build.toplevel}/specialisation/orioledb17"; # Convert versions to major.minor format (e.g., "1.5.0" -> "1.5") toMajorMinor = map (v: lib.versions.majorMinor v); in '' + from pathlib import Path versions = { - "15": [${lib.concatStringsSep ", " (map (s: ''"${s}"'') (toMajorMinor (versions "15")))}], - "17": [${lib.concatStringsSep ", " (map (s: ''"${s}"'') (toMajorMinor (versions "17")))}], + "15": [${lib.concatStringsSep ", " (map (s: ''"${s}"'') (toMajorMinor (versions "15")))}], + "17": [${lib.concatStringsSep ", " (map (s: ''"${s}"'') (toMajorMinor (versions "17")))}], + "orioledb-17": [${ + lib.concatStringsSep ", " (map (s: ''"${s}"'') (toMajorMinor (versions "orioledb-17"))) + }], + } + extension_name = "${pname}" + ext_has_background_worker = ${ + if (installedExtension "15") ? hasBackgroundWorker then "True" else "False" } + sql_test_directory = Path("${../../tests}") + pg_regress_test_name = "${(installedExtension "15").pgRegressTestName or pname}" - def run_sql(query): - return server.succeed(f"""sudo -u postgres psql -t -A -F\",\" -c \"{query}\" """).strip() - - def check_upgrade_path(pg_version): - with subtest("Check ${pname} upgrade path"): - firstVersion = versions[pg_version][0] - server.succeed("sudo -u postgres psql -c 'DROP EXTENSION IF EXISTS ${pname};'") - run_sql(f"""CREATE EXTENSION ${pname} WITH VERSION '{firstVersion}' CASCADE;""") - installed_version = run_sql(r"""SELECT extversion FROM pg_extension WHERE extname = '${pname}';""") - assert installed_version == firstVersion, f"Expected ${pname} version {firstVersion}, but found {installed_version}" - for version in versions[pg_version][1:]: - run_sql(f"""ALTER EXTENSION ${pname} UPDATE TO '{version}';""") - installed_version = run_sql(r"""SELECT extversion FROM pg_extension WHERE extname = '${pname}';""") - assert installed_version == version, f"Expected ${pname} version {version}, but found {installed_version}" + ${builtins.readFile ./lib.py} start_all() server.wait_for_unit("multi-user.target") server.wait_for_unit("postgresql.service") - check_upgrade_path("15") + test = PostgresExtensionTest(server, extension_name, versions, sql_test_directory) + + with subtest("Check upgrade path with postgresql 15"): + test.check_upgrade_path("15") - with subtest("Check ${pname} latest extension version"): - server.succeed("sudo -u postgres psql -c 'DROP EXTENSION ${pname};'") - server.succeed("sudo -u postgres psql -c 'CREATE EXTENSION ${pname} CASCADE;'") - installed_extensions=run_sql(r"""SELECT extname, extversion FROM pg_extension;""") - latestVersion = versions["15"][-1] - assert f"${pname},{latestVersion}" in installed_extensions + with subtest("Check pg_regress with postgresql 15 after extension upgrade"): + test.check_pg_regress(Path("${psql_15}/lib/pgxs/src/test/regress/pg_regress"), "15", pg_regress_test_name) + + last_version = None + with subtest("Check the install of the last version of the extension"): + last_version = test.check_install_last_version("15") + + if ext_has_background_worker: + with subtest("Test switch_${pname}_version"): + test.check_switch_extension_with_background_worker(Path("${psql_15}/lib/${pname}.so"), "15") + + with subtest("Check pg_regress with postgresql 15 after installing the last version"): + test.check_pg_regress(Path("${psql_15}/lib/pgxs/src/test/regress/pg_regress"), "15", pg_regress_test_name) with subtest("switch to postgresql 17"): server.succeed( "${pg17-configuration}/bin/switch-to-configuration test >&2" ) - with subtest("Check ${pname} latest extension version after upgrade"): - installed_extensions=run_sql(r"""SELECT extname, extversion FROM pg_extension;""") - latestVersion = versions["17"][-1] - assert f"${pname},{latestVersion}" in installed_extensions + with subtest("Check last version of the extension after postgresql upgrade"): + test.assert_version_matches(last_version) + + with subtest("Check upgrade path with postgresql 17"): + test.check_upgrade_path("17") + + with subtest("Check pg_regress with postgresql 17 after extension upgrade"): + test.check_pg_regress(Path("${psql_17}/lib/pgxs/src/test/regress/pg_regress"), "17", pg_regress_test_name) + + with subtest("Check the install of the last version of the extension"): + test.check_install_last_version("17") + + with subtest("Check pg_regress with postgresql 17 after installing the last version"): + test.check_pg_regress(Path("${psql_17}/lib/pgxs/src/test/regress/pg_regress"), "17", pg_regress_test_name) + + with subtest("switch to orioledb 17"): + server.succeed( + "${orioledb17-configuration}/bin/switch-to-configuration test >&2" + ) + installed_extensions=test.run_sql("""SELECT extname FROM pg_extension WHERE extname = 'orioledb';""") + assert "orioledb" in installed_extensions + + with subtest("Check upgrade path with orioledb 17"): + test.check_upgrade_path("orioledb-17") - check_upgrade_path("17") + with subtest("Check pg_regress with orioledb 17 after installing the last version"): + test.check_pg_regress(Path("${orioledb_17}/lib/pgxs/src/test/regress/pg_regress"), "orioledb-17", pg_regress_test_name) ''; } diff --git a/nix/ext/tests/index_advisor.nix b/nix/ext/tests/index_advisor.nix new file mode 100644 index 000000000..59e1bf4f9 --- /dev/null +++ b/nix/ext/tests/index_advisor.nix @@ -0,0 +1,248 @@ +{ self, pkgs }: +let + pname = "index_advisor"; + inherit (pkgs) lib; + installedExtension = + postgresMajorVersion: + self.legacyPackages.${pkgs.system}."psql_${postgresMajorVersion}".exts.index_advisor; + versions = postgresqlMajorVersion: (installedExtension postgresqlMajorVersion).versions; + postgresqlWithExtension = + postgresql: + let + majorVersion = + if postgresql.isOrioleDB then "orioledb-17" else lib.versions.major postgresql.version; + pkg = pkgs.buildEnv { + name = "postgresql-${majorVersion}-${pname}"; + paths = [ + postgresql + postgresql.lib + (installedExtension majorVersion) + ] + ++ lib.optional (postgresql.isOrioleDB + ) self.legacyPackages.${pkgs.system}.psql_orioledb-17.exts.orioledb; + passthru = { + inherit (postgresql) version psqlSchema; + installedExtensions = [ (installedExtension majorVersion) ]; + lib = pkg; + withPackages = _: pkg; + withJIT = pkg; + withoutJIT = pkg; + }; + nativeBuildInputs = [ pkgs.makeWrapper ]; + pathsToLink = [ + "/" + "/bin" + "/lib" + ]; + postBuild = '' + wrapProgram $out/bin/postgres --set NIX_PGLIBDIR $out/lib + wrapProgram $out/bin/pg_ctl --set NIX_PGLIBDIR $out/lib + wrapProgram $out/bin/pg_upgrade --set NIX_PGLIBDIR $out/lib + ''; + }; + in + pkg; + psql_15 = postgresqlWithExtension self.packages.${pkgs.system}.postgresql_15; + psql_17 = postgresqlWithExtension self.packages.${pkgs.system}.postgresql_17; + orioledb_17 = postgresqlWithExtension self.packages.${pkgs.system}.postgresql_orioledb-17; +in +self.inputs.nixpkgs.lib.nixos.runTest { + name = pname; + hostPkgs = pkgs; + nodes.server = + { config, ... }: + { + virtualisation = { + forwardPorts = [ + { + from = "host"; + host.port = 13022; + guest.port = 22; + } + ]; + }; + services.openssh = { + enable = true; + }; + + services.postgresql = { + enable = true; + package = psql_15; + enableTCPIP = true; + settings = (installedExtension "15").defaultSettings or { }; + }; + + networking.firewall.allowedTCPPorts = [ config.services.postgresql.settings.port ]; + + specialisation.postgresql17.configuration = { + services.postgresql = { + package = lib.mkForce psql_17; + }; + + systemd.services.postgresql-migrate = { + serviceConfig = { + Type = "oneshot"; + RemainAfterExit = true; + User = "postgres"; + Group = "postgres"; + StateDirectory = "postgresql"; + WorkingDirectory = "${builtins.dirOf config.services.postgresql.dataDir}"; + }; + script = + let + oldPostgresql = psql_15; + newPostgresql = psql_17; + oldDataDir = "${builtins.dirOf config.services.postgresql.dataDir}/${oldPostgresql.psqlSchema}"; + newDataDir = "${builtins.dirOf config.services.postgresql.dataDir}/${newPostgresql.psqlSchema}"; + in + '' + if [[ ! -d ${newDataDir} ]]; then + install -d -m 0700 -o postgres -g postgres "${newDataDir}" + ${newPostgresql}/bin/initdb -D "${newDataDir}" + ${newPostgresql}/bin/pg_upgrade --old-datadir "${oldDataDir}" --new-datadir "${newDataDir}" \ + --old-bindir "${oldPostgresql}/bin" --new-bindir "${newPostgresql}/bin" + else + echo "${newDataDir} already exists" + fi + ''; + }; + + systemd.services.postgresql = { + after = [ "postgresql-migrate.service" ]; + requires = [ "postgresql-migrate.service" ]; + }; + }; + + specialisation.orioledb17.configuration = { + services.postgresql = { + package = lib.mkForce (postgresqlWithExtension self.packages.${pkgs.system}.postgresql_orioledb-17); + settings = lib.mkForce ( + ((installedExtension "17").defaultSettings or { }) + // { + jit = "off"; + shared_preload_libraries = [ + "orioledb" + ] + ++ (lib.toList ((installedExtension "17").defaultSettings.shared_preload_libraries or [ ])); + default_table_access_method = "orioledb"; + } + ); + initdbArgs = [ + "--allow-group-access" + "--locale-provider=icu" + "--encoding=UTF-8" + "--icu-locale=en_US.UTF-8" + ]; + initialScript = pkgs.writeText "init-postgres-with-orioledb" '' + CREATE EXTENSION orioledb CASCADE; + ''; + }; + + systemd.services.postgresql-migrate = { + # we don't support migrating from postgresql 17 to orioledb-17 so we just reinit the datadir + serviceConfig = { + Type = "oneshot"; + RemainAfterExit = true; + User = "postgres"; + Group = "postgres"; + StateDirectory = "postgresql"; + WorkingDirectory = "${builtins.dirOf config.services.postgresql.dataDir}"; + }; + script = + let + newPostgresql = postgresqlWithExtension self.packages.${pkgs.system}.postgresql_orioledb-17; + in + '' + set -x + systemctl cat postgresql.service + rm -rf ${builtins.dirOf config.services.postgresql.dataDir}/${newPostgresql.psqlSchema} + ''; + }; + + systemd.services.postgresql = { + after = [ "postgresql-migrate.service" ]; + requires = [ "postgresql-migrate.service" ]; + }; + }; + }; + testScript = + { nodes, ... }: + let + pg17-configuration = "${nodes.server.system.build.toplevel}/specialisation/postgresql17"; + orioledb17-configuration = "${nodes.server.system.build.toplevel}/specialisation/orioledb17"; + in + '' + from pathlib import Path + versions = { + "15": [${lib.concatStringsSep ", " (map (s: ''"${s}"'') (versions "15"))}], + "17": [${lib.concatStringsSep ", " (map (s: ''"${s}"'') (versions "17"))}], + "orioledb-17": [${lib.concatStringsSep ", " (map (s: ''"${s}"'') (versions "orioledb-17"))}], + } + extension_name = "${pname}" + ext_has_background_worker = ${ + if (installedExtension "15") ? hasBackgroundWorker then "True" else "False" + } + sql_test_directory = Path("${../../tests}") + pg_regress_test_name = "${(installedExtension "15").pgRegressTestName or pname}" + + ${builtins.readFile ./lib.py} + + start_all() + + server.wait_for_unit("multi-user.target") + server.wait_for_unit("postgresql.service") + + test = PostgresExtensionTest(server, extension_name, versions, sql_test_directory) + + with subtest("Check upgrade path with postgresql 15"): + test.check_upgrade_path("15") + + with subtest("Check pg_regress with postgresql 15 after extension upgrade"): + test.check_pg_regress(Path("${psql_15}/lib/pgxs/src/test/regress/pg_regress"), "15", pg_regress_test_name) + + last_version = None + with subtest("Check the install of the last version of the extension"): + last_version = test.check_install_last_version("15") + + if ext_has_background_worker: + with subtest("Test switch_${pname}_version"): + test.check_switch_extension_with_background_worker(Path("${psql_15}/lib/${pname}.so"), "15") + + with subtest("Check pg_regress with postgresql 15 after installing the last version"): + test.check_pg_regress(Path("${psql_15}/lib/pgxs/src/test/regress/pg_regress"), "15", pg_regress_test_name) + + with subtest("switch to postgresql 17"): + server.succeed( + "${pg17-configuration}/bin/switch-to-configuration test >&2" + ) + + with subtest("Check last version of the extension after postgresql upgrade"): + test.assert_version_matches(last_version) + + with subtest("Check upgrade path with postgresql 17"): + test.check_upgrade_path("17") + + with subtest("Check pg_regress with postgresql 17 after extension upgrade"): + test.check_pg_regress(Path("${psql_17}/lib/pgxs/src/test/regress/pg_regress"), "17", pg_regress_test_name) + + with subtest("Check the install of the last version of the extension"): + test.check_install_last_version("17") + + with subtest("Check pg_regress with postgresql 17 after installing the last version"): + test.check_pg_regress(Path("${psql_17}/lib/pgxs/src/test/regress/pg_regress"), "17", pg_regress_test_name) + + with subtest("switch to orioledb 17"): + server.succeed( + "${orioledb17-configuration}/bin/switch-to-configuration test >&2" + ) + installed_extensions=test.run_sql("""SELECT extname FROM pg_extension WHERE extname = 'orioledb';""") + assert "orioledb" in installed_extensions + + with subtest("Check upgrade path with orioledb 17"): + test.check_upgrade_path("orioledb-17") + + #FIXME: pg_regress tests are failing with orioledb: + # with subtest("Check pg_regress with orioledb 17 after installing the last version"): + # test.check_pg_regress(Path("${orioledb_17}/lib/pgxs/src/test/regress/pg_regress"), "orioledb-17", pg_regress_test_name) + ''; +} From 7574614d8264b3934fd23208edf088a6f08b0db9 Mon Sep 17 00:00:00 2001 From: Yvan Sraka Date: Tue, 20 Jan 2026 13:50:10 +0100 Subject: [PATCH 2/2] fix: add PostgreSQL authentication config to extension tests The index_advisor and http extension tests were missing PostgreSQL authentication configuration causing test failures with 'Peer authentication failed'. OrioleDB tests also failed because schemas were not recreated after database reinitialization. This addresses all PR review comments including proper background worker library path resolution, standardized test patterns, safety checks for data directory deletion, enhanced documentation for test limitations, and version-specific OrioleDB configuration. The changes ensure extension tests work consistently across PostgreSQL 15, 17, and OrioleDB variants with proper authentication, schema management, and cross-compilation support. --- nix/ext/tests/default.nix | 17 +++++++++---- nix/ext/tests/http.nix | 42 ++++++++++++++++++++++++++------- nix/ext/tests/index_advisor.nix | 40 ++++++++++++++++++++++++++----- 3 files changed, 80 insertions(+), 19 deletions(-) diff --git a/nix/ext/tests/default.nix b/nix/ext/tests/default.nix index 41b105274..3126eb581 100644 --- a/nix/ext/tests/default.nix +++ b/nix/ext/tests/default.nix @@ -53,7 +53,7 @@ let in pkg; psql_15 = postgresqlWithExtension self.packages.${pkgs.stdenv.hostPlatform.system}.postgresql_15; - psql_17 = postgresqlWithExtension self.packages.${pkgs.system}.postgresql_17; + psql_17 = postgresqlWithExtension self.packages.${pkgs.stdenv.hostPlatform.system}.postgresql_17; orioledb_17 = postgresqlWithExtension self.packages.${pkgs.stdenv.hostPlatform.system}.postgresql_orioledb-17; @@ -148,7 +148,9 @@ let specialisation.orioledb17.configuration = { services.postgresql = { - package = lib.mkForce (postgresqlWithExtension self.packages.${pkgs.system}.postgresql_orioledb-17); + package = lib.mkForce ( + postgresqlWithExtension self.packages.${pkgs.stdenv.hostPlatform.system}.postgresql_orioledb-17 + ); settings = lib.mkForce ( ((installedExtension "17").defaultSettings or { }) // { @@ -183,11 +185,15 @@ let }; script = let - newPostgresql = postgresqlWithExtension self.packages.${pkgs.system}.postgresql_orioledb-17; + newPostgresql = + postgresqlWithExtension + self.packages.${pkgs.stdenv.hostPlatform.system}.postgresql_orioledb-17; in '' - set -x - systemctl cat postgresql.service + if [[ -z "${newPostgresql.psqlSchema}" ]]; then + echo "Error: psqlSchema is empty, refusing to rm -rf" + exit 1 + fi rm -rf ${builtins.dirOf config.services.postgresql.dataDir}/${newPostgresql.psqlSchema} ''; }; @@ -276,6 +282,7 @@ let ) installed_extensions=test.run_sql("""SELECT extname FROM pg_extension WHERE extname = 'orioledb';""") assert "orioledb" in installed_extensions + test.create_schema() with subtest("Check upgrade path with orioledb 17"): test.check_upgrade_path("orioledb-17") diff --git a/nix/ext/tests/http.nix b/nix/ext/tests/http.nix index 6c74ed2ea..badf768e7 100644 --- a/nix/ext/tests/http.nix +++ b/nix/ext/tests/http.nix @@ -44,9 +44,11 @@ let }; in pkg; - psql_15 = postgresqlWithExtension self.packages.${pkgs.system}.postgresql_15; - psql_17 = postgresqlWithExtension self.packages.${pkgs.system}.postgresql_17; - orioledb_17 = postgresqlWithExtension self.packages.${pkgs.system}.postgresql_orioledb-17; + psql_15 = postgresqlWithExtension self.packages.${pkgs.stdenv.hostPlatform.system}.postgresql_15; + psql_17 = postgresqlWithExtension self.packages.${pkgs.stdenv.hostPlatform.system}.postgresql_17; + orioledb_17 = + postgresqlWithExtension + self.packages.${pkgs.stdenv.hostPlatform.system}.postgresql_orioledb-17; in self.inputs.nixpkgs.lib.nixos.runTest { name = pname; @@ -70,6 +72,20 @@ self.inputs.nixpkgs.lib.nixos.runTest { services.postgresql = { enable = true; package = postgresqlWithExtension self.packages.${pkgs.stdenv.hostPlatform.system}.postgresql_15; + authentication = '' + local all postgres peer map=postgres + local all all peer map=root + ''; + identMap = '' + root root supabase_admin + postgres postgres postgres + ''; + ensureUsers = [ + { + name = "supabase_admin"; + ensureClauses.superuser = true; + } + ]; initialScript = pkgs.writeText "init-postgres" '' CREATE TABLE IF NOT EXISTS test_config (key TEXT PRIMARY KEY, value TEXT); INSERT INTO test_config (key, value) VALUES ('http_mock_port', '8880') ON CONFLICT (key) DO UPDATE SET value = EXCLUDED.value; @@ -91,6 +107,7 @@ self.inputs.nixpkgs.lib.nixos.runTest { package = lib.mkForce ( postgresqlWithExtension self.packages.${pkgs.stdenv.hostPlatform.system}.postgresql_17 ); + settings = ((installedExtension "17").defaultSettings or { }); }; systemd.services.postgresql-migrate = { @@ -172,11 +189,15 @@ self.inputs.nixpkgs.lib.nixos.runTest { }; script = let - newPostgresql = postgresqlWithExtension self.packages.${pkgs.system}.postgresql_orioledb-17; + newPostgresql = + postgresqlWithExtension + self.packages.${pkgs.stdenv.hostPlatform.system}.postgresql_orioledb-17; in '' - set -x - systemctl cat postgresql.service + if [[ -z "${newPostgresql.psqlSchema}" ]]; then + echo "Error: psqlSchema is empty, refusing to rm -rf" + exit 1 + fi rm -rf ${builtins.dirOf config.services.postgresql.dataDir}/${newPostgresql.psqlSchema} ''; }; @@ -205,11 +226,14 @@ self.inputs.nixpkgs.lib.nixos.runTest { }], } extension_name = "${pname}" + support_upgrade = True ext_has_background_worker = ${ if (installedExtension "15") ? hasBackgroundWorker then "True" else "False" } sql_test_directory = Path("${../../tests}") pg_regress_test_name = "${(installedExtension "15").pgRegressTestName or pname}" + ext_schema = "${(installedExtension "15").defaultSchema or "public"}" + lib_name = "${(installedExtension "15").libName or pname}" ${builtins.readFile ./lib.py} @@ -218,7 +242,8 @@ self.inputs.nixpkgs.lib.nixos.runTest { server.wait_for_unit("multi-user.target") server.wait_for_unit("postgresql.service") - test = PostgresExtensionTest(server, extension_name, versions, sql_test_directory) + test = PostgresExtensionTest(server, extension_name, versions, sql_test_directory, support_upgrade, ext_schema, lib_name) + test.create_schema() with subtest("Check upgrade path with postgresql 15"): test.check_upgrade_path("15") @@ -232,7 +257,7 @@ self.inputs.nixpkgs.lib.nixos.runTest { if ext_has_background_worker: with subtest("Test switch_${pname}_version"): - test.check_switch_extension_with_background_worker(Path("${psql_15}/lib/${pname}.so"), "15") + test.check_switch_extension_with_background_worker(Path(f"${psql_15}/lib/{lib_name}.so"), "15") with subtest("Check pg_regress with postgresql 15 after installing the last version"): test.check_pg_regress(Path("${psql_15}/lib/pgxs/src/test/regress/pg_regress"), "15", pg_regress_test_name) @@ -263,6 +288,7 @@ self.inputs.nixpkgs.lib.nixos.runTest { ) installed_extensions=test.run_sql("""SELECT extname FROM pg_extension WHERE extname = 'orioledb';""") assert "orioledb" in installed_extensions + test.create_schema() with subtest("Check upgrade path with orioledb 17"): test.check_upgrade_path("orioledb-17") diff --git a/nix/ext/tests/index_advisor.nix b/nix/ext/tests/index_advisor.nix index 59e1bf4f9..564ec350b 100644 --- a/nix/ext/tests/index_advisor.nix +++ b/nix/ext/tests/index_advisor.nix @@ -69,6 +69,20 @@ self.inputs.nixpkgs.lib.nixos.runTest { enable = true; package = psql_15; enableTCPIP = true; + authentication = '' + local all postgres peer map=postgres + local all all peer map=root + ''; + identMap = '' + root root supabase_admin + postgres postgres postgres + ''; + ensureUsers = [ + { + name = "supabase_admin"; + ensureClauses.superuser = true; + } + ]; settings = (installedExtension "15").defaultSettings or { }; }; @@ -77,6 +91,7 @@ self.inputs.nixpkgs.lib.nixos.runTest { specialisation.postgresql17.configuration = { services.postgresql = { package = lib.mkForce psql_17; + settings = (installedExtension "17").defaultSettings or { }; }; systemd.services.postgresql-migrate = { @@ -150,11 +165,15 @@ self.inputs.nixpkgs.lib.nixos.runTest { }; script = let - newPostgresql = postgresqlWithExtension self.packages.${pkgs.system}.postgresql_orioledb-17; + newPostgresql = + postgresqlWithExtension + self.packages.${pkgs.stdenv.hostPlatform.system}.postgresql_orioledb-17; in '' - set -x - systemctl cat postgresql.service + if [[ -z "${newPostgresql.psqlSchema}" ]]; then + echo "Error: psqlSchema is empty, refusing to rm -rf" + exit 1 + fi rm -rf ${builtins.dirOf config.services.postgresql.dataDir}/${newPostgresql.psqlSchema} ''; }; @@ -179,11 +198,14 @@ self.inputs.nixpkgs.lib.nixos.runTest { "orioledb-17": [${lib.concatStringsSep ", " (map (s: ''"${s}"'') (versions "orioledb-17"))}], } extension_name = "${pname}" + support_upgrade = True ext_has_background_worker = ${ if (installedExtension "15") ? hasBackgroundWorker then "True" else "False" } sql_test_directory = Path("${../../tests}") pg_regress_test_name = "${(installedExtension "15").pgRegressTestName or pname}" + ext_schema = "${(installedExtension "15").defaultSchema or "public"}" + lib_name = "${(installedExtension "15").libName or pname}" ${builtins.readFile ./lib.py} @@ -192,7 +214,8 @@ self.inputs.nixpkgs.lib.nixos.runTest { server.wait_for_unit("multi-user.target") server.wait_for_unit("postgresql.service") - test = PostgresExtensionTest(server, extension_name, versions, sql_test_directory) + test = PostgresExtensionTest(server, extension_name, versions, sql_test_directory, support_upgrade, ext_schema, lib_name) + test.create_schema() with subtest("Check upgrade path with postgresql 15"): test.check_upgrade_path("15") @@ -206,7 +229,7 @@ self.inputs.nixpkgs.lib.nixos.runTest { if ext_has_background_worker: with subtest("Test switch_${pname}_version"): - test.check_switch_extension_with_background_worker(Path("${psql_15}/lib/${pname}.so"), "15") + test.check_switch_extension_with_background_worker(Path(f"${psql_15}/lib/{lib_name}.so"), "15") with subtest("Check pg_regress with postgresql 15 after installing the last version"): test.check_pg_regress(Path("${psql_15}/lib/pgxs/src/test/regress/pg_regress"), "15", pg_regress_test_name) @@ -237,11 +260,16 @@ self.inputs.nixpkgs.lib.nixos.runTest { ) installed_extensions=test.run_sql("""SELECT extname FROM pg_extension WHERE extname = 'orioledb';""") assert "orioledb" in installed_extensions + test.create_schema() with subtest("Check upgrade path with orioledb 17"): test.check_upgrade_path("orioledb-17") - #FIXME: pg_regress tests are failing with orioledb: + # NOTE: pg_regress tests are currently disabled for OrioleDB due to compatibility issues + # The standard pg_regress test framework does not currently work with OrioleDB's + # specialized storage engine, causing test failures that need investigation. + # + # TODO: Re-enable once OrioleDB pg_regress compatibility is resolved # with subtest("Check pg_regress with orioledb 17 after installing the last version"): # test.check_pg_regress(Path("${orioledb_17}/lib/pgxs/src/test/regress/pg_regress"), "orioledb-17", pg_regress_test_name) '';