Skip to content

Commit 4c87f97

Browse files
authored
Merge pull request vitessio#2759 from thompsonja/vtctld
Reduce vtctld webdriver test flakiness.
2 parents ddc7d4a + 3abcac3 commit 4c87f97

File tree

1 file changed

+18
-9
lines changed

1 file changed

+18
-9
lines changed

test/vtctld_web_test.py

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ def tearDownModule():
4444

4545
class TestVtctldWeb(unittest.TestCase):
4646

47+
WEBDRIVER_TIMEOUT_S = 10
48+
4749
@classmethod
4850
def setUpClass(cls):
4951
"""Set up two keyspaces: one unsharded, one with two shards."""
@@ -94,7 +96,11 @@ def _get_keyspaces(self):
9496

9597
def _get_keyspace_element(self, keyspace_name):
9698
"""Get a specific keyspace element given a keyspace name."""
97-
return self.driver.find_element_by_id('%s-card' % keyspace_name)
99+
element_id = '%s-card' % keyspace_name
100+
wait = WebDriverWait(self.driver, self.WEBDRIVER_TIMEOUT_S)
101+
wait.until(expected_conditions.visibility_of_element_located(
102+
(By.ID, element_id)))
103+
return self.driver.find_element_by_id(element_id)
98104

99105
def _get_shards(self, keyspace_name):
100106
shard_grid = self.driver.find_element_by_id(
@@ -126,6 +132,9 @@ def _get_tablet_names(self):
126132
[(x.split(' ')[0], x.split(' ')[1][1:-1]) for x in tablet_titles])
127133

128134
def _get_shard_record_keyspace_shard(self):
135+
wait = WebDriverWait(self.driver, self.WEBDRIVER_TIMEOUT_S)
136+
wait.until(expected_conditions.visibility_of_element_located(
137+
(By.ID, 'keyspace-shard')))
129138
return self.driver.find_element_by_id('keyspace-shard').text
130139

131140
def _get_shard_record_master_tablet(self):
@@ -241,7 +250,7 @@ def _check_new_view(
241250
def _navigate_to_dashboard(self):
242251
logging.info('Fetching main vtctld page: %s', self.vtctld_addr)
243252
self.driver.get('%s/app2' % self.vtctld_addr)
244-
wait = WebDriverWait(self.driver, 10)
253+
wait = WebDriverWait(self.driver, self.WEBDRIVER_TIMEOUT_S)
245254
wait.until(expected_conditions.visibility_of_element_located(
246255
(By.ID, 'test_keyspace')))
247256

@@ -254,7 +263,7 @@ def _navigate_to_keyspace_view(self):
254263
first_keyspace_card = keyspace_cards[0]
255264
shard_stats = first_keyspace_card.find_element_by_tag_name('md-list')
256265
shard_stats.click()
257-
wait = WebDriverWait(self.driver, 10)
266+
wait = WebDriverWait(self.driver, self.WEBDRIVER_TIMEOUT_S)
258267
wait.until(expected_conditions.visibility_of_element_located(
259268
(By.CLASS_NAME, 'vt-card')))
260269

@@ -267,14 +276,14 @@ def _navigate_to_shard_view(self):
267276

268277
first_shard_card = shard_cards[0]
269278
first_shard_card.click()
270-
wait = WebDriverWait(self.driver, 10)
279+
wait = WebDriverWait(self.driver, self.WEBDRIVER_TIMEOUT_S)
271280
wait.until(expected_conditions.visibility_of_element_located(
272281
(By.ID, '1')))
273282

274283
# Get Elements
275284
def _get_dashboard_keyspaces(self):
276285
"""Get list of all present keyspaces."""
277-
wait = WebDriverWait(self.driver, 10)
286+
wait = WebDriverWait(self.driver, self.WEBDRIVER_TIMEOUT_S)
278287
wait.until(expected_conditions.visibility_of_element_located(
279288
(By.TAG_NAME, 'vt-dashboard')))
280289
dashboard_content = self.driver.find_element_by_tag_name('vt-dashboard')
@@ -283,23 +292,23 @@ def _get_dashboard_keyspaces(self):
283292

284293
def _get_dashboard_shards(self):
285294
"""Get list of all present shards."""
286-
wait = WebDriverWait(self.driver, 10)
295+
wait = WebDriverWait(self.driver, self.WEBDRIVER_TIMEOUT_S)
287296
wait.until(expected_conditions.visibility_of_element_located(
288297
(By.TAG_NAME, 'vt-dashboard')))
289298
dashboard_content = self.driver.find_element_by_tag_name('vt-dashboard')
290299
return [sh.text for sh in
291300
dashboard_content.find_elements_by_class_name('vt-shard-stats')]
292301

293302
def _get_keyspace_shards(self):
294-
wait = WebDriverWait(self.driver, 10)
303+
wait = WebDriverWait(self.driver, self.WEBDRIVER_TIMEOUT_S)
295304
wait.until(expected_conditions.visibility_of_element_located(
296305
(By.TAG_NAME, 'vt-keyspace-view')))
297306
keyspace_content = self.driver.find_element_by_tag_name('vt-keyspace-view')
298307
return [sh.text for sh in
299308
keyspace_content.find_elements_by_class_name('vt-serving-shard')]
300309

301310
def _get_shard_tablets(self):
302-
wait = WebDriverWait(self.driver, 10)
311+
wait = WebDriverWait(self.driver, self.WEBDRIVER_TIMEOUT_S)
303312
wait.until(expected_conditions.visibility_of_element_located(
304313
(By.TAG_NAME, 'vt-shard-view')))
305314
shard_content = self.driver.find_element_by_tag_name('vt-shard-view')
@@ -536,7 +545,7 @@ def test_realtime_stats(self):
536545
self.driver.get('%s/app2' % self.vtctld_addr)
537546
status_button = self.driver.find_element_by_partial_link_text('Status')
538547
status_button.click()
539-
wait = WebDriverWait(self.driver, 10)
548+
wait = WebDriverWait(self.driver, self.WEBDRIVER_TIMEOUT_S)
540549
wait.until(expected_conditions.visibility_of_element_located(
541550
(By.TAG_NAME, 'vt-status')))
542551

0 commit comments

Comments
 (0)