Skip to content

Commit 3e2ed81

Browse files
JelteFY--
andauthored
Fix a few motherduck and testing issues (#770)
When running the tests locally I found a few issues, both in the actual code and in the testing code. So this does the following changes: 1. Use `FindState` instead of `GetState` in all functions that are called by connection backends. (also added an Assert to not use the wrong one in the future). 2. Fail tests in case of an abort/segfault 3. Don't try running background worker queries in DuckDB even when `duckdb.force_execution` is set to `true`. 4. Include logfile path in test output on failure, for easier manual debugging. Partial fix for #746 --------- Co-authored-by: Yves <[email protected]> Co-authored-by: Y. <[email protected]>
1 parent e7f002c commit 3e2ed81

File tree

4 files changed

+30
-6
lines changed

4 files changed

+30
-6
lines changed

src/pgduckdb_background_worker.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ FindState() {
120120

121121
BgwStatePerDB *
122122
GetState() {
123+
Assert(is_background_worker);
123124
auto state = FindState();
124125
if (!state) {
125126
SpinLockRelease(&BgwShmemStruct->lock);
@@ -421,7 +422,10 @@ UnclaimBgwSessionHint(int /*code*/, Datum /*arg*/) {
421422
}
422423

423424
SpinLockAcquire(&BgwShmemStruct->lock);
424-
GetState()->bgw_session_hint_is_reused = false;
425+
auto *state = FindState();
426+
if (state) {
427+
state->bgw_session_hint_is_reused = false;
428+
}
425429
SpinLockRelease(&BgwShmemStruct->lock);
426430
reused_bgw_session_hint = false;
427431
}
@@ -510,8 +514,8 @@ PossiblyReuseBgwSessionHint(void) {
510514

511515
const char *result = "";
512516
SpinLockAcquire(&BgwShmemStruct->lock);
513-
auto state = GetState();
514-
if (!state->bgw_session_hint_is_reused) {
517+
auto state = FindState();
518+
if (state && !state->bgw_session_hint_is_reused) {
515519
result = bgw_session_hint;
516520
state->bgw_session_hint_is_reused = true;
517521
reused_bgw_session_hint = true;

src/pgduckdb_hooks.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,14 @@ ShouldTryToUseDuckdbExecution(Query *query) {
163163
return false;
164164
}
165165

166+
if (pgduckdb::is_background_worker) {
167+
/* If we're the background worker, we don't want to force duckdb
168+
* execution. Some of the queries that we're doing depend on Postgres
169+
* execution, particularly the ones that use the regclsas type to
170+
* understand tablenames. */
171+
return false;
172+
}
173+
166174
return duckdb_force_execution && pgduckdb::IsAllowedStatement(query) && ContainsFromClause(query);
167175
}
168176

test/pycheck/conftest.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,20 @@ def pg(initialized_shared_pg, default_db_name):
6363
try:
6464
shared_pg.cleanup_test_leftovers()
6565
finally:
66-
print("\n\nPG_LOG\n")
67-
print(f.read())
66+
print(f"\n\nPG_LOG {shared_pg.log_path}\n")
67+
logs = f.read()
68+
print(logs)
69+
# Usually when Postgres crashes we quickly notice due to a
70+
# query failing. Sometimes though it restarts fast enough that
71+
# there's no indictaion of the crash except for the logs. So
72+
# here we check that postgres did not crash during the last
73+
# test.
74+
assert (
75+
"was terminated by signal 6" not in logs
76+
), "Postgres crashed! Check the logs above."
77+
assert (
78+
"was terminated by signal 11" not in logs
79+
), "Postgres crashed! Check the logs above."
6880

6981

7082
@pytest.fixture

test/pycheck/utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -753,7 +753,7 @@ def start(self):
753753
try:
754754
self.pgctl(f'-o "-p {self.port}" -l {self.log_path} start')
755755
except Exception:
756-
print("\n\nPG_LOG\n")
756+
print(f"\n\nPG_LOG {self.log_path}\n")
757757
with self.log_path.open() as f:
758758
print(f.read())
759759
raise

0 commit comments

Comments
 (0)