Skip to content

Commit fc0d91c

Browse files
feat: address PR comments
1 parent 5448d8c commit fc0d91c

File tree

2 files changed

+59
-27
lines changed

2 files changed

+59
-27
lines changed

Makefile

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,29 @@ define E2E
4040
endef
4141
export E2E
4242

43+
44+
define messaging
45+
echo "messaging make"
46+
cd examples/message
47+
pip install -r requirements.txt
48+
pip install -e ../../
49+
pytest
50+
endef
51+
export messaging
52+
53+
4354
.PHONY: e2e
4455
e2e:
4556
bash -c "$$E2E"
4657

58+
59+
.PHONY: messaging
60+
messaging:
61+
bash -c "$$messaging"
62+
63+
4764
.PHONY: examples
48-
examples: e2e
49-
65+
examples: e2e messaging
5066

5167

5268
.PHONY: package

examples/message/tests/consumer/test_message_consumer.py

Lines changed: 41 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -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

7364
def 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

Comments
 (0)