11
11
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
12
# See the License for the specific language governing permissions and
13
13
# limitations under the License.
14
- import os
15
14
import pathlib
16
15
import pytest
17
16
import requests
30
29
31
30
@pytest .fixture (autouse = True )
32
31
def run_around_tests ():
32
+ # the test samples test also listens on 8080, so let's be good stewards of
33
+ # the port and make sure it's free
33
34
_wait_for_no_listen (TEST_HOST , TEST_PORT )
34
35
yield
36
+ _wait_for_no_listen (TEST_HOST , TEST_PORT )
35
37
36
38
39
+ @pytest .mark .slow_integration_test
37
40
def test_no_timeout_allows_request_processing_to_finish ():
38
41
source = TEST_FUNCTIONS_DIR / "timeout" / "main.py"
39
42
target = "function"
@@ -53,12 +56,13 @@ def test_no_timeout_allows_request_processing_to_finish():
53
56
54
57
result = requests .get ("http://{}:{}/" .format (TEST_HOST , TEST_PORT ))
55
58
56
- gunicorn_p .kill ()
59
+ gunicorn_p .terminate ()
57
60
gunicorn_p .join ()
58
61
59
62
assert result .status_code == 200
60
63
61
64
65
+ @pytest .mark .slow_integration_test
62
66
def test_timeout_but_not_threaded_timeout_enabled_does_not_kill (monkeypatch ):
63
67
monkeypatch .setenv ("CLOUD_RUN_TIMEOUT_SECONDS" , "1" )
64
68
monkeypatch .setenv ("THREADED_TIMEOUT_ENABLED" , "false" )
@@ -73,23 +77,20 @@ def test_timeout_but_not_threaded_timeout_enabled_does_not_kill(monkeypatch):
73
77
app , TEST_HOST , TEST_PORT , False , ** options
74
78
)
75
79
76
- os .environ .clear ()
77
- os .environ ["CLOUD_RUN_TIMEOUT_SECONDS" ] = "1"
78
- os .environ ["THREADED_TIMEOUT_ENABLED" ] = "false"
79
-
80
80
gunicorn_p = Process (target = gunicorn_app .run )
81
81
gunicorn_p .start ()
82
82
83
83
_wait_for_listen (TEST_HOST , TEST_PORT )
84
84
85
85
result = requests .get ("http://{}:{}/" .format (TEST_HOST , TEST_PORT ))
86
86
87
- gunicorn_p .kill ()
87
+ gunicorn_p .terminate ()
88
88
gunicorn_p .join ()
89
89
90
90
assert result .status_code == 200
91
91
92
92
93
+ @pytest .mark .slow_integration_test
93
94
def test_timeout_and_threaded_timeout_enabled_kills (monkeypatch ):
94
95
monkeypatch .setenv ("CLOUD_RUN_TIMEOUT_SECONDS" , "1" )
95
96
monkeypatch .setenv ("THREADED_TIMEOUT_ENABLED" , "true" )
@@ -111,7 +112,7 @@ def test_timeout_and_threaded_timeout_enabled_kills(monkeypatch):
111
112
112
113
result = requests .get ("http://{}:{}/" .format (TEST_HOST , TEST_PORT ))
113
114
114
- gunicorn_p .kill ()
115
+ gunicorn_p .terminate ()
115
116
gunicorn_p .join ()
116
117
117
118
# Any exception raised in execution is a 500 error. Cloud Functions 1st gen and
@@ -121,6 +122,7 @@ def test_timeout_and_threaded_timeout_enabled_kills(monkeypatch):
121
122
assert result .status_code == 500
122
123
123
124
125
+ @pytest .mark .slow_integration_test
124
126
def test_timeout_and_threaded_timeout_enabled_but_timeout_not_exceeded_doesnt_kill (
125
127
monkeypatch ,
126
128
):
@@ -144,7 +146,7 @@ def test_timeout_and_threaded_timeout_enabled_but_timeout_not_exceeded_doesnt_ki
144
146
145
147
result = requests .get ("http://{}:{}/" .format (TEST_HOST , TEST_PORT ))
146
148
147
- gunicorn_p .kill ()
149
+ gunicorn_p .terminate ()
148
150
gunicorn_p .join ()
149
151
150
152
assert result .status_code == 200
0 commit comments