Author: jbellis
Date: Tue Apr  6 21:39:48 2010
New Revision: 931340

URL: http://svn.apache.org/viewvc?rev=931340&view=rev
Log:
fix heisenbug in system tests, especially common on OS X.  patch by Brandon 
Williams; reviewed by jbellis for CASSANDRA-944

Modified:
    cassandra/trunk/CHANGES.txt
    cassandra/trunk/test/system/test_thrift_server.py

Modified: cassandra/trunk/CHANGES.txt
URL: 
http://svn.apache.org/viewvc/cassandra/trunk/CHANGES.txt?rev=931340&r1=931339&r2=931340&view=diff
==============================================================================
--- cassandra/trunk/CHANGES.txt (original)
+++ cassandra/trunk/CHANGES.txt Tue Apr  6 21:39:48 2010
@@ -5,6 +5,7 @@ dev
  * drain method to flush memtables and purge commit log prior to shutdown. 
(CASSANDRA-880)
  * access levels for authentication/authorization (CASSANDRA-900)
  * add ReadRepairChance to CF definition (CASSANDRA-930)
+ * fix heisenbug in system tests, especially common on OS X (CASSANDRA-944)
 
 
 0.6.1

Modified: cassandra/trunk/test/system/test_thrift_server.py
URL: 
http://svn.apache.org/viewvc/cassandra/trunk/test/system/test_thrift_server.py?rev=931340&r1=931339&r2=931340&view=diff
==============================================================================
--- cassandra/trunk/test/system/test_thrift_server.py (original)
+++ cassandra/trunk/test/system/test_thrift_server.py Tue Apr  6 21:39:48 2010
@@ -172,6 +172,23 @@ def _expect_exception(fn, type_):
 def _expect_missing(fn):
     _expect_exception(fn, NotFoundException)
 
+def waitfor(secs, fn, *args, **kwargs):
+    start = time.time()
+    success = False
+    last_exception = None
+    while not success and time.time() < start + secs:
+        try:
+            fn(*args, **kwargs)
+            success = True
+        except KeyboardInterrupt:
+            raise
+        except Exception, e:
+            last_exception = e
+            pass
+    if not success and last_exception:
+        raise last_exception
+
+ZERO_WAIT = 5
 
 class TestMutations(ThriftTester):
     def test_insert(self):
@@ -311,11 +328,10 @@ class TestMutations(ThriftTester):
         keyed_mutations = dict((key, mutation_map) for key in keys)
 
         client.batch_mutate('Keyspace1', keyed_mutations, 
ConsistencyLevel.ZERO)
-        time.sleep(0.1)
 
         for column_family in column_families:
             for key in keys:
-                _assert_column('Keyspace1', column_family, key, 'c1', 'value1')
+               waitfor(ZERO_WAIT, _assert_column, 'Keyspace1', column_family, 
key, 'c1', 'value1')
 
     def test_batch_mutate_standard_columns_blocking(self):
         column_families = ['Standard1', 'Standard2']
@@ -365,12 +381,11 @@ class TestMutations(ThriftTester):
         keyed_mutations = dict((key, mutation_map) for key in keys)
 
         client.batch_mutate('Keyspace1', keyed_mutations, 
ConsistencyLevel.ZERO)
-        time.sleep(0.1)
         for column_family in column_families:
             for sc in _SUPER_COLUMNS:
                 for c in sc.columns:
                     for key in keys:
-                        _assert_no_columnpath('Keyspace1', key, 
ColumnPath(column_family, super_column=sc.name, column=c.name))
+                        waitfor(ZERO_WAIT, _assert_no_columnpath, 'Keyspace1', 
key, ColumnPath(column_family, super_column=sc.name, column=c.name))
 
     def 
test_batch_mutate_remove_super_columns_with_none_given_underneath(self):
         keys = ['key_%d' % i for i in range(17,21)]
@@ -394,12 +409,11 @@ class TestMutations(ThriftTester):
                 _assert_columnpath_exists('Keyspace1', key, 
ColumnPath('Super1', super_column=sc.name))
 
         client.batch_mutate('Keyspace1', keyed_mutations, 
ConsistencyLevel.ZERO)
-        time.sleep(0.1)
 
         for sc in _SUPER_COLUMNS:
             for c in sc.columns:
                 for key in keys:
-                    _assert_no_columnpath('Keyspace1', key, 
ColumnPath('Super1', super_column=sc.name))
+                    waitfor(ZERO_WAIT, _assert_no_columnpath, 'Keyspace1', 
key, ColumnPath('Super1', super_column=sc.name))
 
     def test_batch_mutate_insertions_and_deletions(self):
         first_insert = SuperColumn("sc1",
@@ -543,9 +557,8 @@ class TestMutations(ThriftTester):
          cfmap = {'Super1': [ColumnOrSuperColumn(super_column=c) for c in 
_SUPER_COLUMNS],
                   'Super2': [ColumnOrSuperColumn(super_column=c) for c in 
_SUPER_COLUMNS]}
          client.batch_insert('Keyspace1', 'key1', cfmap, ConsistencyLevel.ZERO)
-         time.sleep(0.1)
-         _verify_super('Super1')
-         _verify_super('Super2')
+         waitfor(ZERO_WAIT, _verify_super, 'Super1')
+         waitfor(ZERO_WAIT, _verify_super, 'Super2')
 
     def test_batch_insert_super_blocking(self):
          cfmap = {'Super1': [ColumnOrSuperColumn(super_column=c) for c in 
_SUPER_COLUMNS],


Reply via email to