From: Daniele Varrazzo Date: Fri, 6 Jan 2023 13:35:38 +0000 (+0000) Subject: test(crdb): fix flakey test X-Git-Tag: pool-3.2.0~141 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=861e06fe69a752b29ea79bc9c015d240e9f304c2;p=thirdparty%2Fpsycopg.git test(crdb): fix flakey test We often find a "delete" record more than once in the changefeed, before deleting it. Tolerate one. --- diff --git a/tests/crdb/test_cursor.py b/tests/crdb/test_cursor.py index 991b08455..d3c10e524 100644 --- a/tests/crdb/test_cursor.py +++ b/tests/crdb/test_cursor.py @@ -61,5 +61,14 @@ def test_changefeed(conn_cls, dsn, conn, testfeed, fmt_out): cur.execute("cancel query %s", [qid]) assert cur.statusmessage == "CANCEL QUERIES 1" - assert q.get(timeout=1) is None + # We often find the record with {"after": null} at least another time + # in the queue. Let's tolerate an extra one. + for i in range(2): + row = q.get(timeout=1) + if row is None: + break + assert json.loads(row.value)["after"] is None, json + else: + pytest.fail("keep on receiving messages") + t.join() diff --git a/tests/crdb/test_cursor_async.py b/tests/crdb/test_cursor_async.py index 229295ddd..fcc7760a9 100644 --- a/tests/crdb/test_cursor_async.py +++ b/tests/crdb/test_cursor_async.py @@ -57,5 +57,14 @@ async def test_changefeed(aconn_cls, dsn, aconn, testfeed, fmt_out): await cur.execute("cancel query %s", [qid]) assert cur.statusmessage == "CANCEL QUERIES 1" - assert await asyncio.wait_for(q.get(), 1.0) is None + # We often find the record with {"after": null} at least another time + # in the queue. Let's tolerate an extra one. + for i in range(2): + row = await asyncio.wait_for(q.get(), 1.0) + if row is None: + break + assert json.loads(row.value)["after"] is None, json + else: + pytest.fail("keep on receiving messages") + await asyncio.gather(t)