14
14
# limitations under the License.
15
15
16
16
import copy
17
- from enum import Enum
17
+ from enum import Enum , auto
18
18
19
19
import yaml
20
20
50
50
'maxInterval' ,
51
51
'timedInteractionTimeoutMs' ,
52
52
'busyWaitMs' ,
53
+ 'wait' ,
53
54
]
54
55
55
56
_TEST_ARGUMENTS_SECTION = [
@@ -91,11 +92,12 @@ class PostProcessCheckStatus(Enum):
91
92
92
93
class PostProcessCheckType (Enum ):
93
94
'''Indicates the post processing check step type.'''
94
- IM_STATUS = 'IMStatus' ,
95
- CLUSTER_STATUS = 'ClusterStatus' ,
96
- RESPONSE_VALIDATION = 'Response' ,
97
- CONSTRAINT_VALIDATION = 'Constraints' ,
98
- SAVE_AS_VARIABLE = 'SaveAs'
95
+ IM_STATUS = auto ()
96
+ CLUSTER_STATUS = auto ()
97
+ RESPONSE_VALIDATION = auto ()
98
+ CONSTRAINT_VALIDATION = auto ()
99
+ SAVE_AS_VARIABLE = auto ()
100
+ WAIT_VALIDATION = auto ()
99
101
100
102
101
103
class PostProcessCheck :
@@ -213,9 +215,10 @@ def __init__(self, test: dict, config: dict, definitions: SpecDefinitions, pics_
213
215
self .timed_interaction_timeout_ms = _value_or_none (
214
216
test , 'timedInteractionTimeoutMs' )
215
217
self .busy_wait_ms = _value_or_none (test , 'busyWaitMs' )
218
+ self .wait_for = _value_or_none (test , 'wait' )
216
219
217
- self .is_attribute = self .command in _ATTRIBUTE_COMMANDS
218
- self .is_event = self .command in _EVENT_COMMANDS
220
+ self .is_attribute = self .command in _ATTRIBUTE_COMMANDS or self . wait_for in _ATTRIBUTE_COMMANDS
221
+ self .is_event = self .command in _EVENT_COMMANDS or self . wait_for in _EVENT_COMMANDS
219
222
220
223
self .arguments_with_placeholders = _value_or_none (test , 'arguments' )
221
224
self .response_with_placeholders = _value_or_none (test , 'response' )
@@ -472,9 +475,17 @@ def timed_interaction_timeout_ms(self):
472
475
def busy_wait_ms (self ):
473
476
return self ._test .busy_wait_ms
474
477
478
+ @property
479
+ def wait_for (self ):
480
+ return self ._test .wait_for
481
+
475
482
def post_process_response (self , response : dict ):
476
483
result = PostProcessResponseResult ()
477
484
485
+ if self .wait_for is not None :
486
+ self ._response_cluster_wait_validation (response , result )
487
+ return result
488
+
478
489
if self ._skip_post_processing (response , result ):
479
490
return result
480
491
@@ -487,6 +498,52 @@ def post_process_response(self, response: dict):
487
498
488
499
return result
489
500
501
+ def _response_cluster_wait_validation (self , response , result ):
502
+ """Check if the response concrete path matches the configuration of the test step
503
+ and validate that the response type (e.g readAttribute/writeAttribute/...) matches
504
+ the expectation from the test step."""
505
+ check_type = PostProcessCheckType .WAIT_VALIDATION
506
+ error_success = 'The test expectation "{wait_for}" for "{cluster}.{wait_type}" on endpoint {endpoint} is true'
507
+ error_failure = 'The test expectation "{expected} == {received}" is false'
508
+
509
+ if self .is_attribute :
510
+ expected_wait_type = self .attribute
511
+ received_wait_type = response .get ('attribute' )
512
+ elif self .is_event :
513
+ expected_wait_type = self .event
514
+ received_wait_type = response .get ('event' )
515
+ else :
516
+ expected_wait_type = self .command
517
+ received_wait_type = response .get ('command' )
518
+
519
+ expected_values = [
520
+ self .wait_for ,
521
+ self .endpoint ,
522
+ # TODO The name in tests does not always use spaces
523
+ self .cluster .replace (' ' , '' ),
524
+ expected_wait_type
525
+ ]
526
+
527
+ received_values = [
528
+ response .get ('wait_for' ),
529
+ response .get ('endpoint' ),
530
+ response .get ('cluster' ),
531
+ received_wait_type
532
+ ]
533
+
534
+ success = True
535
+ for expected_value in expected_values :
536
+ received_value = received_values .pop (0 )
537
+
538
+ if expected_value != received_value :
539
+ result .error (check_type , error_failure .format (
540
+ expected = expected_value , received = received_value ))
541
+ success = False
542
+
543
+ if success :
544
+ result .success (check_type , error_success .format (
545
+ wait_for = self .wait_for , cluster = self .cluster , wait_type = expected_wait_type , endpoint = self .endpoint ))
546
+
490
547
def _skip_post_processing (self , response : dict , result ) -> bool :
491
548
'''Should we skip perform post processing.
492
549
0 commit comments