Fix for materialized_views_tests to wait for the build to finish before any checks
@@ -90,6 +90,21 @@ class TestMaterializedViews(Tester):
time.sleep(0.1)
attempts -= 1
+ def _wait_for_view(self, ks, view):
+ debug("waiting for view")
+
+ def _view_build_finished(node):
+ s = self.patient_exclusive_cql_connection(node)
+ result = list(s.execute("SELECT * FROM system.views_builds_in_progress WHERE keyspace_name='%s' AND view_name='%s'" % (ks, view)))
+ return len(result) == 0
+
+ for node in self.cluster.nodelist():
+ if node.is_running():
+ attempts = 50 # 1 sec per attempt, so 50 seconds total
+ while attempts > 0 and not _view_build_finished(node):
+ time.sleep(1)
+ attempts -= 1
+
def _insert_data(self, session):
# insert data
insert_stmt = "INSERT INTO users (username, password, gender, state, birth_year) VALUES "
@@ -184,6 +199,9 @@ class TestMaterializedViews(Tester):
session.execute(("CREATE MATERIALIZED VIEW t_by_v AS SELECT * FROM t WHERE v IS NOT NULL "
"AND id IS NOT NULL PRIMARY KEY (v, id)"))
+ debug("wait for view to build")
+ self._wait_for_view("ks", "t_by_v")
+
debug("wait that all batchlogs are replayed")
self._replay_batchlogs()
@@ -204,6 +222,9 @@ class TestMaterializedViews(Tester):
session.execute(("CREATE MATERIALIZED VIEW t_by_v AS SELECT * FROM t WHERE v IS NOT NULL "
"AND id IS NOT NULL PRIMARY KEY (v, id)"))
+ debug("wait for view to build")
+ self._wait_for_view("ks", "t_by_v")
+
debug("wait that all batchlogs are replayed")
self._replay_batchlogs()
