Skip to content

Commit 6ce7bdc

Browse files
committed
Fix #157 Improve the stability of API mock servers in unit tests
1 parent 3475ae7 commit 6ce7bdc

File tree

79 files changed

+872
-430
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

79 files changed

+872
-430
lines changed

.github/workflows/ci-build.yml

Lines changed: 40 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,15 @@ on:
99

1010
jobs:
1111
build:
12-
runs-on: ubuntu-latest
12+
runs-on: ubuntu-20.04
1313
timeout-minutes: 10
1414
strategy:
1515
matrix:
1616
python-version: ['3.6', '3.7', '3.8', '3.9']
17-
17+
env:
18+
# default: multiprocessing
19+
# threading is more stable on GitHub Actions
20+
BOLT_PYTHON_MOCK_SERVER_MODE: threading
1821
steps:
1922
- uses: actions/checkout@v2
2023
- name: Set up Python ${{ matrix.python-version }}
@@ -30,10 +33,41 @@ jobs:
3033
run: |
3134
pytest tests/slack_bolt/
3235
pytest tests/scenario_tests/
33-
- name: Run tests for adapters
36+
- name: Run tests for Socket Mode adapters
3437
run: |
3538
pip install -e ".[adapter]"
36-
pytest tests/adapter_tests/
39+
pytest tests/adapter_tests/socket_mode/
40+
- name: Run tests for HTTP Mode adapters (AWS)
41+
run: |
42+
pytest tests/adapter_tests/aws/
43+
- name: Run tests for HTTP Mode adapters (Bottle)
44+
run: |
45+
pytest tests/adapter_tests/bottle/
46+
- name: Run tests for HTTP Mode adapters (CherryPy)
47+
run: |
48+
pytest tests/adapter_tests/cherrypy/
49+
- name: Run tests for HTTP Mode adapters (Django)
50+
run: |
51+
pytest tests/adapter_tests/django/
52+
- name: Run tests for HTTP Mode adapters (Falcon)
53+
run: |
54+
pytest tests/adapter_tests/falcon/
55+
- name: Run tests for HTTP Mode adapters (Flask)
56+
run: |
57+
pytest tests/adapter_tests/flask/
58+
- name: Run tests for HTTP Mode adapters (Pyramid)
59+
run: |
60+
pytest tests/adapter_tests/pyramid/
61+
- name: Run tests for HTTP Mode adapters (Starlette)
62+
run: |
63+
pytest tests/adapter_tests/starlette/
64+
- name: Run tests for HTTP Mode adapters (Tornado)
65+
run: |
66+
pytest tests/adapter_tests/tornado/
67+
- name: Run tests for HTTP Mode adapters (asyncio-based libraries)
68+
run: |
69+
pip install -e ".[async]"
70+
pytest tests/adapter_tests_async/
3771
- name: Run pytype verification (3.8 only)
3872
run: |
3973
python_version=`python -V`
@@ -42,12 +76,10 @@ jobs:
4276
pip install -e ".[adapter]"
4377
pip install "pytype" && pytype slack_bolt/
4478
fi
45-
- name: Run all tests for codecov (3.6 only)
79+
- name: Run all tests for codecov (3.9 only)
4680
run: |
4781
python_version=`python -V`
48-
# TODO: As Python 3.6 works the most stably on GitHub Actions,
49-
# we use the version for code coverage and async tests
50-
if [ ${python_version:7:3} == "3.6" ]; then
82+
if [ ${python_version:7:3} == "3.9" ]; then
5183
pip install -e ".[async]"
5284
pip install -e ".[testing]"
5385
pytest --cov=slack_bolt/ && bash <(curl -s https://codecov.io/bash)

tests/adapter_tests/aws/__init__.py

Whitespace-only changes.

tests/adapter_tests/test_aws_chalice.py renamed to tests/adapter_tests/aws/test_aws_chalice.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
from tests.mock_web_api_server import (
2020
setup_mock_web_api_server,
2121
cleanup_mock_web_api_server,
22+
assert_auth_test_count,
2223
)
2324
from tests.utils import remove_os_env_temporarily, restore_os_env
2425

@@ -110,7 +111,7 @@ def events() -> Response:
110111
headers=self.build_headers(timestamp, body),
111112
)
112113
assert response["statusCode"] == 200
113-
assert self.mock_received_requests["/auth.test"] == 1
114+
assert_auth_test_count(self, 1)
114115

115116
def test_shortcuts(self):
116117
app = App(
@@ -157,7 +158,7 @@ def events() -> Response:
157158
headers=self.build_headers(timestamp, body),
158159
)
159160
assert response["statusCode"] == 200
160-
assert self.mock_received_requests["/auth.test"] == 1
161+
assert_auth_test_count(self, 1)
161162

162163
def test_commands(self):
163164
app = App(
@@ -204,7 +205,7 @@ def events() -> Response:
204205
headers=self.build_headers(timestamp, body),
205206
)
206207
assert response["statusCode"] == 200
207-
assert self.mock_received_requests["/auth.test"] == 1
208+
assert_auth_test_count(self, 1)
208209

