-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Allow auth with using queue #2611
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
Changes from all commits
ed7f226
072a644
096b1e9
bb21d60
0579adc
509a9ff
6a3501e
4cd6291
6811c7e
5496677
21e0f5c
cb0ea86
29b3f7b
6f2d536
169200e
b7afc76
1bb1579
554c12b
09a6c37
eb4265c
507f3c3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -905,3 +905,74 @@ def test_queue_enabled_for_fn(): | |
| demo.queue() | ||
| assert demo.queue_enabled_for_fn(0) | ||
| assert demo.queue_enabled_for_fn(1) | ||
|
|
||
|
|
||
| @pytest.mark.asyncio | ||
| async def test_queue_when_using_auth(): | ||
| sleep_time = 1 | ||
|
|
||
| async def say_hello(name): | ||
| await asyncio.sleep(sleep_time) | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think we need to sleep for so long. The test takes quite a while to run right now.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it is 1 sec and 3 times now |
||
| return f"Hello {name}!" | ||
|
|
||
| with gr.Blocks() as demo: | ||
| _input = gr.Textbox() | ||
| _output = gr.Textbox() | ||
| button = gr.Button() | ||
| button.click(say_hello, _input, _output) | ||
| demo.queue() | ||
| app, _, _ = demo.launch(auth=("abc", "123"), prevent_thread_lock=True) | ||
| client = TestClient(app) | ||
|
|
||
| resp = client.post( | ||
| f"{demo.local_url}login", data={"username": "abc", "password": "123"} | ||
| ) | ||
| assert resp.ok | ||
| token = resp.cookies.get("access-token") | ||
| assert token | ||
|
|
||
| with pytest.raises(Exception) as e: | ||
| async with websockets.connect( | ||
| f"{demo.local_url.replace('http', 'ws')}queue/join", | ||
| ) as ws: | ||
| await ws.recv() | ||
| assert e.type == websockets.InvalidStatusCode | ||
|
|
||
| async def run_ws(_loop, _time, i): | ||
| async with websockets.connect( | ||
| f"{demo.local_url.replace('http', 'ws')}queue/join", | ||
| extra_headers={"Cookie": f"access-token={token}"}, | ||
| ) as ws: | ||
| while True: | ||
| try: | ||
| msg = json.loads(await ws.recv()) | ||
| except websockets.ConnectionClosedOK: | ||
| break | ||
| if msg["msg"] == "send_hash": | ||
| await ws.send( | ||
| json.dumps({"fn_index": 0, "session_hash": "enwpitpex2q"}) | ||
| ) | ||
| if msg["msg"] == "send_data": | ||
| await ws.send( | ||
| json.dumps( | ||
| { | ||
| "data": [str(i)], | ||
| "fn_index": 0, | ||
| "session_hash": "enwpitpex2q", | ||
| } | ||
| ) | ||
| ) | ||
| msg = json.loads(await ws.recv()) | ||
| assert msg["msg"] == "process_starts" | ||
| if msg["msg"] == "process_completed": | ||
| assert msg["success"] | ||
| assert msg["output"]["data"] == [f"Hello {i}!"] | ||
| assert _loop.time() > _time | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is not passing on our CI. I don't think we need to check the time. I think it would be sufficient to test that the output is correct. Might make sense to rewrite this loop so that the "name" is different for each event in the queue.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. "name" is different for each event in the queue is added now, time is checked as I think we need to ensure the queue is actually working |
||
| break | ||
|
|
||
| loop = asyncio.get_event_loop() | ||
| tm = loop.time() | ||
| group = asyncio.gather( | ||
| *[run_ws(loop, tm + sleep_time * (i + 1) - 0.3, i) for i in range(3)] | ||
| ) | ||
| await group | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How come we need this change?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the comments are removed here, it is changed to allow the initialization to run the queue background coros