v3
Browse files
gradio-web/test/test_queue_session_limit_e2e.py
CHANGED
|
@@ -87,6 +87,15 @@ def _read_progress_text(page) -> str | None:
|
|
| 87 |
)
|
| 88 |
|
| 89 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 90 |
def _read_progress_overlay_snapshot(page) -> dict[str, float | bool | None]:
|
| 91 |
return page.evaluate(
|
| 92 |
"""() => {
|
|
@@ -111,13 +120,24 @@ def _read_session_wait_overlay_snapshot(page) -> dict[str, float | bool | None]:
|
|
| 111 |
"""() => {
|
| 112 |
const host = document.getElementById('native_progress_host');
|
| 113 |
if (!host) {
|
| 114 |
-
return {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 115 |
}
|
| 116 |
const markdown = host.querySelector('[data-testid="markdown"]');
|
| 117 |
const prose = markdown ? markdown.querySelector('.prose, .md') || markdown : null;
|
| 118 |
const text = prose ? ((prose.innerText || prose.textContent || '').trim()) : '';
|
| 119 |
const rect = host.getBoundingClientRect();
|
| 120 |
const style = getComputedStyle(host);
|
|
|
|
| 121 |
return {
|
| 122 |
present: true,
|
| 123 |
visible: style.display !== 'none' && rect.width > 0 && rect.height > 0 && text.length > 0,
|
|
@@ -125,6 +145,9 @@ def _read_session_wait_overlay_snapshot(page) -> dict[str, float | bool | None]:
|
|
| 125 |
height: rect.height,
|
| 126 |
background: style.backgroundColor || null,
|
| 127 |
content: text || null,
|
|
|
|
|
|
|
|
|
|
| 128 |
};
|
| 129 |
}"""
|
| 130 |
)
|
|
@@ -189,7 +212,7 @@ def test_gradio_queue_respects_configured_limit_on_init_load(monkeypatch):
|
|
| 189 |
time.sleep(0.25)
|
| 190 |
|
| 191 |
def _queue_snapshot_ready():
|
| 192 |
-
progress_texts = [
|
| 193 |
processing_ready = all(
|
| 194 |
text and config.UI_TEXT["progress"]["episode_loading"] in text
|
| 195 |
for text in progress_texts[: config.SESSION_INIT_CONCURRENCY_LIMIT]
|
|
@@ -204,11 +227,11 @@ def test_gradio_queue_respects_configured_limit_on_init_load(monkeypatch):
|
|
| 204 |
|
| 205 |
_wait_until(_queue_snapshot_ready, timeout_s=10.0)
|
| 206 |
processing_pages = [
|
| 207 |
-
|
| 208 |
for page in pages[: config.SESSION_INIT_CONCURRENCY_LIMIT]
|
| 209 |
]
|
| 210 |
queued_pages = [
|
| 211 |
-
|
| 212 |
for page in pages[config.SESSION_INIT_CONCURRENCY_LIMIT :]
|
| 213 |
]
|
| 214 |
|
|
@@ -223,6 +246,8 @@ def test_gradio_queue_respects_configured_limit_on_init_load(monkeypatch):
|
|
| 223 |
assert overlay_snapshot["width"] and overlay_snapshot["width"] > 0
|
| 224 |
assert overlay_snapshot["height"] and overlay_snapshot["height"] >= 400
|
| 225 |
assert overlay_snapshot["background"] == "rgba(255, 255, 255, 0.92)"
|
|
|
|
|
|
|
| 226 |
|
| 227 |
_wait_until(lambda: _read_progress_text(pages[0]) is None, timeout_s=15.0)
|
| 228 |
_wait_until(lambda: _read_progress_text(pages[-1]) is None, timeout_s=25.0)
|
|
@@ -483,6 +508,11 @@ def test_late_user_waits_for_active_session_slot_release(monkeypatch):
|
|
| 483 |
assert len(state_manager.GLOBAL_SESSIONS) == config.SESSION_CONCURRENCY_LIMIT
|
| 484 |
assert len(state_manager.ACTIVE_SESSION_SLOTS) == config.SESSION_CONCURRENCY_LIMIT
|
| 485 |
assert _read_session_wait_overlay_snapshot(page3)["visible"] is True
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 486 |
|
| 487 |
page1.close()
|
| 488 |
|
|
@@ -579,6 +609,10 @@ def test_second_and_later_late_users_show_queue_overlay(monkeypatch):
|
|
| 579 |
assert overlay_snapshot["width"] and overlay_snapshot["width"] > 0
|
| 580 |
assert overlay_snapshot["height"] and overlay_snapshot["height"] >= 400
|
| 581 |
assert config.UI_TEXT["progress"]["queue_wait"] in str(overlay_snapshot["content"] or "")
|
|
|
|
|
|
|
|
|
|
|
|
|
| 582 |
|
| 583 |
browser.close()
|
| 584 |
finally:
|
|
|
|
| 87 |
)
|
| 88 |
|
| 89 |
|
| 90 |
+
def _read_unified_overlay_text(page) -> str | None:
|
| 91 |
+
progress_text = _read_progress_text(page)
|
| 92 |
+
if progress_text:
|
| 93 |
+
return progress_text
|
| 94 |
+
snapshot = _read_session_wait_overlay_snapshot(page)
|
| 95 |
+
content = snapshot.get("content")
|
| 96 |
+
return str(content).strip() if content else None
|
| 97 |
+
|
| 98 |
+
|
| 99 |
def _read_progress_overlay_snapshot(page) -> dict[str, float | bool | None]:
|
| 100 |
return page.evaluate(
|
| 101 |
"""() => {
|
|
|
|
| 120 |
"""() => {
|
| 121 |
const host = document.getElementById('native_progress_host');
|
| 122 |
if (!host) {
|
| 123 |
+
return {
|
| 124 |
+
present: false,
|
| 125 |
+
visible: false,
|
| 126 |
+
width: null,
|
| 127 |
+
height: null,
|
| 128 |
+
background: null,
|
| 129 |
+
content: null,
|
| 130 |
+
proseBackground: null,
|
| 131 |
+
proseBorderRadius: null,
|
| 132 |
+
proseBoxShadow: null,
|
| 133 |
+
};
|
| 134 |
}
|
| 135 |
const markdown = host.querySelector('[data-testid="markdown"]');
|
| 136 |
const prose = markdown ? markdown.querySelector('.prose, .md') || markdown : null;
|
| 137 |
const text = prose ? ((prose.innerText || prose.textContent || '').trim()) : '';
|
| 138 |
const rect = host.getBoundingClientRect();
|
| 139 |
const style = getComputedStyle(host);
|
| 140 |
+
const proseStyle = prose ? getComputedStyle(prose) : null;
|
| 141 |
return {
|
| 142 |
present: true,
|
| 143 |
visible: style.display !== 'none' && rect.width > 0 && rect.height > 0 && text.length > 0,
|
|
|
|
| 145 |
height: rect.height,
|
| 146 |
background: style.backgroundColor || null,
|
| 147 |
content: text || null,
|
| 148 |
+
proseBackground: proseStyle ? proseStyle.backgroundColor || null : null,
|
| 149 |
+
proseBorderRadius: proseStyle ? proseStyle.borderRadius || null : null,
|
| 150 |
+
proseBoxShadow: proseStyle ? proseStyle.boxShadow || null : null,
|
| 151 |
};
|
| 152 |
}"""
|
| 153 |
)
|
|
|
|
| 212 |
time.sleep(0.25)
|
| 213 |
|
| 214 |
def _queue_snapshot_ready():
|
| 215 |
+
progress_texts = [_read_unified_overlay_text(page) for page in pages]
|
| 216 |
processing_ready = all(
|
| 217 |
text and config.UI_TEXT["progress"]["episode_loading"] in text
|
| 218 |
for text in progress_texts[: config.SESSION_INIT_CONCURRENCY_LIMIT]
|
|
|
|
| 227 |
|
| 228 |
_wait_until(_queue_snapshot_ready, timeout_s=10.0)
|
| 229 |
processing_pages = [
|
| 230 |
+
_read_unified_overlay_text(page) or ""
|
| 231 |
for page in pages[: config.SESSION_INIT_CONCURRENCY_LIMIT]
|
| 232 |
]
|
| 233 |
queued_pages = [
|
| 234 |
+
_read_unified_overlay_text(page) or ""
|
| 235 |
for page in pages[config.SESSION_INIT_CONCURRENCY_LIMIT :]
|
| 236 |
]
|
| 237 |
|
|
|
|
| 246 |
assert overlay_snapshot["width"] and overlay_snapshot["width"] > 0
|
| 247 |
assert overlay_snapshot["height"] and overlay_snapshot["height"] >= 400
|
| 248 |
assert overlay_snapshot["background"] == "rgba(255, 255, 255, 0.92)"
|
| 249 |
+
session_wait_snapshot = _read_session_wait_overlay_snapshot(pages[-1])
|
| 250 |
+
assert session_wait_snapshot["content"] in (None, "")
|
| 251 |
|
| 252 |
_wait_until(lambda: _read_progress_text(pages[0]) is None, timeout_s=15.0)
|
| 253 |
_wait_until(lambda: _read_progress_text(pages[-1]) is None, timeout_s=25.0)
|
|
|
|
| 508 |
assert len(state_manager.GLOBAL_SESSIONS) == config.SESSION_CONCURRENCY_LIMIT
|
| 509 |
assert len(state_manager.ACTIVE_SESSION_SLOTS) == config.SESSION_CONCURRENCY_LIMIT
|
| 510 |
assert _read_session_wait_overlay_snapshot(page3)["visible"] is True
|
| 511 |
+
wait_snapshot = _read_session_wait_overlay_snapshot(page3)
|
| 512 |
+
assert wait_snapshot["content"] == f'{config.UI_TEXT["progress"]["queue_wait"]} | queue: 1'
|
| 513 |
+
assert wait_snapshot["proseBackground"] == "rgba(0, 0, 0, 0)"
|
| 514 |
+
assert wait_snapshot["proseBorderRadius"] == "0px"
|
| 515 |
+
assert wait_snapshot["proseBoxShadow"] == "none"
|
| 516 |
|
| 517 |
page1.close()
|
| 518 |
|
|
|
|
| 609 |
assert overlay_snapshot["width"] and overlay_snapshot["width"] > 0
|
| 610 |
assert overlay_snapshot["height"] and overlay_snapshot["height"] >= 400
|
| 611 |
assert config.UI_TEXT["progress"]["queue_wait"] in str(overlay_snapshot["content"] or "")
|
| 612 |
+
assert "queue:" in str(overlay_snapshot["content"] or "").lower()
|
| 613 |
+
assert overlay_snapshot["proseBackground"] == "rgba(0, 0, 0, 0)"
|
| 614 |
+
assert overlay_snapshot["proseBorderRadius"] == "0px"
|
| 615 |
+
assert overlay_snapshot["proseBoxShadow"] == "none"
|
| 616 |
|
| 617 |
browser.close()
|
| 618 |
finally:
|
gradio-web/ui_layout.py
CHANGED
|
@@ -405,67 +405,11 @@ PROGRESS_TEXT_REWRITE_JS = f"""
|
|
| 405 |
wrap.style.setProperty("background", "rgba(255, 255, 255, 0.92)", "important");
|
| 406 |
wrap.style.setProperty("backdrop-filter", "blur(2px)", "important");
|
| 407 |
}}
|
| 408 |
-
}};
|
| 409 |
-
|
| 410 |
-
const resetManualOverlayStyles = (host, markdown, prose) => {{
|
| 411 |
-
host.style.setProperty("pointer-events", "none", "important");
|
| 412 |
-
if (markdown instanceof HTMLElement) {{
|
| 413 |
-
[
|
| 414 |
-
"position",
|
| 415 |
-
"inset",
|
| 416 |
-
"display",
|
| 417 |
-
"align-items",
|
| 418 |
-
"justify-content",
|
| 419 |
-
"padding",
|
| 420 |
-
].forEach((prop) => markdown.style.removeProperty(prop));
|
| 421 |
-
}}
|
| 422 |
-
if (prose instanceof HTMLElement) {{
|
| 423 |
-
[
|
| 424 |
-
"min-width",
|
| 425 |
-
"max-width",
|
| 426 |
-
"margin",
|
| 427 |
-
"padding",
|
| 428 |
-
"border-radius",
|
| 429 |
-
"background",
|
| 430 |
-
"border",
|
| 431 |
-
"box-shadow",
|
| 432 |
-
"text-align",
|
| 433 |
-
"color",
|
| 434 |
-
"font-size",
|
| 435 |
-
"font-weight",
|
| 436 |
-
"line-height",
|
| 437 |
-
"white-space",
|
| 438 |
-
].forEach((prop) => prose.style.removeProperty(prop));
|
| 439 |
-
}}
|
| 440 |
-
}};
|
| 441 |
-
|
| 442 |
-
const updateManualWaitOverlay = () => {{
|
| 443 |
-
const host = document.getElementById("native_progress_host");
|
| 444 |
-
if (!(host instanceof HTMLElement)) {{
|
| 445 |
-
return;
|
| 446 |
-
}}
|
| 447 |
-
|
| 448 |
const markdown = host.querySelector('[data-testid="markdown"]');
|
| 449 |
const prose =
|
| 450 |
markdown instanceof HTMLElement
|
| 451 |
? markdown.querySelector(".prose, .md") || markdown
|
| 452 |
: null;
|
| 453 |
-
const progressNode = host.querySelector(".progress-text");
|
| 454 |
-
const text =
|
| 455 |
-
prose instanceof HTMLElement
|
| 456 |
-
? (prose.innerText || prose.textContent || "").trim()
|
| 457 |
-
: "";
|
| 458 |
-
const manualVisible =
|
| 459 |
-
Boolean(text) &&
|
| 460 |
-
!progressNode &&
|
| 461 |
-
text.toLowerCase().includes(queueWaitText.toLowerCase());
|
| 462 |
-
|
| 463 |
-
if (!manualVisible) {{
|
| 464 |
-
resetManualOverlayStyles(host, markdown, prose);
|
| 465 |
-
return;
|
| 466 |
-
}}
|
| 467 |
-
|
| 468 |
-
host.style.setProperty("pointer-events", "auto", "important");
|
| 469 |
if (markdown instanceof HTMLElement) {{
|
| 470 |
markdown.style.setProperty("position", "fixed", "important");
|
| 471 |
markdown.style.setProperty("inset", "0", "important");
|
|
@@ -475,14 +419,10 @@ PROGRESS_TEXT_REWRITE_JS = f"""
|
|
| 475 |
markdown.style.setProperty("padding", "24px", "important");
|
| 476 |
}}
|
| 477 |
if (prose instanceof HTMLElement) {{
|
| 478 |
-
prose.style.setProperty("
|
| 479 |
prose.style.setProperty("max-width", "calc(100vw - 48px)", "important");
|
| 480 |
prose.style.setProperty("margin", "0", "important");
|
| 481 |
-
prose.style.setProperty("padding", "
|
| 482 |
-
prose.style.setProperty("border-radius", "16px", "important");
|
| 483 |
-
prose.style.setProperty("background", "rgba(255, 255, 255, 0.96)", "important");
|
| 484 |
-
prose.style.setProperty("border", "1px solid rgba(15, 23, 42, 0.08)", "important");
|
| 485 |
-
prose.style.setProperty("box-shadow", "0 24px 60px rgba(15, 23, 42, 0.14)", "important");
|
| 486 |
prose.style.setProperty("text-align", "center", "important");
|
| 487 |
prose.style.setProperty("color", "#0f172a", "important");
|
| 488 |
prose.style.setProperty("font-size", "var(--text-lg)", "important");
|
|
@@ -550,7 +490,6 @@ PROGRESS_TEXT_REWRITE_JS = f"""
|
|
| 550 |
const rewriteAll = () => {{
|
| 551 |
ensureOverlayStyles();
|
| 552 |
document.querySelectorAll(".progress-text").forEach(rewriteNode);
|
| 553 |
-
updateManualWaitOverlay();
|
| 554 |
}};
|
| 555 |
|
| 556 |
const scheduleRewrite = () => {{
|
|
@@ -1015,7 +954,7 @@ def create_ui_blocks():
|
|
| 1015 |
return tuple(gr.skip() for _ in range(len(load_flow_outputs)))
|
| 1016 |
|
| 1017 |
def _pending_init_flow(uid, queue_position):
|
| 1018 |
-
|
| 1019 |
return (
|
| 1020 |
uid,
|
| 1021 |
gr.update(visible=True),
|
|
@@ -1038,7 +977,7 @@ def create_ui_blocks():
|
|
| 1038 |
gr.update(interactive=False),
|
| 1039 |
PHASE_INIT,
|
| 1040 |
True,
|
| 1041 |
-
gr.update(value=f'{UI_TEXT["progress"]["queue_wait"]}
|
| 1042 |
gr.update(active=True),
|
| 1043 |
)
|
| 1044 |
|
|
|
|
| 405 |
wrap.style.setProperty("background", "rgba(255, 255, 255, 0.92)", "important");
|
| 406 |
wrap.style.setProperty("backdrop-filter", "blur(2px)", "important");
|
| 407 |
}}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 408 |
const markdown = host.querySelector('[data-testid="markdown"]');
|
| 409 |
const prose =
|
| 410 |
markdown instanceof HTMLElement
|
| 411 |
? markdown.querySelector(".prose, .md") || markdown
|
| 412 |
: null;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 413 |
if (markdown instanceof HTMLElement) {{
|
| 414 |
markdown.style.setProperty("position", "fixed", "important");
|
| 415 |
markdown.style.setProperty("inset", "0", "important");
|
|
|
|
| 419 |
markdown.style.setProperty("padding", "24px", "important");
|
| 420 |
}}
|
| 421 |
if (prose instanceof HTMLElement) {{
|
| 422 |
+
prose.style.setProperty("width", "min(720px, calc(100vw - 48px))", "important");
|
| 423 |
prose.style.setProperty("max-width", "calc(100vw - 48px)", "important");
|
| 424 |
prose.style.setProperty("margin", "0", "important");
|
| 425 |
+
prose.style.setProperty("padding", "0", "important");
|
|
|
|
|
|
|
|
|
|
|
|
|
| 426 |
prose.style.setProperty("text-align", "center", "important");
|
| 427 |
prose.style.setProperty("color", "#0f172a", "important");
|
| 428 |
prose.style.setProperty("font-size", "var(--text-lg)", "important");
|
|
|
|
| 490 |
const rewriteAll = () => {{
|
| 491 |
ensureOverlayStyles();
|
| 492 |
document.querySelectorAll(".progress-text").forEach(rewriteNode);
|
|
|
|
| 493 |
}};
|
| 494 |
|
| 495 |
const scheduleRewrite = () => {{
|
|
|
|
| 954 |
return tuple(gr.skip() for _ in range(len(load_flow_outputs)))
|
| 955 |
|
| 956 |
def _pending_init_flow(uid, queue_position):
|
| 957 |
+
queue_label = f'queue: {max(1, int(queue_position or 1))}'
|
| 958 |
return (
|
| 959 |
uid,
|
| 960 |
gr.update(visible=True),
|
|
|
|
| 977 |
gr.update(interactive=False),
|
| 978 |
PHASE_INIT,
|
| 979 |
True,
|
| 980 |
+
gr.update(value=f'{UI_TEXT["progress"]["queue_wait"]} | {queue_label}'),
|
| 981 |
gr.update(active=True),
|
| 982 |
)
|
| 983 |
|