Skip to content

Commit 08ef000

Browse files
authored
issue-4952 fix (GoogleCloudPlatform#11454)
1 parent 2ffb2ec commit 08ef000

1 file changed

Lines changed: 8 additions & 31 deletions

File tree

functions/helloworld/sample_http_test_integration.py

Lines changed: 8 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -14,42 +14,19 @@
1414

1515
# [START functions_http_integration_test]
1616
import os
17-
import subprocess
1817
import uuid
1918

20-
import requests
21-
from requests.packages.urllib3.util.retry import Retry
19+
from functions_framework import create_app
2220

2321

2422
def test_args():
2523
name = str(uuid.uuid4())
26-
port = os.getenv(
27-
"PORT", 8080
28-
) # Each functions framework instance needs a unique port
29-
30-
process = subprocess.Popen(
31-
["functions-framework", "--target", "hello_http", "--port", str(port)],
32-
cwd=os.path.dirname(__file__),
33-
stdout=subprocess.PIPE,
34-
)
35-
36-
# Send HTTP request simulating Pub/Sub message
37-
# (GCF translates Pub/Sub messages to HTTP requests internally)
38-
BASE_URL = f"http://localhost:{port}"
39-
40-
retry_policy = Retry(total=6, backoff_factor=1)
41-
retry_adapter = requests.adapters.HTTPAdapter(max_retries=retry_policy)
42-
43-
session = requests.Session()
44-
session.mount(BASE_URL, retry_adapter)
45-
46-
name = str(uuid.uuid4())
47-
res = session.post(BASE_URL, json={"name": name})
48-
assert res.text == f"Hello {name}!"
49-
50-
# Stop the functions framework process
51-
process.kill()
52-
process.wait()
53-
24+
target = "hello_http"
25+
source = os.path.join(os.path.dirname(__file__), "main.py")
26+
client = create_app(target, source).test_client()
27+
resp = client.post("/my_path", json={"name": name})
28+
assert resp.status_code == 200
29+
expected_response = f"Hello {name}!"
30+
assert resp.data.decode("utf-8") == expected_response
5431

5532
# [END functions_http_integration_test]

0 commit comments

Comments
 (0)