Changeset: 200f4137e5fc for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/200f4137e5fc
Modified Files:
        sql/test/BugTracker-2021/Tests/serializable-snapshot.Bug-7200.SQL.py
Branch: default
Log Message:

Use with clauses, and print more info when test fails.


diffs (102 lines):

diff --git 
a/sql/test/BugTracker-2021/Tests/serializable-snapshot.Bug-7200.SQL.py 
b/sql/test/BugTracker-2021/Tests/serializable-snapshot.Bug-7200.SQL.py
--- a/sql/test/BugTracker-2021/Tests/serializable-snapshot.Bug-7200.SQL.py
+++ b/sql/test/BugTracker-2021/Tests/serializable-snapshot.Bug-7200.SQL.py
@@ -1,21 +1,16 @@
 from MonetDBtesting import tpymonetdb as pymonetdb
-import sys, threading, os
-
-client1 = pymonetdb.connect(port = int(os.getenv('MAPIPORT', '50000')), 
database = os.getenv('TSTDB', 'demo'), hostname = os.getenv('MAPIHOST', 
'localhost'), autocommit=True)
-client2 = pymonetdb.connect(port = int(os.getenv('MAPIPORT', '50000')), 
database = os.getenv('TSTDB', 'demo'), hostname = os.getenv('MAPIHOST', 
'localhost'), autocommit=True)
-cursor1 = client1.cursor()
-cursor2 = client2.cursor()
+import sys
+import threading
+import os
 
 MAX_ITERATIONS = 1000
-EXPECTED_SUM = sum(range(0, MAX_ITERATIONS))
+# EXPECTED_SUM = sum(range(0, MAX_ITERATIONS))
+EXPECTED_SUM = MAX_ITERATIONS * (MAX_ITERATIONS - 1) // 2
 
-cursor1.execute("DROP TABLE if exists T;")
-cursor1.execute("CREATE TABLE T (k INT PRIMARY KEY, v INT);")
 
 class TestClient(threading.Thread):
-
     def __init__(self, cursor):
-        threading.Thread.__init__ (self)
+        threading.Thread.__init__(self)
         self._cursor = cursor
 
     def run(self):
@@ -26,31 +21,46 @@ class TestClient(threading.Thread):
                 pass
 
 
-thread1 = TestClient(cursor1)
-thread2 = TestClient(cursor2)
-thread1.start()
-thread2.start()
-thread1.join()
-thread2.join()
+xit = 0                         # exit code
+
+with pymonetdb.connect(port=int(os.getenv('MAPIPORT', '50000')),
+                       database=os.getenv('TSTDB', 'demo'),
+                       hostname=os.getenv('MAPIHOST', 'localhost'),
+                       autocommit=True) as client1, \
+     pymonetdb.connect(port=int(os.getenv('MAPIPORT', '50000')),
+                       database=os.getenv('TSTDB', 'demo'),
+                       hostname=os.getenv('MAPIHOST', 'localhost'),
+                       autocommit=True) as client2, \
+     client1.cursor() as cursor1, \
+     client2.cursor() as cursor2:
+
+    cursor1.execute("DROP TABLE if exists T;")
+    cursor1.execute("CREATE TABLE T (k INT PRIMARY KEY, v INT);")
 
-cursor1.execute("SELECT COUNT(*), COUNT(DISTINCT v), SUM(k) from T;")
-res = cursor1.fetchall()
-if res != [(MAX_ITERATIONS, MAX_ITERATIONS, EXPECTED_SUM)]:
-    print("[(%d,%d,%d)] expected, [(%d,%d,%d)] received" % (MAX_ITERATIONS, 
MAX_ITERATIONS, EXPECTED_SUM, res[0][0], res[0][1], res[0][2]), file=sys.stderr)
-    cursor1.execute("SELECT * FROM T;")
+    thread1 = TestClient(cursor1)
+    thread2 = TestClient(cursor2)
+    thread1.start()
+    thread2.start()
+    thread1.join()
+    thread2.join()
+
+    cursor1.execute("SELECT COUNT(*), COUNT(DISTINCT v), SUM(k) from T;")
     res = cursor1.fetchall()
-    s = set()
-    for t in res:
-        if t[0] in s:
-            print(f"duplicate entry {t}", file=sys.stderr)
-        else:
-            s.add(t[0])
-    for i in range(MAX_ITERATIONS):
-        if i not in s:
-            print(f"entry {i} missing", file=sys.stderr)
+    if res != [(MAX_ITERATIONS, MAX_ITERATIONS, EXPECTED_SUM)]:
+        xit = 1
+        print(f"{[(MAX_ITERATIONS, MAX_ITERATIONS, EXPECTED_SUM)]} expected,"
+              f" {res} received", file=sys.stderr)
+        cursor1.execute("SELECT * FROM T;")
+        res = cursor1.fetchall()
+        s = set()
+        for t in res:
+            if t[0] in s:
+                print(f"duplicate entry {t}", file=sys.stderr)
+            else:
+                s.add(t[0])
+        for i in range(MAX_ITERATIONS):
+            if i not in s:
+                print(f"entry {i} missing", file=sys.stderr)
 
 
-cursor1.close()
-cursor2.close()
-client1.close()
-client2.close()
+sys.exit(xit)
_______________________________________________
checkin-list mailing list -- [email protected]
To unsubscribe send an email to [email protected]

Reply via email to