Merge lp:~afrantzis/unity-system-compositor/fix-1473418-external-spinner-tests into lp:unity-system-compositor

Proposed by Alexandros Frantzis
Status: Merged
Approved by: Alexandros Frantzis
Approved revision: 225
Merged at revision: 233
Proposed branch: lp:~afrantzis/unity-system-compositor/fix-1473418-external-spinner-tests
Merge into: lp:unity-system-compositor
Diff against target: 158 lines (+95/-11)
4 files modified
tests/integration-tests/CMakeLists.txt (+1/-0)
tests/integration-tests/spin_wait.cpp (+39/-0)
tests/integration-tests/spin_wait.h (+39/-0)
tests/integration-tests/test_external_spinner.cpp (+16/-11)
To merge this branch: bzr merge lp:~afrantzis/unity-system-compositor/fix-1473418-external-spinner-tests
Reviewer Review Type Date Requested Status
Kevin DuBois (community) Approve
PS Jenkins bot (community) continuous-integration Approve
Review via email: mp+264411@code.launchpad.net

Commit message

Wait a bit for spinner process to appear in AnExternalSpinner tests

Description of the change

Wait a bit for spinner process to appear in AnExternalSpinner tests

To post a comment you must log in.
225. By Alexandros Frantzis

Add forgotten files

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Kevin DuBois (kdub) wrote :

lgtm

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'tests/integration-tests/CMakeLists.txt'
2--- tests/integration-tests/CMakeLists.txt 2015-04-07 13:36:48 +0000
3+++ tests/integration-tests/CMakeLists.txt 2015-07-10 12:10:34 +0000
4@@ -32,6 +32,7 @@
5 run_command.cpp
6 dbus_bus.cpp
7 dbus_client.cpp
8+ spin_wait.cpp
9 test_dbus_event_loop.cpp
10 test_unity_screen_service.cpp
11 test_external_spinner.cpp
12
13=== added file 'tests/integration-tests/spin_wait.cpp'
14--- tests/integration-tests/spin_wait.cpp 1970-01-01 00:00:00 +0000
15+++ tests/integration-tests/spin_wait.cpp 2015-07-10 12:10:34 +0000
16@@ -0,0 +1,39 @@
17+/*
18+ * Copyright © 2015 Canonical Ltd.
19+ *
20+ * This program is free software: you can redistribute it and/or modify it
21+ * under the terms of the GNU General Public License version 3,
22+ * as published by the Free Software Foundation.
23+ *
24+ * This program is distributed in the hope that it will be useful,
25+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
26+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27+ * GNU General Public License for more details.
28+ *
29+ * You should have received a copy of the GNU General Public License
30+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
31+ *
32+ * Authored by: Alexandros Frantzis <alexandros.frantzis@canonical.com>
33+ */
34+
35+#include "spin_wait.h"
36+
37+#include <thread>
38+
39+bool usc::test::spin_wait_for_condition_or_timeout(
40+ std::function<bool()> const& condition,
41+ std::chrono::milliseconds timeout,
42+ std::chrono::milliseconds spin_period)
43+{
44+ auto const end = std::chrono::steady_clock::now() + timeout;
45+ bool condition_fulfilled = false;
46+
47+ while (std::chrono::steady_clock::now() < end &&
48+ !(condition_fulfilled = condition()))
49+ {
50+ std::this_thread::sleep_for(spin_period);
51+ }
52+
53+ return condition_fulfilled;
54+}
55+
56
57=== added file 'tests/integration-tests/spin_wait.h'
58--- tests/integration-tests/spin_wait.h 1970-01-01 00:00:00 +0000
59+++ tests/integration-tests/spin_wait.h 2015-07-10 12:10:34 +0000
60@@ -0,0 +1,39 @@
61+/*
62+ * Copyright © 2015 Canonical Ltd.
63+ *
64+ * This program is free software: you can redistribute it and/or modify it
65+ * under the terms of the GNU General Public License version 3,
66+ * as published by the Free Software Foundation.
67+ *
68+ * This program is distributed in the hope that it will be useful,
69+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
70+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
71+ * GNU General Public License for more details.
72+ *
73+ * You should have received a copy of the GNU General Public License
74+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
75+ *
76+ * Authored by: Alexandros Frantzis <alexandros.frantzis@canonical.com>
77+ */
78+
79+#ifndef USC_SPIN_WAIT_H_
80+#define USC_SPIN_WAIT_H_
81+
82+#include <functional>
83+#include <chrono>
84+
85+namespace usc
86+{
87+namespace test
88+{
89+
90+
91+bool spin_wait_for_condition_or_timeout(
92+ std::function<bool()> const& condition,
93+ std::chrono::milliseconds timeout,
94+ std::chrono::milliseconds spin_period = std::chrono::milliseconds{10});
95+
96+}
97+}
98+
99+#endif
100
101=== modified file 'tests/integration-tests/test_external_spinner.cpp'
102--- tests/integration-tests/test_external_spinner.cpp 2015-04-01 17:11:57 +0000
103+++ tests/integration-tests/test_external_spinner.cpp 2015-07-10 12:10:34 +0000
104@@ -18,6 +18,7 @@
105
106 #include "src/external_spinner.h"
107 #include "run_command.h"
108+#include "spin_wait.h"
109
110 #include <fstream>
111 #include <chrono>
112@@ -74,12 +75,21 @@
113 {
114 std::vector<pid_t> spinner_pids()
115 {
116- return pidof(spinner_cmd);
117+ std::vector<pid_t> pids;
118+
119+ usc::test::spin_wait_for_condition_or_timeout(
120+ [&pids, this] { pids = pidof(spinner_cmd); return !pids.empty(); },
121+ timeout);
122+
123+ if (pids.empty())
124+ BOOST_THROW_EXCEPTION(std::runtime_error("spinner_pids timed out"));
125+
126+ return pids;
127 }
128
129 std::vector<std::string> environment_of_spinner()
130 {
131- auto const pids = pidof(spinner_cmd);
132+ auto const pids = spinner_pids();
133 if (pids.size() > 1)
134 BOOST_THROW_EXCEPTION(std::runtime_error("Detected multiple spinner processes"));
135 std::vector<std::string> env;
136@@ -96,19 +106,14 @@
137
138 void wait_for_spinner_to_terminate()
139 {
140- auto const timeout = std::chrono::milliseconds{3000};
141- auto const expire = std::chrono::steady_clock::now() + timeout;
142-
143- while (spinner_pids().size() > 0)
144- {
145- if (std::chrono::steady_clock::now() > expire)
146- BOOST_THROW_EXCEPTION(std::runtime_error("wait_for_no_spinner timed out"));
147- std::this_thread::sleep_for(std::chrono::milliseconds{10});
148- }
149+ usc::test::spin_wait_for_condition_or_timeout(
150+ [this] { return pidof(spinner_cmd).empty(); },
151+ timeout);
152 }
153
154 std::string const spinner_cmd{executable_path() + "/usc_test_helper_wait_for_signal"};
155 std::string const mir_socket{"usc_mir_socket"};
156+ std::chrono::milliseconds const timeout{3000};
157 usc::ExternalSpinner spinner{spinner_cmd, mir_socket};
158 };
159

Subscribers

People subscribed via source and target branches