Skip to content

Commit 785976d

Browse files
committed
Merge branch '1.x' into majorgreys/ci-pin-importlib
2 parents 9a00bfa + 91c4278 commit 785976d

5 files changed

+42
-15
lines changed

riotfile.py

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1833,9 +1833,29 @@ def select_pys(min_version=MIN_PYTHON_VERSION, max_version=MAX_PYTHON_VERSION):
18331833
"sanic": [
18341834
"~=21.9.0",
18351835
"~=21.12.0",
1836-
"==22.6.2",
18371836
],
1838-
"sanic-testing": ["<=22.6.0"],
1837+
"sanic-testing": "~=0.8.3",
1838+
},
1839+
),
1840+
Venv(
1841+
pys=select_pys(min_version="3.7"),
1842+
pkgs={
1843+
"sanic": "~=22.3.0",
1844+
"sanic-testing": "~=22.3.0",
1845+
},
1846+
),
1847+
Venv(
1848+
pys=select_pys(min_version="3.7"),
1849+
pkgs={
1850+
"sanic": "~=22.9.0",
1851+
"sanic-testing": "~=22.9.0",
1852+
},
1853+
),
1854+
Venv(
1855+
pys=select_pys(min_version="3.7"),
1856+
pkgs={
1857+
"sanic": latest,
1858+
"sanic-testing": latest,
18391859
},
18401860
),
18411861
],

tests/contrib/sanic/run_server.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,10 @@
1919
app = Sanic("test_sanic_server")
2020

2121

22-
@tracer.wrap()
22+
# Depending on the version of sanic the application can be run in a child process.
23+
# This can alter the name of the function and the default span name. Setting the span name to
24+
# `random_sleep` ensures the snapshot tests produce consistent spans across sanic versions.
25+
@tracer.wrap("random_sleep")
2326
async def random_sleep():
2427
await asyncio.sleep(random.random() * 0.1)
2528

@@ -41,4 +44,5 @@ async def shutdown_tracer(request):
4144
return json({"success": True})
4245

4346

44-
app.run(host="0.0.0.0", port=os.environ["SANIC_PORT"], access_log=False)
47+
if __name__ == "__main__":
48+
app.run(host="0.0.0.0", port=int(os.environ["SANIC_PORT"]), access_log=False)

tests/contrib/sanic/test_sanic_server.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import os
2+
import signal
23
import subprocess
34

45
import pytest
@@ -19,16 +20,18 @@ def sanic_client():
1920
env = os.environ.copy()
2021
env["SANIC_PORT"] = str(SERVER_PORT)
2122
args = ["ddtrace-run", "python", RUN_SERVER_PY]
22-
subp = subprocess.Popen(args, stdout=subprocess.PIPE, stderr=subprocess.PIPE, close_fds=True, env=env)
23-
23+
subp = subprocess.Popen(
24+
args, stdout=subprocess.PIPE, stderr=subprocess.PIPE, close_fds=True, env=env, preexec_fn=os.setsid
25+
)
2426
client = Client("http://0.0.0.0:{}".format(SERVER_PORT))
2527
client.wait(path="/hello")
2628
try:
2729
yield client
2830
finally:
2931
resp = client.get_ignored("/shutdown-tracer")
3032
assert resp.status_code == 200
31-
subp.terminate()
33+
# sanic server can spawn child processes, ensure child process are killed
34+
os.killpg(os.getpgid(subp.pid), signal.SIGTERM)
3235
try:
3336
# Give the server 3 seconds to shutdown, then kill it
3437
subp.wait(3)

tests/snapshots/tests.contrib.sanic.test_sanic_server.test_multiple_requests_sanic_http.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@
2727
"start": 1643465627712966000
2828
},
2929
{
30-
"name": "__main__.random_sleep",
30+
"name": "random_sleep",
3131
"service": "sanic",
32-
"resource": "__main__.random_sleep",
32+
"resource": "random_sleep",
3333
"trace_id": 0,
3434
"span_id": 2,
3535
"parent_id": 1,
@@ -65,9 +65,9 @@
6565
"start": 1643465627811584000
6666
},
6767
{
68-
"name": "__main__.random_sleep",
68+
"name": "random_sleep",
6969
"service": "sanic",
70-
"resource": "__main__.random_sleep",
70+
"resource": "random_sleep",
7171
"trace_id": 1,
7272
"span_id": 2,
7373
"parent_id": 1,

tests/snapshots/tests.contrib.sanic.test_sanic_server.test_multiple_requests_sanic_http_pre_21.9.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@
2626
"start": 1643465607624457000
2727
},
2828
{
29-
"name": "__main__.random_sleep",
29+
"name": "random_sleep",
3030
"service": "sanic",
31-
"resource": "__main__.random_sleep",
31+
"resource": "random_sleep",
3232
"trace_id": 0,
3333
"span_id": 2,
3434
"parent_id": 1,
@@ -63,9 +63,9 @@
6363
"start": 1643465607721195000
6464
},
6565
{
66-
"name": "__main__.random_sleep",
66+
"name": "random_sleep",
6767
"service": "sanic",
68-
"resource": "__main__.random_sleep",
68+
"resource": "random_sleep",
6969
"trace_id": 1,
7070
"span_id": 2,
7171
"parent_id": 1,

0 commit comments

Comments
 (0)