diff --git a/env/integtest_pg_conn.py b/env/integtest_pg_conn.py index 61bb5be9..14d16a61 100644 --- a/env/integtest_pg_conn.py +++ b/env/integtest_pg_conn.py @@ -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() diff --git a/env/pg_conn.py b/env/pg_conn.py index ba1007e1..6f9d7afb 100644 --- a/env/pg_conn.py +++ b/env/pg_conn.py @@ -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: