Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lock on windows platform using multiple workers #74

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@


@asynccontextmanager
async def _server(interface, port, threading_mode, tls=False):
async def _server(interface, port, threading_mode, tls=False, workers=1):
certs_path = Path.cwd() / "tests" / "fixtures" / "tls"
tls_opts = (
f"--ssl-certificate {certs_path / 'cert.pem'} "
Expand All @@ -20,6 +20,7 @@ async def _server(interface, port, threading_mode, tls=False):
"".join([
f"granian --interface {interface} --port {port} ",
f"--threads 1 --threading-mode {threading_mode} ",
f"--workers {workers} ",
tls_opts,
f"tests.apps.{interface}:app"
]),
Expand Down
27 changes: 27 additions & 0 deletions tests/test_lock.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import httpx
import pytest
import asyncio

async def make_req(port):
async with httpx.AsyncClient() as client:
return await client.post(f"http://localhost:{port}/echo", content="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:
for _ in range(100):
ok = 0
timeout = 0
for res in await asyncio.gather(*[make_req(port) for _ in range(3)], return_exceptions=True):
if isinstance(res, Exception):
timeout += 1
else:
assert res.status_code == 200
ok += 1
assert (timeout, ok) == (0, 3)