|
| 1 | +import itertools |
| 2 | +import time |
| 3 | +import flask |
| 4 | +import pytest |
| 5 | + |
| 6 | +import dash_html_components as html |
| 7 | +import dash_core_components as dcc |
| 8 | +from dash import Dash |
| 9 | +from dash.dependencies import Input, Output |
| 10 | + |
| 11 | + |
| 12 | +DELAY_TIME = 0.2 |
| 13 | + |
| 14 | +routes = [ |
| 15 | + "layout", |
| 16 | + "dependencies", |
| 17 | + "update-component", |
| 18 | + "_config" |
| 19 | + # routes and component-suites |
| 20 | + # are other endpoints but are excluded to speed up tests |
| 21 | +] |
| 22 | + |
| 23 | +permuted_strs = [ |
| 24 | + ','.join(endpoints) for endpoints in itertools.permutations(routes, len(routes)) |
| 25 | +] |
| 26 | + |
| 27 | + |
| 28 | +@pytest.mark.parametrize("permuted_str", permuted_strs) |
| 29 | +def test_rdrc001_race_conditions(dash_duo, permuted_str): |
| 30 | + endpoints = permuted_str.split(',') |
| 31 | + app = Dash(__name__) |
| 32 | + app.layout = html.Div( |
| 33 | + [ |
| 34 | + html.Div("Hello world", id="output"), |
| 35 | + dcc.Input(id="input", value="initial value"), |
| 36 | + ] |
| 37 | + ) |
| 38 | + |
| 39 | + @app.callback(Output("output", "children"), Input("input", "value")) |
| 40 | + def update(value): |
| 41 | + return value |
| 42 | + |
| 43 | + def delay(): |
| 44 | + for i, route in enumerate(endpoints): |
| 45 | + if route in flask.request.path: |
| 46 | + time.sleep((DELAY_TIME * i) + DELAY_TIME) |
| 47 | + |
| 48 | + app.server.before_request(delay) |
| 49 | + dash_duo.start_server(app) |
| 50 | + |
| 51 | + dash_duo.wait_for_text_to_equal( |
| 52 | + '#output', |
| 53 | + "initial value", |
| 54 | + timeout=DELAY_TIME * (len(endpoints) + 3) + 3 |
| 55 | + ) |
| 56 | + |
| 57 | + assert not dash_duo.get_logs() |
0 commit comments