-
-
Notifications
You must be signed in to change notification settings - Fork 92
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add tests for granian lock on windows platform using multiple workers
- Loading branch information
Showing
2 changed files
with
32 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import httpx | ||
import pytest | ||
from concurrent.futures import ProcessPoolExecutor | ||
import asyncio | ||
|
||
def make_req(port): | ||
return httpx.post(f"http://localhost:{port}/echo", data="test") | ||
|
||
@pytest.mark.asyncio | ||
@pytest.mark.parametrize("threading_mode", ["runtime", "workers"]) | ||
@pytest.mark.parametrize("server_mode", ["wsgi", "asgi", "rsgi"]) | ||
async def test_lock(wsgi_server, asgi_server, rsgi_server, threading_mode, server_mode): | ||
server = {"wsgi": wsgi_server, | ||
"asgi": asgi_server, | ||
"rsgi": rsgi_server, | ||
}[server_mode] | ||
async with server(threading_mode, workers=2) as port: | ||
with ProcessPoolExecutor() as executor: | ||
for _ in range(100): | ||
futures = [executor.submit(make_req, port) for _ in range(3)] | ||
ok = 0 | ||
timeout = 0 | ||
for future in futures: | ||
try: | ||
res = await asyncio.wrap_future(future) | ||
assert res.status_code == 200 | ||
ok += 1 | ||
except httpx.ReadTimeout: | ||
timeout += 1 | ||
assert (timeout, ok) == (0, 3) |