]> git.ipfire.org Git - thirdparty/psycopg.git/commitdiff
test(crdb): fix flakey test
authorDaniele Varrazzo <daniele.varrazzo@gmail.com>
Fri, 6 Jan 2023 13:35:38 +0000 (13:35 +0000)
committerDaniele Varrazzo <daniele.varrazzo@gmail.com>
Fri, 6 Jan 2023 15:23:45 +0000 (15:23 +0000)
We often find a "delete" record more than once in the changefeed, before
deleting it. Tolerate one.

tests/crdb/test_cursor.py
tests/crdb/test_cursor_async.py

index 991b08455f016557a4230a59870084586c0b4157..d3c10e52454e7f25b0ff6808a06dd8c35701e203 100644 (file)
@@ -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()
index 229295ddd243405f3e0abb44ca9d6a03c31ce564..fcc7760a94915af18387a5e5ca8ffccb976b86f6 100644 (file)
@@ -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)