Skip to content

Commit

Permalink
added tests for explain
Browse files Browse the repository at this point in the history
  • Loading branch information
wangpatrick57 committed Nov 14, 2024
1 parent 4fb3b2c commit 5f006ea
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
13 changes: 10 additions & 3 deletions env/integtest_pg_conn.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,12 +180,19 @@ def test_time_query(self) -> None:
pg_conn.restart_postgres()

# Test
runtime, did_time_out, explain_data = pg_conn.time_query("select 1", 5)
# The runtime (in microseconds) should be within these two orders of magnitude.
self.assertTrue(100 <= runtime < 10000)
# No explain
runtime, did_time_out, explain_data = pg_conn.time_query("select pg_sleep(1)", 2)
# The runtime should be about 1 second.
self.assertTrue(abs(runtime - 1_000_000) < 100_000)
self.assertFalse(did_time_out)
self.assertIsNone(explain_data)

# With explain
runtime, did_time_out, explain_data = pg_conn.time_query("explain (analyze, format json, timing off) select pg_sleep(1)", 2)
self.assertTrue(abs(runtime - 1_000_000) < 100_000)
self.assertFalse(did_time_out)
self.assertIsNotNone(explain_data)

# Cleanup
pg_conn.shutdown_postgres()

Expand Down
2 changes: 1 addition & 1 deletion env/pg_conn.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ def time_query(self, query: str, timeout: float) -> tuple[float, bool, Any]:
It returns the runtime, whether the query timed out, and the explain data.
"""
did_time_out = False
has_explain = "EXPLAIN" in query
has_explain = "explain" in query.lower()
explain_data = None

try:
Expand Down

0 comments on commit 5f006ea

Please sign in to comment.