Skip to content

Commit a118034

Browse files
committed
fix(tests): correct library naming and symlinks for background worker extensions
Test assertions were inconsistent: expecting {version}.so and {extension_name}-{version}.so patterns while actual libraries use {lib_name}-{version}.so (e.g. pg_partman_bgw-5.3.1.so, timescaledb-loader-2.16.1.so). Updated PostgresExtensionTest to accept Optional[str] lib_name parameter and use consistent {lib_name}-{version}.so assertions throughout. Added missing timescaledb-loader.so symlink creation and updated the switch script to maintain both symlinks when switching versions. Fixes 'Expected timescaledb version 2.16.1, but found timescaledb-loader-2.16.1.so' and 'Expected pg_partman version 5.3.1, but found pg_partman_bgw-5.3.1.so' test failures.
1 parent e1e5a1e commit a118034

File tree

4 files changed

+15
-7
lines changed

4 files changed

+15
-7
lines changed

nix/ext/tests/default.nix

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ let
168168
server.wait_for_unit("multi-user.target")
169169
server.wait_for_unit("postgresql.service")
170170
171-
test = PostgresExtensionTest(server, extension_name, versions, sql_test_directory, support_upgrade, ext_schema)
171+
test = PostgresExtensionTest(server, extension_name, versions, sql_test_directory, support_upgrade, ext_schema, lib_name)
172172
test.create_schema()
173173
174174
with subtest("Check upgrade path with postgresql 15"):

nix/ext/tests/lib.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
installation, upgrades, and version verification of PostgreSQL extensions.
66
"""
77

8-
from typing import Sequence, Mapping
8+
from typing import Sequence, Mapping, Optional
99
from pathlib import Path
1010
from test_driver.machine import Machine
1111

@@ -21,6 +21,7 @@ def __init__(
2121
sql_test_dir: Path,
2222
support_upgrade: bool = True,
2323
schema: str = "public",
24+
lib_name: Optional[str] = None,
2425
):
2526
"""Initialize the PostgreSQL extension test framework.
2627
@@ -30,13 +31,15 @@ def __init__(
3031
versions: Mapping of PostgreSQL versions to available extension versions
3132
sql_test_dir: Directory containing SQL test files for pg_regress
3233
support_upgrade: Whether the extension supports in-place upgrades
34+
lib_name: Name of the shared library (defaults to extension_name)
3335
"""
3436
self.vm = vm
3537
self.extension_name = extension_name
3638
self.versions = versions
3739
self.support_upgrade = support_upgrade
3840
self.sql_test_dir = sql_test_dir
3941
self.schema = schema
42+
self.lib_name = lib_name or extension_name
4043

4144
def create_schema(self):
4245
self.run_sql(f"CREATE SCHEMA IF NOT EXISTS {self.schema};")
@@ -163,7 +166,7 @@ def check_switch_extension_with_background_worker(
163166
f"No versions available for PostgreSQL version {pg_version}"
164167
)
165168
last_version = available_versions[-1]
166-
assert ext_version.endswith(f"{last_version}.so"), (
169+
assert ext_version.endswith(f"{self.lib_name}-{last_version}.so"), (
167170
f"Expected {self.extension_name} version {last_version}, but found {ext_version}"
168171
)
169172

@@ -173,15 +176,15 @@ def check_switch_extension_with_background_worker(
173176

174177
# Check that we are using the first version now
175178
ext_version = self.vm.succeed(f"readlink -f {extension_lib_path}").strip()
176-
assert ext_version.endswith(f"{first_version}.so"), (
179+
assert ext_version.endswith(f"{self.lib_name}-{first_version}.so"), (
177180
f"Expected {self.extension_name} version {first_version}, but found {ext_version}"
178181
)
179182

180183
# Switch to the last version
181184
self.vm.succeed(f"switch_{self.extension_name}_version {last_version}")
182185
# Check that we are using the last version now
183186
ext_version = self.vm.succeed(f"readlink -f {extension_lib_path}").strip()
184-
assert ext_version.endswith(f"{self.extension_name}-{last_version}.so"), (
187+
assert ext_version.endswith(f"{self.lib_name}-{last_version}.so"), (
185188
f"Expected {self.extension_name} version {last_version}, but found {ext_version}"
186189
)
187190

nix/ext/tests/timescaledb.nix

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,12 +88,12 @@ self.inputs.nixpkgs.lib.nixos.runTest {
8888
support_upgrade = True
8989
sql_test_directory = Path("${../../tests}")
9090
91-
test = PostgresExtensionTest(server, extension_name, versions, sql_test_directory, support_upgrade)
91+
test = PostgresExtensionTest(server, extension_name, versions, sql_test_directory, support_upgrade, "public", "timescaledb-loader")
9292
9393
with subtest("Check upgrade path with postgresql 15"):
9494
test.check_upgrade_path("15")
9595
9696
with subtest("Test switch_${pname}_version"):
97-
test.check_switch_extension_with_background_worker(Path("${psql_15}/lib/${pname}.so"), "15")
97+
test.check_switch_extension_with_background_worker(Path("${psql_15}/lib/timescaledb-loader.so"), "15")
9898
'';
9999
}

nix/ext/timescaledb.nix

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ let
108108
EXT_LOADER_TO_USE="$EXT_WRAPPER_LIB/$EXT_NAME-loader-$VERSION${postgresql.dlSuffix}"
109109
if [ -f "$EXT_LOADER_TO_USE" ]; then
110110
ln -sfnv "$EXT_LOADER_TO_USE" "$EXT_WRAPPER_LIB/$EXT_NAME${postgresql.dlSuffix}"
111+
ln -sfnv "$EXT_LOADER_TO_USE" "$EXT_WRAPPER_LIB/$EXT_NAME-loader${postgresql.dlSuffix}"
111112
fi
112113
'';
113114
};
@@ -125,6 +126,9 @@ buildEnv {
125126
# Create symlink from the latest versioned loader to timescaledb.so
126127
ln -sfn ${pname}-loader-${latestVersion}${postgresql.dlSuffix} $out/lib/${pname}${postgresql.dlSuffix}
127128
129+
# Create symlink for timescaledb-loader.so (used by background worker tests)
130+
ln -sfn ${pname}-loader-${latestVersion}${postgresql.dlSuffix} $out/lib/${pname}-loader${postgresql.dlSuffix}
131+
128132
# The versioned extension libraries (timescaledb-VERSION.so) are already in place
129133
130134
# checks - we should have loader files and versioned extension files
@@ -143,6 +147,7 @@ buildEnv {
143147
passthru = {
144148
inherit versions numberOfVersions switch-ext-version;
145149
hasBackgroundWorker = true;
150+
libName = "timescaledb-loader";
146151
defaultSettings = {
147152
shared_preload_libraries = [ "timescaledb" ];
148153
};

0 commit comments

Comments
 (0)