This repository was archived by the owner on Jun 4, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 33
/
Copy pathtest_race_conditions.py
84 lines (68 loc) · 2.11 KB
/
test_race_conditions.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
import itertools
import time
import flask
from dash import Dash
from dash.dependencies import Input, Output, State, Event
import dash
import dash_html_components as html
import dash_core_components as dcc
from .IntegrationTests import IntegrationTests
from .utils import assert_clean_console, wait_for
class Tests(IntegrationTests):
def setUp(self):
pass
DELAY_TIME = 1
def create_race_conditions_test(endpoints):
def test(self):
app = Dash()
app.layout = html.Div([
html.Div('Hello world', id='output'),
dcc.Input(id='input', value='initial value')
])
app.scripts.config.serve_locally = True
@app.callback(
Output('output', 'children'),
[Input('input', 'value')])
def update(value):
return value
def delay():
for i, route in enumerate(endpoints):
if route in flask.request.path:
time.sleep((DELAY_TIME * i) + DELAY_TIME)
def element_text(id):
try:
return self.driver.find_element_by_id(id).text
except:
return ''
app.server.before_request(delay)
self.startServer(app)
total_delay = 0
for i in routes:
total_delay += DELAY_TIME*2 + DELAY_TIME
time.sleep(total_delay + DELAY_TIME)
wait_for(
lambda: element_text('output') == 'initial value',
lambda: '"{}" != "initial value"\nbody text: {}'.format(
element_text('output'),
element_text('react-entry-point')
)
)
assert_clean_console(self)
return test
routes = [
'layout',
'dependencies',
'update-component',
'_config'
# routes and component-suites
# are other endpoints but are excluded to speed up tests
]
for route_list in itertools.permutations(routes, len(routes)):
setattr(
Tests,
'test_delayed_{}'.format(
'_'.join([
r.replace('-', '_') for r in route_list
])),
create_race_conditions_test(route_list)
)