@@ -119,18 +119,54 @@ def __access_function():
119
119
120
120
return result
121
121
122
- def wait_for_field_match (
122
+ def wait_for_fields (
123
123
self ,
124
124
table_name : str ,
125
125
key : str ,
126
- expected_fields : Dict [ str , str ],
126
+ expected_fields : List [ str ],
127
127
polling_config : PollingConfig = DEFAULT_POLLING_CONFIG
128
128
) -> Dict [str , str ]:
129
129
"""Wait for the entry stored at `key` to have the specified fields and retrieve it.
130
130
131
131
This method is useful if you only care about a subset of the fields stored in the
132
132
specified entry.
133
133
134
+ Args:
135
+ table_name: The name of the table where the entry is stored.
136
+ key: The key that maps to the entry being checked.
137
+ expected_fields: The fields that we expect to see in the entry.
138
+ polling_config: The parameters to use to poll the db.
139
+
140
+ Returns:
141
+ The entry stored at `key`. If no entry is found, then an empty Dict is returned.
142
+ """
143
+ def __access_function ():
144
+ fv_pairs = self .get_entry (table_name , key )
145
+ return (all (field in fv_pairs for field in expected_fields ), fv_pairs )
146
+
147
+ status , result = wait_for_result (
148
+ __access_function ,
149
+ self ._disable_strict_polling (polling_config ))
150
+
151
+ if not status :
152
+ assert not polling_config .strict , \
153
+ f"Expected fields not found: expected={ expected_fields } , \
154
+ received={ result } , key=\" { key } \" , table=\" { table_name } \" "
155
+
156
+ return result
157
+
158
+ def wait_for_field_match (
159
+ self ,
160
+ table_name : str ,
161
+ key : str ,
162
+ expected_fields : Dict [str , str ],
163
+ polling_config : PollingConfig = DEFAULT_POLLING_CONFIG
164
+ ) -> Dict [str , str ]:
165
+ """Wait for the entry stored at `key` to have the specified field/value pairs and retrieve it.
166
+
167
+ This method is useful if you only care about the contents of a subset of the fields stored in the
168
+ specified entry.
169
+
134
170
Args:
135
171
table_name: The name of the table where the entry is stored.
136
172
key: The key that maps to the entry being checked.
@@ -150,7 +186,42 @@ def __access_function():
150
186
151
187
if not status :
152
188
assert not polling_config .strict , \
153
- f"Expected fields not found: expected={ expected_fields } , \
189
+ f"Expected field/value pairs not found: expected={ expected_fields } , \
190
+ received={ result } , key=\" { key } \" , table=\" { table_name } \" "
191
+
192
+ return result
193
+
194
+ def wait_for_field_negative_match (
195
+ self ,
196
+ table_name : str ,
197
+ key : str ,
198
+ old_fields : Dict [str , str ],
199
+ polling_config : PollingConfig = DEFAULT_POLLING_CONFIG
200
+ ) -> Dict [str , str ]:
201
+ """Wait for the entry stored at `key` to have different field/value pairs than the ones specified.
202
+
203
+ This method is useful if you expect some field to change, but you don't know their exact values.
204
+
205
+ Args:
206
+ table_name: The name of the table where the entry is stored.
207
+ key: The key that maps to the entry being checked.
208
+ old_fields: The original field/value pairs we expect to change.
209
+ polling_config: The parameters to use to poll the db.
210
+
211
+ Returns:
212
+ The entry stored at `key`. If no entry is found, then an empty Dict is returned.
213
+ """
214
+ def __access_function ():
215
+ fv_pairs = self .get_entry (table_name , key )
216
+ return (all (k in fv_pairs and fv_pairs [k ] != v for k , v in old_fields .items ()), fv_pairs )
217
+
218
+ status , result = wait_for_result (
219
+ __access_function ,
220
+ self ._disable_strict_polling (polling_config ))
221
+
222
+ if not status :
223
+ assert not polling_config .strict , \
224
+ f"Did not expect field/values to match, but they did: provided={ old_fields } , \
154
225
received={ result } , key=\" { key } \" , table=\" { table_name } \" "
155
226
156
227
return result
0 commit comments