Skip to content

Commit b9a07a0

Browse files
committed
Add test page cancel.
1 parent b5c1287 commit b9a07a0

File tree

2 files changed

+127
-0
lines changed

2 files changed

+127
-0
lines changed
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
from dash import Dash, Input, Output, dcc, html, page_container, register_page
2+
3+
import time
4+
5+
from tests.integration.long_callback.utils import get_long_callback_manager
6+
7+
long_callback_manager = get_long_callback_manager()
8+
handle = long_callback_manager.handle
9+
10+
11+
app = Dash(
12+
__name__,
13+
use_pages=True,
14+
pages_folder="",
15+
long_callback_manager=long_callback_manager,
16+
)
17+
18+
app.layout = html.Div(
19+
[
20+
dcc.Link("page1", "/"),
21+
dcc.Link("page2", "/2"),
22+
html.Button("Cancel", id="cancel"),
23+
page_container,
24+
]
25+
)
26+
27+
28+
register_page(
29+
"one",
30+
"/",
31+
layout=html.Div(
32+
[
33+
html.Button("start", id="start1"),
34+
html.Button("cancel1", id="cancel1"),
35+
html.Div("idle", id="progress1"),
36+
html.Div("initial", id="output1"),
37+
]
38+
),
39+
)
40+
register_page(
41+
"two",
42+
"/2",
43+
layout=html.Div(
44+
[
45+
html.Button("start2", id="start2"),
46+
html.Button("cancel2", id="cancel2"),
47+
html.Div("idle", id="progress2"),
48+
html.Div("initial", id="output2"),
49+
]
50+
),
51+
)
52+
53+
54+
@app.callback(
55+
Output("output1", "children"),
56+
Input("start1", "n_clicks"),
57+
running=[
58+
(Output("progress1", "children"), "running", "idle"),
59+
],
60+
cancel=[
61+
Input("cancel1", "n_clicks"),
62+
Input("cancel", "n_clicks"),
63+
],
64+
background=True,
65+
prevent_initial_call=True,
66+
interval=300,
67+
)
68+
def on_click1(n_clicks):
69+
time.sleep(2)
70+
return f"Click {n_clicks}"
71+
72+
73+
@app.callback(
74+
Output("output2", "children"),
75+
Input("start2", "n_clicks"),
76+
running=[
77+
(Output("progress2", "children"), "running", "idle"),
78+
],
79+
cancel=[
80+
Input("cancel2", "n_clicks"),
81+
Input("cancel", "n_clicks"),
82+
],
83+
background=True,
84+
prevent_initial_call=True,
85+
interval=300,
86+
)
87+
def on_click1(n_clicks):
88+
time.sleep(2)
89+
return f"Click {n_clicks}"
90+
91+
92+
if __name__ == "__main__":
93+
app.run(debug=True)

tests/integration/long_callback/test_basic_long_callback.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -556,3 +556,37 @@ def test_lcbc015_diff_outputs_same_func(dash_duo, manager):
556556
for i in range(1, 3):
557557
dash_duo.find_element(f"#button-{i}").click()
558558
dash_duo.wait_for_text_to_equal(f"#output-{i}", f"Clicked on {i}")
559+
560+
561+
def test_lcbc016_multi_page_cancel(dash_duo, manager):
562+
with setup_long_callback_app(manager, "app_page_cancel") as app:
563+
dash_duo.start_server(app)
564+
dash_duo.find_element("#start1").click()
565+
dash_duo.wait_for_text_to_equal("#progress1", "running")
566+
dash_duo.find_element("#cancel").click()
567+
dash_duo.wait_for_text_to_equal("#progress1", "idle")
568+
time.sleep(2.1)
569+
dash_duo.wait_for_text_to_equal("#output1", "initial")
570+
571+
dash_duo.find_element("#start1").click()
572+
dash_duo.wait_for_text_to_equal("#progress1", "running")
573+
dash_duo.find_element("#cancel1").click()
574+
dash_duo.wait_for_text_to_equal("#progress1", "idle")
575+
time.sleep(2.1)
576+
dash_duo.wait_for_text_to_equal("#output1", "initial")
577+
578+
dash_duo.server_url = dash_duo.server_url + "/2"
579+
580+
dash_duo.find_element("#start2").click()
581+
dash_duo.wait_for_text_to_equal("#progress2", "running")
582+
dash_duo.find_element("#cancel").click()
583+
dash_duo.wait_for_text_to_equal("#progress2", "idle")
584+
time.sleep(2.1)
585+
dash_duo.wait_for_text_to_equal("#output2", "initial")
586+
587+
dash_duo.find_element("#start2").click()
588+
dash_duo.wait_for_text_to_equal("#progress2", "running")
589+
dash_duo.find_element("#cancel2").click()
590+
dash_duo.wait_for_text_to_equal("#progress2", "idle")
591+
time.sleep(2.1)
592+
dash_duo.wait_for_text_to_equal("#output2", "initial")

0 commit comments

Comments
 (0)