Commit d245b891 authored by Jim Fulton's avatar Jim Fulton

Refactored tests to use separate transaction managers to provide

isolation between connections, rather than using the no-longer
supported synch=False hack.
parent b0f992fd
...@@ -399,11 +399,13 @@ class NastyConfict(Base, TestCase): ...@@ -399,11 +399,13 @@ class NastyConfict(Base, TestCase):
# Invoke conflict resolution by committing a transaction. # Invoke conflict resolution by committing a transaction.
self.openDB() self.openDB()
r1 = self.db.open().root() tm1 = transaction.TransactionManager()
r1 = self.db.open(transaction_manager=tm1).root()
r1["t"] = self.t r1["t"] = self.t
transaction.commit() tm1.commit()
r2 = self.db.open(synch=False).root() tm2 = transaction.TransactionManager()
r2 = self.db.open(transaction_manager=tm2).root()
copy = r2["t"] copy = r2["t"]
# Make sure all of copy is loaded. # Make sure all of copy is loaded.
list(copy.values()) list(copy.values())
...@@ -433,7 +435,7 @@ class NastyConfict(Base, TestCase): ...@@ -433,7 +435,7 @@ class NastyConfict(Base, TestCase):
self.assertEqual(state[0][3], 75) self.assertEqual(state[0][3], 75)
self.assertEqual(state[0][5], 120) self.assertEqual(state[0][5], 120)
transaction.commit() tm1.commit()
# In the other transaction, add 3 values near the tail end of bucket1. # In the other transaction, add 3 values near the tail end of bucket1.
# This doesn't cause a split. # This doesn't cause a split.
...@@ -451,8 +453,7 @@ class NastyConfict(Base, TestCase): ...@@ -451,8 +453,7 @@ class NastyConfict(Base, TestCase):
self.assertEqual(state[0][1], 60) self.assertEqual(state[0][1], 60)
self.assertEqual(state[0][3], 120) self.assertEqual(state[0][3], 120)
self.assertRaises(ConflictError, transaction.commit) self.assertRaises(ConflictError, tm2.commit)
transaction.abort() # horrible things happen w/o this
def testEmptyBucketConflict(self): def testEmptyBucketConflict(self):
# Tests that an emptied bucket *created by* conflict resolution is # Tests that an emptied bucket *created by* conflict resolution is
...@@ -476,11 +477,13 @@ class NastyConfict(Base, TestCase): ...@@ -476,11 +477,13 @@ class NastyConfict(Base, TestCase):
# Invoke conflict resolution by committing a transaction. # Invoke conflict resolution by committing a transaction.
self.openDB() self.openDB()
r1 = self.db.open().root() tm1 = transaction.TransactionManager()
r1 = self.db.open(transaction_manager=tm1).root()
r1["t"] = self.t r1["t"] = self.t
transaction.commit() tm1.commit()
r2 = self.db.open(synch=False).root() tm2 = transaction.TransactionManager()
r2 = self.db.open(transaction_manager=tm2).root()
copy = r2["t"] copy = r2["t"]
# Make sure all of copy is loaded. # Make sure all of copy is loaded.
list(copy.values()) list(copy.values())
...@@ -502,7 +505,7 @@ class NastyConfict(Base, TestCase): ...@@ -502,7 +505,7 @@ class NastyConfict(Base, TestCase):
self.assertEqual(state[0][1], 60) self.assertEqual(state[0][1], 60)
self.assertEqual(state[0][3], 120) self.assertEqual(state[0][3], 120)
transaction.commit() tm1.commit()
# In the other transaction, delete the other half of bucket 1. # In the other transaction, delete the other half of bucket 1.
b = copy b = copy
...@@ -523,8 +526,7 @@ class NastyConfict(Base, TestCase): ...@@ -523,8 +526,7 @@ class NastyConfict(Base, TestCase):
# create an "insane" BTree (a legit BTree cannot contain an empty # create an "insane" BTree (a legit BTree cannot contain an empty
# bucket -- it contains NULL pointers the BTree code doesn't # bucket -- it contains NULL pointers the BTree code doesn't
# expect, and segfaults result). # expect, and segfaults result).
self.assertRaises(ConflictError, transaction.commit) self.assertRaises(ConflictError, tm2.commit)
transaction.abort() # horrible things happen w/o this
def testEmptyBucketNoConflict(self): def testEmptyBucketNoConflict(self):
...@@ -599,12 +601,14 @@ class NastyConfict(Base, TestCase): ...@@ -599,12 +601,14 @@ class NastyConfict(Base, TestCase):
def testThreeEmptyBucketsNoSegfault(self): def testThreeEmptyBucketsNoSegfault(self):
self.openDB() self.openDB()
r1 = self.db.open().root() tm1 = transaction.TransactionManager()
r1 = self.db.open(transaction_manager=tm1).root()
self.assertEqual(len(self.t), 0) self.assertEqual(len(self.t), 0)
r1["t"] = b = self.t # an empty tree r1["t"] = b = self.t # an empty tree
transaction.commit() tm1.commit()
r2 = self.db.open(synch=False).root() tm2 = transaction.TransactionManager()
r2 = self.db.open(transaction_manager=tm2).root()
copy = r2["t"] copy = r2["t"]
# Make sure all of copy is loaded. # Make sure all of copy is loaded.
list(copy.values()) list(copy.values())
...@@ -612,15 +616,14 @@ class NastyConfict(Base, TestCase): ...@@ -612,15 +616,14 @@ class NastyConfict(Base, TestCase):
# In one transaction, add and delete a key. # In one transaction, add and delete a key.
b[2] = 2 b[2] = 2
del b[2] del b[2]
transaction.commit() tm1.commit()
# In the other transaction, also add and delete a key. # In the other transaction, also add and delete a key.
b = copy b = copy
b[1] = 1 b[1] = 1
del b[1] del b[1]
# If the commit() segfaults, the C code is still wrong for this case. # If the commit() segfaults, the C code is still wrong for this case.
self.assertRaises(ConflictError, transaction.commit) self.assertRaises(ConflictError, tm2.commit)
transaction.abort()
def testCantResolveBTreeConflict(self): def testCantResolveBTreeConflict(self):
# Test that a conflict involving two different changes to # Test that a conflict involving two different changes to
...@@ -646,11 +649,13 @@ class NastyConfict(Base, TestCase): ...@@ -646,11 +649,13 @@ class NastyConfict(Base, TestCase):
# Set up database connections to provoke conflict. # Set up database connections to provoke conflict.
self.openDB() self.openDB()
r1 = self.db.open().root() tm1 = transaction.TransactionManager()
r1 = self.db.open(transaction_manager=tm1).root()
r1["t"] = self.t r1["t"] = self.t
transaction.commit() tm1.commit()
r2 = self.db.open(synch=False).root() tm2 = transaction.TransactionManager()
r2 = self.db.open(transaction_manager=tm2).root()
copy = r2["t"] copy = r2["t"]
# Make sure all of copy is loaded. # Make sure all of copy is loaded.
list(copy.values()) list(copy.values())
...@@ -662,16 +667,15 @@ class NastyConfict(Base, TestCase): ...@@ -662,16 +667,15 @@ class NastyConfict(Base, TestCase):
for k in range(200, 300, 4): for k in range(200, 300, 4):
self.t[k] = k self.t[k] = k
transaction.commit() tm1.commit()
for k in range(0, 60, 4): for k in range(0, 60, 4):
del copy[k] del copy[k]
try: try:
transaction.commit() tm2.commit()
except ConflictError, detail: except ConflictError, detail:
self.assert_(str(detail).startswith('database conflict error')) self.assert_(str(detail).startswith('database conflict error'))
transaction.abort()
else: else:
self.fail("expected ConflictError") self.fail("expected ConflictError")
...@@ -700,11 +704,13 @@ class NastyConfict(Base, TestCase): ...@@ -700,11 +704,13 @@ class NastyConfict(Base, TestCase):
# Set up database connections to provoke conflict. # Set up database connections to provoke conflict.
self.openDB() self.openDB()
r1 = self.db.open().root() tm1 = transaction.TransactionManager()
r1 = self.db.open(transaction_manager=tm1).root()
r1["t"] = self.t r1["t"] = self.t
transaction.commit() tm1.commit()
r2 = self.db.open(synch=False).root() tm2 = transaction.TransactionManager()
r2 = self.db.open(transaction_manager=tm2).root()
copy = r2["t"] copy = r2["t"]
# Make sure all of copy is loaded. # Make sure all of copy is loaded.
list(copy.values()) list(copy.values())
...@@ -716,15 +722,14 @@ class NastyConfict(Base, TestCase): ...@@ -716,15 +722,14 @@ class NastyConfict(Base, TestCase):
for k in range(0, 60, 4): for k in range(0, 60, 4):
del self.t[k] del self.t[k]
transaction.commit() tm1.commit()
copy[1] = 1 copy[1] = 1
try: try:
transaction.commit() tm2.commit()
except ConflictError, detail: except ConflictError, detail:
self.assert_(str(detail).startswith('database conflict error')) self.assert_(str(detail).startswith('database conflict error'))
transaction.abort()
else: else:
self.fail("expected ConflictError") self.fail("expected ConflictError")
...@@ -733,11 +738,13 @@ class NastyConfict(Base, TestCase): ...@@ -733,11 +738,13 @@ class NastyConfict(Base, TestCase):
for i in range(0, 200, 4): for i in range(0, 200, 4):
b[i] = i b[i] = i
r1 = self.db.open().root() tm1 = transaction.TransactionManager()
r1 = self.db.open(transaction_manager=tm1).root()
r1["t"] = b r1["t"] = b
transaction.commit() tm1.commit()
r2 = self.db.open(synch=False).root() tm2 = transaction.TransactionManager()
r2 = self.db.open(transaction_manager=tm2).root()
copy = r2["t"] copy = r2["t"]
# Make sure all of copy is loaded. # Make sure all of copy is loaded.
list(copy.values()) list(copy.values())
...@@ -747,15 +754,14 @@ class NastyConfict(Base, TestCase): ...@@ -747,15 +754,14 @@ class NastyConfict(Base, TestCase):
# Now one transaction empties the first bucket, and another adds a # Now one transaction empties the first bucket, and another adds a
# key to the first bucket. # key to the first bucket.
b[1] = 1 b[1] = 1
transaction.commit() tm1.commit()
for k in range(0, 60, 4): for k in range(0, 60, 4):
del copy[k] del copy[k]
try: try:
transaction.commit() tm2.commit()
except ConflictError, detail: except ConflictError, detail:
self.assert_(str(detail).startswith('database conflict error')) self.assert_(str(detail).startswith('database conflict error'))
transaction.abort()
else: else:
self.fail("expected ConflictError") self.fail("expected ConflictError")
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment