Skip to content

Commit 98ff337

Browse files
authored
Fix unit and e2e tests
* Fix unit tests by disabling background worker during tests * Fix E2E test race condition in extension drop/recreate tests Add 1-second delay after worker table initialization to avoid migration conflicts when client connects. The race condition occurred when: 1. Background worker initializes duroxide-pg tables 2. Client session calls df.start() and creates its own PostgresProvider 3. Both try to run migrations concurrently, causing duplicate key errors Tests fixed: 25_extension_creation_security, 26_drop_create_loop
1 parent b6c6e76 commit 98ff337

5 files changed

Lines changed: 18 additions & 6 deletions

File tree

.github/workflows/ci.yml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,3 @@ jobs:
114114
# - name: Stop PostgreSQL after pg_regress
115115
# if: steps.pg_regress.outcome != 'skipped'
116116
# run: ./scripts/pg-stop.sh
117-
118-
# - name: Stop PostgreSQL after pg_regress
119-
# if: steps.pg_regress.outcome != 'skipped'
120-
# run: ./scripts/pg-reset.sh

scripts/pg-start.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ if [ -f "$PG_CONF" ]; then
3737

3838
# Configure pg_durable.database_name GUC if provided
3939
if [ -n "$DATABASE_GUC" ]; then
40-
# Remove any existing pg_durable.database_name setting
41-
sed -i '/^pg_durable\.database_name/d' "$PG_CONF"
40+
# Remove any existing pg_durable.database_name setting (portable sed -i usage)
41+
sed -i.bak '/^pg_durable\.database_name/d' "$PG_CONF" && rm -f "$PG_CONF.bak"
4242
echo -e "\033[0;33mSetting pg_durable.database_name = '$DATABASE_GUC'...\033[0m"
4343
echo "pg_durable.database_name = '$DATABASE_GUC'" >> "$PG_CONF"
4444
fi

src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ pub extern "C-unwind" fn _PG_init() {
5959
pgrx::GucFlags::default(),
6060
);
6161

62+
// Don't start the background worker during pgrx tests to avoid database locking issues
63+
#[cfg(not(feature = "pg_test"))]
6264
worker::register_background_worker();
6365
}
6466

tests/e2e/sql/25_extension_creation_security.sql

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,10 @@ BEGIN
189189
RAISE NOTICE 'PASS: Worker initialized duroxide-pg after recreation';
190190
END $$;
191191

192+
-- Give the worker additional time to fully complete initialization
193+
-- This avoids race conditions with migration conflicts when client connects
194+
SELECT pg_sleep(1);
195+
192196
-- Verify extension schemas and ownership
193197
DO $$
194198
DECLARE

tests/e2e/sql/26_drop_create_loop.sql

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,10 @@ BEGIN
4444
RAISE NOTICE 'PASS: Worker initialized duroxide-pg after cycle 1';
4545
END $$;
4646

47+
-- Give the worker additional time to fully complete initialization
48+
-- This avoids race conditions with migration conflicts when client connects
49+
SELECT pg_sleep(1);
50+
4751
-- Verify operational with a simple durable function
4852
CREATE TEMP TABLE _cycle1_state (instance_id TEXT);
4953
INSERT INTO _cycle1_state
@@ -100,6 +104,9 @@ BEGIN
100104
RAISE NOTICE 'PASS: Worker initialized duroxide-pg after cycle 2';
101105
END $$;
102106

107+
-- Give the worker additional time to fully complete initialization
108+
SELECT pg_sleep(1);
109+
103110
-- Verify operational again
104111
CREATE TEMP TABLE _cycle2_state (instance_id TEXT);
105112
INSERT INTO _cycle2_state
@@ -156,6 +163,9 @@ BEGIN
156163
RAISE NOTICE 'PASS: Worker initialized duroxide-pg after cycle 3';
157164
END $$;
158165

166+
-- Give the worker additional time to fully complete initialization
167+
SELECT pg_sleep(1);
168+
159169
-- Verify operational one more time
160170
CREATE TEMP TABLE _cycle3_state (instance_id TEXT);
161171
INSERT INTO _cycle3_state

0 commit comments

Comments
 (0)