E2E test that Queue Full does not break the client. Also that backend exceptions don't break the client or queue. (#6812)

* Add test

* Dont launch new app lol

* Remove unused imports
This commit is contained in:
Freddy Boulton 2023-12-18 15:13:44 -05:00 committed by GitHub
parent f3abde8088
commit 992d540c3d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 68 additions and 0 deletions

View File

@ -0,0 +1 @@
{"cells": [{"cell_type": "markdown", "id": "302934307671667531413257853548643485645", "metadata": {}, "source": ["# Gradio Demo: queue_full_e2e_test"]}, {"cell_type": "code", "execution_count": null, "id": "272996653310673477252411125948039410165", "metadata": {}, "outputs": [], "source": ["!pip install -q gradio "]}, {"cell_type": "code", "execution_count": null, "id": "288918539441861185822528903084949547379", "metadata": {}, "outputs": [], "source": ["import gradio as gr\n", "import time\n", "import random\n", "\n", "n_calls = 0\n", "\n", "def get_random_number():\n", " global n_calls\n", " if n_calls == 1:\n", " n_calls += 1\n", " raise gr.Error(\"This is a gradio error\")\n", " n_calls += 1\n", " time.sleep(5)\n", " return random.randrange(1, 10)\n", "\n", "\n", "with gr.Blocks() as demo:\n", " with gr.Row():\n", " with gr.Column():\n", " first = gr.Button(\"First Call\")\n", " second = gr.Button(\"Second Call\")\n", " third = gr.Button(\"Third Call\")\n", " fourth = gr.Button(\"Fourth Call\")\n", " with gr.Column():\n", " first_o = gr.Number(label=\"First Result\")\n", " second_o = gr.Number(label=\"Second Result\")\n", " third_o = gr.Number(label=\"Third Result\")\n", " fourth_o = gr.Number(label=\"Fourth Result\")\n", " \n", " first.click(get_random_number, None, first_o, concurrency_id=\"f\")\n", " second.click(get_random_number, None, second_o, concurrency_id=\"f\")\n", " third.click(get_random_number, None, third_o, concurrency_id=\"f\")\n", " fourth.click(get_random_number, None, fourth_o, concurrency_id=\"f\")\n", "\n", "demo.queue(max_size=2)\n", "\n", "if __name__ == \"__main__\":\n", " demo.launch()\n"]}], "metadata": {}, "nbformat": 4, "nbformat_minor": 5}

View File

@ -0,0 +1,38 @@
import gradio as gr
import time
import random
n_calls = 0
def get_random_number():
global n_calls
if n_calls == 1:
n_calls += 1
raise gr.Error("This is a gradio error")
n_calls += 1
time.sleep(5)
return random.randrange(1, 10)
with gr.Blocks() as demo:
with gr.Row():
with gr.Column():
first = gr.Button("First Call")
second = gr.Button("Second Call")
third = gr.Button("Third Call")
fourth = gr.Button("Fourth Call")
with gr.Column():
first_o = gr.Number(label="First Result")
second_o = gr.Number(label="Second Result")
third_o = gr.Number(label="Third Result")
fourth_o = gr.Number(label="Fourth Result")
first.click(get_random_number, None, first_o, concurrency_id="f")
second.click(get_random_number, None, second_o, concurrency_id="f")
third.click(get_random_number, None, third_o, concurrency_id="f")
fourth.click(get_random_number, None, fourth_o, concurrency_id="f")
demo.queue(max_size=2)
if __name__ == "__main__":
demo.launch()

View File

@ -0,0 +1,29 @@
import { test, expect } from "@gradio/tootils";
test("When the queue is full the queue full message gets shown. Also when there is an exception in a user function the queue does not get blocked", async ({
page
}) => {
await page.pause();
await page.getByRole("button", { name: "First Call" }).click();
await page.getByRole("button", { name: "Second Call" }).click();
await page.getByRole("button", { name: "Third Call" }).click();
await page.getByRole("button", { name: "Fourth Call" }).click();
await expect(page.getByTestId("toast-body")).toHaveCount(2, {
timeout: 10000
});
const all_toast = (await page.getByTestId("toast-body").all()).map(
async (t) => await t.innerText()
);
const all_text = await Promise.all(all_toast);
expect(all_text.join("\n")).toContain("This is a gradio error");
expect(all_text.join("\n")).toContain("application is too busy");
await expect
.poll(async () => page.getByLabel("First Result").inputValue())
.toBeTruthy();
await expect
.poll(async () => page.getByLabel("First Result").inputValue())
.toBeTruthy();
});