Skip to content

Commit 99a4eee

Browse files
author
Brett Hazen
committed
Merge pull request basho#339 from basho/bugfix/bch/yz-test-setup
Remove time.sleep() from YZ test cases
2 parents 92d0e1d + 0f87d3c commit 99a4eee

File tree

2 files changed

+21
-6
lines changed

2 files changed

+21
-6
lines changed

riak/tests/test_mapreduce.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
from riak.mapreduce import RiakMapReduce
44
from riak import key_filter, RiakError
5+
from riak.tests.test_yokozuna import wait_for_yz_index
56
import platform
67
if platform.python_version() < '2.7':
78
unittest = __import__('unittest2')
@@ -374,8 +375,7 @@ def test_mr_search(self):
374375
"calories_i": 110,
375376
"fruit_b": False}).store()
376377
# Wait for Solr to catch up
377-
while len(bucket.search('_yz_rk:Crunch')['docs']) == 0:
378-
pass
378+
wait_for_yz_index(bucket, "Crunch")
379379
mr = RiakMapReduce(self.client).search(self.mr_bucket, 'fruit_b:false')
380380
mr.map("""function(v) {
381381
var solr_doc = JSON.parse(v.values[0].data);

riak/tests/test_yokozuna.py

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
# -*- coding: utf-8 -*-
22
import platform
3-
import time
43
if platform.python_version() < '2.7':
54
unittest = __import__('unittest2')
65
else:
@@ -9,12 +8,25 @@
98
from . import RUN_YZ
109

1110

11+
def wait_for_yz_index(bucket, key):
12+
"""
13+
Wait until Solr index has been updated and a value returns from a query.
14+
15+
:param bucket: Bucket to which indexed value is written
16+
:type bucket: RiakBucket
17+
:param key: Key to which value was written
18+
:type key: str
19+
"""
20+
while len(bucket.search('_yz_rk:' + key)['docs']) == 0:
21+
pass
22+
23+
1224
class YZSearchTests(object):
1325
@unittest.skipUnless(RUN_YZ, 'RUN_YZ is undefined')
1426
def test_yz_search_from_bucket(self):
1527
bucket = self.client.bucket(self.yz_bucket)
1628
bucket.new("user", {"user_s": "Z"}).store()
17-
time.sleep(1)
29+
wait_for_yz_index(bucket, "user")
1830
results = bucket.search("user_s:Z")
1931
self.assertEquals(1, len(results['docs']))
2032
# TODO: check that docs return useful info
@@ -49,7 +61,10 @@ def test_yz_delete_search_index(self):
4961
self.client.create_search_index(self.yz_bucket, '_yz_default', 3)
5062
b = self.client.bucket(self.yz_bucket)
5163
b.set_property('search_index', self.yz_bucket)
52-
time.sleep(1) # wait for index to apply
64+
# Wait for index to apply
65+
indexes = []
66+
while self.yz_bucket not in indexes:
67+
indexes = [i['name'] for i in self.client.list_search_indexes()]
5368

5469
@unittest.skipUnless(RUN_YZ, 'RUN_YZ is undefined')
5570
def test_yz_list_search_indexes(self):
@@ -112,7 +127,7 @@ def test_yz_search_queries(self):
112127
"age_i": 32}).store()
113128
bucket.new("H", {"username_s": "H", "name_s": "brett",
114129
"age_i": 14}).store()
115-
time.sleep(1)
130+
wait_for_yz_index(bucket, "H")
116131
# multiterm
117132
results = bucket.search("username_s:(F OR H)")
118133
self.assertEquals(2, len(results['docs']))

0 commit comments

Comments
 (0)