Fix for materialized_views_tests to wait for the build to finish before any checks
Project: http://git-wip-us.apache.org/repos/asf/cassandra-dtest/repo Commit: http://git-wip-us.apache.org/repos/asf/cassandra-dtest/commit/21d47364 Tree: http://git-wip-us.apache.org/repos/asf/cassandra-dtest/tree/21d47364 Diff: http://git-wip-us.apache.org/repos/asf/cassandra-dtest/diff/21d47364 Branch: refs/heads/master Commit: 21d473644ddd1a892b76db419ae454fb72f83465 Parents: 13a8ec4 Author: T Jake Luciani <[email protected]> Authored: Thu Feb 23 17:12:48 2017 -0500 Committer: T Jake Luciani <[email protected]> Committed: Thu Mar 9 11:31:32 2017 -0500 ---------------------------------------------------------------------- materialized_views_test.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cassandra-dtest/blob/21d47364/materialized_views_test.py ---------------------------------------------------------------------- diff --git a/materialized_views_test.py b/materialized_views_test.py index e8c86c0..0c9cdcb 100644 --- a/materialized_views_test.py +++ b/materialized_views_test.py @@ -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() --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
