@@ -119,7 +119,14 @@ def _access_function():
119
119
fv_pairs = self .get_entry (table_name , key )
120
120
return (bool (fv_pairs ), fv_pairs )
121
121
122
- return wait_for_result (_access_function , polling_config )
122
+ status , result = wait_for_result (_access_function ,
123
+ self ._disable_strict_polling (polling_config ))
124
+
125
+ if not status :
126
+ assert not polling_config .strict , \
127
+ "Entry not found: key=\" {}\" , table=\" {}\" " .format (key , table_name )
128
+
129
+ return result
123
130
124
131
def wait_for_field_match (self ,
125
132
table_name ,
@@ -131,9 +138,6 @@ def wait_for_field_match(self,
131
138
at `key` in the specified table. This method will wait for the
132
139
fields to exist.
133
140
134
- Note:
135
- This method does not check for an exact match.
136
-
137
141
Args:
138
142
table_name (str): The name of the table where the entry is
139
143
stored.
@@ -152,12 +156,57 @@ def _access_function():
152
156
fv_pairs = self .get_entry (table_name , key )
153
157
return (all (fv_pairs .get (k ) == v for k , v in expected_fields .items ()), fv_pairs )
154
158
155
- return wait_for_result (_access_function , polling_config )
159
+ status , result = wait_for_result (_access_function ,
160
+ self ._disable_strict_polling (polling_config ))
161
+
162
+ if not status :
163
+ assert not polling_config .strict , \
164
+ "Expected fields not found: expected={}, received={}, \
165
+ key=\" {}\" , table=\" {}\" " .format (expected_fields , result , key , table_name )
156
166
157
- def wait_for_empty_entry (self ,
167
+ return result
168
+
169
+ def wait_for_exact_match (self ,
158
170
table_name ,
159
171
key ,
172
+ expected_entry ,
160
173
polling_config = DEFAULT_POLLING_CONFIG ):
174
+ """
175
+ Checks if the provided entry matches the entry stored at `key`
176
+ in the specified table. This method will wait for the exact entry
177
+ to exist.
178
+
179
+ Args:
180
+ table_name (str): The name of the table where the entry is
181
+ stored.
182
+ key (str): The key that maps to the entry being checked.
183
+ expected_entry (dict): The entry we expect to see.
184
+ polling_config (PollingConfig): The parameters to use to poll
185
+ the db.
186
+
187
+ Returns:
188
+ Dict[str, str]: The entry stored at `key`. If no entry is found,
189
+ then an empty Dict will be returned.
190
+ """
191
+
192
+ def _access_function ():
193
+ fv_pairs = self .get_entry (table_name , key )
194
+ return (fv_pairs == expected_entry , fv_pairs )
195
+
196
+ status , result = wait_for_result (_access_function ,
197
+ self ._disable_strict_polling (polling_config ))
198
+
199
+ if not status :
200
+ assert not polling_config .strict , \
201
+ "Exact match not found: expected={}, received={}, \
202
+ key=\" {}\" , table=\" {}\" " .format (expected_entry , result , key , table_name )
203
+
204
+ return result
205
+
206
+ def wait_for_deleted_entry (self ,
207
+ table_name ,
208
+ key ,
209
+ polling_config = DEFAULT_POLLING_CONFIG ):
161
210
"""
162
211
Checks if there is any entry stored at `key` in the specified
163
212
table. This method will wait for the entry to be empty.
@@ -169,14 +218,23 @@ def wait_for_empty_entry(self,
169
218
the db.
170
219
171
220
Returns:
172
- bool: True if no entry exists at `key`, False otherwise.
221
+ Dict[str, str]: The entry stored at `key`. If no entry is found,
222
+ then an empty Dict will be returned.
173
223
"""
174
224
175
225
def _access_function ():
176
226
fv_pairs = self .get_entry (table_name , key )
177
227
return (not bool (fv_pairs ), fv_pairs )
178
228
179
- return wait_for_result (_access_function , polling_config )
229
+ status , result = wait_for_result (_access_function ,
230
+ self ._disable_strict_polling (polling_config ))
231
+
232
+ if not status :
233
+ assert not polling_config .strict , \
234
+ "Entry still exists: entry={}, key=\" {}\" , table=\" {}\" " \
235
+ .format (result , key , table_name )
236
+
237
+ return result
180
238
181
239
def wait_for_n_keys (self ,
182
240
table_name ,
@@ -203,7 +261,15 @@ def _access_function():
203
261
keys = self .get_keys (table_name )
204
262
return (len (keys ) == num_keys , keys )
205
263
206
- return wait_for_result (_access_function , polling_config )
264
+ status , result = wait_for_result (_access_function ,
265
+ self ._disable_strict_polling (polling_config ))
266
+
267
+ if not status :
268
+ assert not polling_config .strict , \
269
+ "Unexpected number of keys: expected={}, received={} ({}), table=\" {}\" " \
270
+ .format (num_keys , len (result ), result , table_name )
271
+
272
+ return result
207
273
208
274
def wait_for_matching_keys (self ,
209
275
table_name ,
@@ -230,7 +296,15 @@ def _access_function():
230
296
keys = self .get_keys (table_name )
231
297
return (all (key in keys for key in expected_keys ), keys )
232
298
233
- return wait_for_result (_access_function , polling_config )
299
+ status , result = wait_for_result (_access_function ,
300
+ self ._disable_strict_polling (polling_config ))
301
+
302
+ if not status :
303
+ assert not polling_config .strict , \
304
+ "Expected keys not found: expected={}, received={}, table=\" {}\" " \
305
+ .format (expected_keys , result , table_name )
306
+
307
+ return result
234
308
235
309
def wait_for_deleted_keys (self ,
236
310
table_name ,
@@ -257,4 +331,19 @@ def _access_function():
257
331
keys = self .get_keys (table_name )
258
332
return (all (key not in keys for key in deleted_keys ), keys )
259
333
260
- return wait_for_result (_access_function , polling_config )
334
+ status , result = wait_for_result (_access_function ,
335
+ self ._disable_strict_polling (polling_config ))
336
+
337
+ if not status :
338
+ assert not polling_config .strict , \
339
+ "Unexpected keys found: expected={}, received={}, table=\" {}\" " \
340
+ .format (deleted_keys , result , table_name )
341
+
342
+ return result
343
+
344
+ @staticmethod
345
+ def _disable_strict_polling (polling_config ):
346
+ disabled_config = PollingConfig (polling_interval = polling_config .polling_interval ,
347
+ timeout = polling_config .timeout ,
348
+ strict = False )
349
+ return disabled_config
0 commit comments