From 963416ae29e3fe011a4a037405434a8ac631a604 Mon Sep 17 00:00:00 2001 From: Robert Vollmert Date: Thu, 6 Apr 2023 20:31:52 +0200 Subject: [PATCH] test: stabilize log probe in test_pool_acquisition_timeout There's two lines of log output, and their order is not deterministic. --- test/io/postgrest.py | 12 ++++++++++++ test/io/test_io.py | 21 +++++---------------- 2 files changed, 17 insertions(+), 16 deletions(-) diff --git a/test/io/postgrest.py b/test/io/postgrest.py index bd25c4c47..0dccb41b6 100644 --- a/test/io/postgrest.py +++ b/test/io/postgrest.py @@ -42,6 +42,18 @@ class PostgrestProcess: process: object session: object + def read_stdout(self, nlines=1): + "Wait for line(s) on standard output." + output = [] + for _ in range(10): + l = self.process.stdout.readline() + if l: + output.append(l.decode()) + if len(output) >= nlines: + break + time.sleep(0.1) + return output + @contextlib.contextmanager def run( diff --git a/test/io/test_io.py b/test/io/test_io.py index a33a9c34b..08e6ef5f7 100644 --- a/test/io/test_io.py +++ b/test/io/test_io.py @@ -416,14 +416,8 @@ def test_invalid_role_claim_key_notify_reload(defaultenv): with run(env=env) as postgrest: postgrest.session.post("/rpc/invalid_role_claim_key_reload") - output = None - for _ in range(10): - output = postgrest.process.stdout.readline() - if output: - break - time.sleep(0.1) - - assert "failed to parse role-claim-key value" in output.decode() + output = postgrest.read_stdout() + assert "failed to parse role-claim-key value" in output[0] response = postgrest.session.post("/rpc/reset_invalid_role_claim_key") assert response.status_code == 204 @@ -572,14 +566,9 @@ def test_pool_acquisition_timeout(defaultenv, metapostgrest): assert data["message"] == "Timed out acquiring connection from connection pool." # ensure the message appears on the logs as well - output = None - for _ in range(10): - output = postgrest.process.stdout.readline() - if output: - break - time.sleep(0.1) - - assert "Timed out acquiring connection from connection pool." in output.decode() + output = sorted(postgrest.read_stdout(nlines=2)) + assert " 504 " in output[0] + assert "Timed out acquiring connection from connection pool." in output[1] def test_change_statement_timeout_held_connection(defaultenv, metapostgrest):