209210
def test_lazy_listeners(self):
210211
app = App(
@@ -261,7 +262,7 @@ def say_it(say):
261262
)
262263
response: Response = slack_handler.handle(request)
263264
assert response.status_code == 200
264-
assert self.mock_received_requests["/auth.test"] == 1
265+
assert_auth_test_count(self, 1)
265266
assert self.mock_received_requests["/chat.postMessage"] == 1
266267

267268
def test_oauth(self):

tests/adapter_tests/test_aws_lambda.py renamed to tests/adapter_tests/aws/test_aws_lambda.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
from tests.mock_web_api_server import (
1515
setup_mock_web_api_server,
1616
cleanup_mock_web_api_server,
17+
assert_auth_test_count,
1718
)
1819
from tests.utils import remove_os_env_temporarily, restore_os_env
1920

@@ -123,7 +124,7 @@ def event_handler():
123124
}
124125
response = SlackRequestHandler(app).handle(event, self.context)
125126
assert response["statusCode"] == 200
126-
assert self.mock_received_requests["/auth.test"] == 1
127+
assert_auth_test_count(self, 1)
127128

128129
event = {
129130
"body": body,
@@ -134,7 +135,7 @@ def event_handler():
134135
}
135136
response = SlackRequestHandler(app).handle(event, self.context)
136137
assert response["statusCode"] == 200
137-
assert self.mock_received_requests["/auth.test"] == 1
138+
assert_auth_test_count(self, 1)
138139

139140
@mock_lambda
140141
def test_shortcuts(self):
@@ -173,7 +174,7 @@ def shortcut_handler(ack):
173174
}
174175
response = SlackRequestHandler(app).handle(event, self.context)
175176
assert response["statusCode"] == 200
176-
assert self.mock_received_requests["/auth.test"] == 1
177+
assert_auth_test_count(self, 1)
177178

178179
event = {
179180
"body": body,
@@ -184,7 +185,7 @@ def shortcut_handler(ack):
184185
}
185186
response = SlackRequestHandler(app).handle(event, self.context)
186187
assert response["statusCode"] == 200
187-
assert self.mock_received_requests["/auth.test"] == 1
188+
assert_auth_test_count(self, 1)
188189

189190
@mock_lambda
190191
def test_commands(self):
@@ -223,7 +224,7 @@ def command_handler(ack):
223224
}
224225
response = SlackRequestHandler(app).handle(event, self.context)
225226
assert response["statusCode"] == 200
226-
assert self.mock_received_requests["/auth.test"] == 1
227+
assert_auth_test_count(self, 1)
227228

228229
event = {
229230
"body": body,
@@ -234,7 +235,7 @@ def command_handler(ack):
234235
}
235236
response = SlackRequestHandler(app).handle(event, self.context)
236237
assert response["statusCode"] == 200
237-
assert self.mock_received_requests["/auth.test"] == 1
238+
assert_auth_test_count(self, 1)
238239

239240
@mock_lambda
240241
def test_lazy_listeners(self):
@@ -279,7 +280,7 @@ def say_it(say):
279280
}
280281
response = SlackRequestHandler(app).handle(event, self.context)
281282
assert response["statusCode"] == 200
282-
assert self.mock_received_requests["/auth.test"] == 1
283+
assert_auth_test_count(self, 1)
283284
assert self.mock_received_requests["/chat.postMessage"] == 1
284285

285286
@mock_lambda
File renamed without changes.

tests/adapter_tests/bottle/__init__.py

Whitespace-only changes.
Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
from tests.mock_web_api_server import (
1212
setup_mock_web_api_server,
1313
cleanup_mock_web_api_server,
14+
assert_auth_test_count,
1415
)
1516
from tests.utils import remove_os_env_temporarily, restore_os_env
1617

@@ -109,7 +110,7 @@ def test_events(self):
109110
response_body = slack_events()
110111
assert response.status_code == 200
111112
assert response_body == ""
112-
assert self.mock_received_requests["/auth.test"] == 1
113+
assert_auth_test_count(self, 1)
113114

114115
def test_shortcuts(self):
115116
input = {
@@ -138,7 +139,7 @@ def test_shortcuts(self):
138139
response_body = slack_events()
139140
assert response.status_code == 200
140141
assert response_body == ""
141-
assert self.mock_received_requests["/auth.test"] == 1
142+
assert_auth_test_count(self, 1)
142143

143144
def test_commands(self):
144145
input = (
@@ -167,4 +168,4 @@ def test_commands(self):
167168
response_body = slack_events()
168169
assert response.status_code == 200
169170
assert response_body == ""
170-
assert self.mock_received_requests["/auth.test"] == 1
171+
assert_auth_test_count(self, 1)
File renamed without changes.

tests/adapter_tests/cherrypy/__init__.py

Whitespace-only changes.
File renamed without changes.

0 commit comments

Comments
 (0)