|
1 | 1 | # -*- coding: utf-8 -*- |
2 | 2 | import platform |
3 | | -import time |
4 | 3 | if platform.python_version() < '2.7': |
5 | 4 | unittest = __import__('unittest2') |
6 | 5 | else: |
|
9 | 8 | from . import RUN_YZ |
10 | 9 |
|
11 | 10 |
|
| 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 | + |
12 | 24 | class YZSearchTests(object): |
13 | 25 | @unittest.skipUnless(RUN_YZ, 'RUN_YZ is undefined') |
14 | 26 | def test_yz_search_from_bucket(self): |
15 | 27 | bucket = self.client.bucket(self.yz_bucket) |
16 | 28 | bucket.new("user", {"user_s": "Z"}).store() |
17 | | - time.sleep(1) |
| 29 | + wait_for_yz_index(bucket, "user") |
18 | 30 | results = bucket.search("user_s:Z") |
19 | 31 | self.assertEquals(1, len(results['docs'])) |
20 | 32 | # TODO: check that docs return useful info |
@@ -49,7 +61,10 @@ def test_yz_delete_search_index(self): |
49 | 61 | self.client.create_search_index(self.yz_bucket, '_yz_default', 3) |
50 | 62 | b = self.client.bucket(self.yz_bucket) |
51 | 63 | 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()] |
53 | 68 |
|
54 | 69 | @unittest.skipUnless(RUN_YZ, 'RUN_YZ is undefined') |
55 | 70 | def test_yz_list_search_indexes(self): |
@@ -112,7 +127,7 @@ def test_yz_search_queries(self): |
112 | 127 | "age_i": 32}).store() |
113 | 128 | bucket.new("H", {"username_s": "H", "name_s": "brett", |
114 | 129 | "age_i": 14}).store() |
115 | | - time.sleep(1) |
| 130 | + wait_for_yz_index(bucket, "H") |
116 | 131 | # multiterm |
117 | 132 | results = bucket.search("username_s:(F OR H)") |
118 | 133 | self.assertEquals(2, len(results['docs'])) |
|
0 commit comments