@@ -44,30 +44,21 @@ def cleanup_json(expected_json):
4444 if (isfile (f"pacts/{ expected_json } " )):
4545 remove (f"pacts/{ expected_json } " )
4646
47-
48- def test_generate_pact_file (pact ):
49- cleanup_json (expected_json )
50-
51- expected_event = {
52- 'documentName' : 'document.doc' ,
53- 'creator' : 'TP' ,
54- 'documentType' : 'microsoft-word'
55- }
56-
57- (pact
58- .given ('A document create in Document Service' )
59- .expects_to_receive ('Provider state attribute' )
60- .with_content (expected_event )
61- .with_metadata ({
62- 'Content-Type' : 'application/json'
63- }))
64-
65- with pact :
66- # handler needs 'documentType' == 'microsoft-word'
67- MessageHandler (expected_event )
68-
69- time .sleep (1 )
70- assert isfile (f"pacts/{ expected_json } " ) == 1
47+ def progressive_delay (file , time_to_wait = 10 , second_interval = 0.5 , verbose = False ):
48+ """
49+ progressive delay
50+ defaults to wait up to 5 seconds with 0.5 second intervals
51+ """
52+ time_counter = 0
53+ while not isfile (file ):
54+ time .sleep (second_interval )
55+ time_counter += 1
56+ if verbose :
57+ print (f'Trying for { time_counter * second_interval } seconds' )
58+ if time_counter > time_to_wait :
59+ if verbose :
60+ print (f'Already waited { time_counter * second_interval } seconds' )
61+ break
7162
7263
7364def test_throw_exception_handler (pact ):
@@ -92,5 +83,30 @@ def test_throw_exception_handler(pact):
9283 # handler needs 'documentType' == 'microsoft-word'
9384 MessageHandler (wrong_event )
9485
95- time . sleep ( 1 )
86+ progressive_delay ( f"pacts/ { expected_json } " )
9687 assert isfile (f"pacts/{ expected_json } " ) == 0
88+
89+
90+ def test_generate_pact_file (pact ):
91+ cleanup_json (expected_json )
92+
93+ expected_event = {
94+ 'documentName' : 'document.doc' ,
95+ 'creator' : 'TP' ,
96+ 'documentType' : 'microsoft-word'
97+ }
98+
99+ (pact
100+ .given ('A document create in Document Service' )
101+ .expects_to_receive ('Description' )
102+ .with_content (expected_event )
103+ .with_metadata ({
104+ 'Content-Type' : 'application/json'
105+ }))
106+
107+ with pact :
108+ # handler needs 'documentType' == 'microsoft-word'
109+ MessageHandler (expected_event )
110+
111+ progressive_delay (f"pacts/{ expected_json } " )
112+ assert isfile (f"pacts/{ expected_json } " ) == 1
0 commit comments