Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
python-spectrometer
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
External wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
qutech
python-spectrometer
Commits
2a67041a
Verified
Commit
2a67041a
authored
2 months ago
by
Tobias Hangleiter
Browse files
Options
Downloads
Patches
Plain Diff
Fix flaky tests on CI
parent
1de03da4
No related branches found
No related tags found
1 merge request
!65
Fix flaky live view tests on CI
Checking pipeline status
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
tests/test_live_view.py
+45
-37
45 additions, 37 deletions
tests/test_live_view.py
with
45 additions
and
37 deletions
tests/test_live_view.py
+
45
−
37
View file @
2a67041a
...
@@ -35,17 +35,43 @@ def advance_frames(view: LiveViewT, n_frames: int):
...
@@ -35,17 +35,43 @@ def advance_frames(view: LiveViewT, n_frames: int):
view
.
fig
.
canvas
.
flush_events
()
view
.
fig
.
canvas
.
flush_events
()
def
stop_view
(
view
):
def
advance_until_stopped
(
*
views
):
to_advance
=
list
(
views
)
while
to_advance
:
for
view
in
to_advance
:
try
:
advance_frames
(
view
,
1
)
except
AttributeError
:
# event_source has been removed, meaning the animation was stopped
to_advance
.
remove
(
view
)
except
RuntimeError
:
# thread did not join
continue
def
stop_view
(
*
views
):
if
len
(
views
)
!=
1
:
# need to hack a bit to get the linked views to stop
views
[
0
].
stop_event
.
set
()
advance_until_stopped
(
*
views
)
try
:
try
:
view
.
stop
()
views
[
0
].
stop
()
except
RuntimeError
:
except
AttributeError
:
# Thread did not join. Try to trigger event loop once.
# ???
advance_frames
(
view
,
1
)
views
[
0
].
stop
()
view
.
stop
()
def
close_figure
(
fig
):
def
close_view
(
*
views
,
in_process
=
False
):
if
not
is_using_mpl_gui_backend
(
fig
):
if
in_process
:
views
[
0
].
close_event
.
set
()
# Give the process time to process all events
time
.
sleep
(
250e-3
)
return
stop_view
(
*
views
)
if
not
is_using_mpl_gui_backend
(
fig
:
=
views
[
0
].
fig
):
# Need to manually trigger the close event because the event loop isn't running
# Need to manually trigger the close event because the event loop isn't running
fig
.
canvas
.
callbacks
.
process
(
'
close_event
'
,
CloseEvent
(
'
close_event
'
,
fig
.
canvas
))
fig
.
canvas
.
callbacks
.
process
(
'
close_event
'
,
CloseEvent
(
'
close_event
'
,
fig
.
canvas
))
...
@@ -89,7 +115,7 @@ def started(spectrometer, plot_timetrace, in_process, in_gitlab_ci):
...
@@ -89,7 +115,7 @@ def started(spectrometer, plot_timetrace, in_process, in_gitlab_ci):
if
not
in_process
:
if
not
in_process
:
for
view
in
views
:
for
view
in
views
:
start_animation
(
view
.
fig
)
start_animation
(
view
.
fig
)
advance_frames
(
view
,
random
.
randint
(
1
,
1
0
))
advance_frames
(
view
,
random
.
randint
(
1
0
,
2
0
))
with
misc
.
timeout
(
30
,
raise_exc
=
True
)
as
exceeded
:
with
misc
.
timeout
(
30
,
raise_exc
=
True
)
as
exceeded
:
while
not
all
(
view
.
is_running
()
for
view
in
views
)
and
not
exceeded
:
while
not
all
(
view
.
is_running
()
for
view
in
views
)
and
not
exceeded
:
...
@@ -97,43 +123,25 @@ def started(spectrometer, plot_timetrace, in_process, in_gitlab_ci):
...
@@ -97,43 +123,25 @@ def started(spectrometer, plot_timetrace, in_process, in_gitlab_ci):
yield
views
yield
views
for
view
in
views
:
stop_view
(
*
views
)
view
.
stop
()
close_view
(
*
views
,
in_process
=
in_process
)
if
in_process
:
if
in_process
:
for
view
in
views
:
view
.
process
.
terminate
()
view
.
process
.
terminate
()
else
:
close_figure
(
view
.
fig
)
@pytest.fixture
@pytest.fixture
def
stopped
(
started
:
list
[
LiveViewT
],
in_process
:
bool
):
def
stopped
(
started
:
list
[
LiveViewT
],
in_process
:
bool
):
view
=
random
.
choice
(
started
)
random
.
shuffle
(
views
:
=
started
)
stop_view
(
view
)
stop_view
(
*
views
)
return
views
if
not
in_process
and
len
(
started
)
>
1
:
advance_frames
(
started
[
1
-
started
.
index
(
view
)],
1
)
stopped
=
started
return
stopped
@pytest.fixture
@pytest.fixture
def
closed
(
started
:
list
[
LiveViewT
],
in_process
:
bool
):
def
closed
(
started
:
list
[
LiveViewT
],
in_process
:
bool
):
view
=
random
.
choice
(
started
)
random
.
shuffle
(
views
:
=
started
)
close_view
(
*
views
,
in_process
=
in_process
)
if
in_process
:
yield
views
view
.
close_event
.
set
()
else
:
close_figure
(
view
.
fig
)
if
not
in_process
and
len
(
started
)
>
1
:
advance_frames
(
started
[
1
-
started
.
index
(
view
)],
1
)
else
:
# Give the process time to process all events
time
.
sleep
(
250e-3
)
closed
=
started
yield
closed
def
test_started
(
spectrometer
,
started
,
plot_timetrace
,
in_process
):
def
test_started
(
spectrometer
,
started
,
plot_timetrace
,
in_process
):
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment