Merge lp:~dobey/unity-scope-click/faster-tests into lp:unity-scope-click/devel

Proposed by dobey
Status: Merged
Approved by: Alejandro J. Cura
Approved revision: 351
Merged at revision: 361
Proposed branch: lp:~dobey/unity-scope-click/faster-tests
Merge into: lp:unity-scope-click/devel
Diff against target: 300 lines (+141/-99)
5 files modified
libclickscope/tests/CMakeLists.txt (+3/-0)
libclickscope/tests/integration/CMakeLists.txt (+1/-0)
libclickscope/tests/integration/departmentsdb_integration.cpp (+137/-0)
libclickscope/tests/test_departments-db.cpp (+0/-98)
scope/tests/CMakeLists.txt (+0/-1)
To merge this branch: bzr merge lp:~dobey/unity-scope-click/faster-tests
Reviewer Review Type Date Requested Status
Alejandro J. Cura (community) Approve
PS Jenkins bot (community) continuous-integration Approve
Review via email: mp+227793@code.launchpad.net

Commit message

Move the slow departments db concurrency test to the integration suite.
Move the existing integration suite under libclickscope as it's for that code.

To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Alejandro J. Cura (alecu) wrote :

Better, faster, stronger!

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'libclickscope/tests/CMakeLists.txt'
2--- libclickscope/tests/CMakeLists.txt 2014-07-14 08:49:19 +0000
3+++ libclickscope/tests/CMakeLists.txt 2014-07-22 17:17:20 +0000
4@@ -70,3 +70,6 @@
5 COMMAND valgrind --tool=memcheck --track-origins=yes --num-callers=40 --leak-resolution=high --leak-check=full ${CMAKE_CURRENT_BINARY_DIR}/${LIBCLICKSCOPE_TESTS_TARGET}
6 DEPENDS ${LIBCLICKSCOPE_TESTS_TARGET}
7 )
8+
9+
10+add_subdirectory(integration)
11
12=== renamed directory 'scope/tests/integration' => 'libclickscope/tests/integration'
13=== modified file 'libclickscope/tests/integration/CMakeLists.txt'
14--- scope/tests/integration/CMakeLists.txt 2014-05-26 15:56:40 +0000
15+++ libclickscope/tests/integration/CMakeLists.txt 2014-07-22 17:17:20 +0000
16@@ -11,6 +11,7 @@
17 FILE (GLOB TEST_HEADERS *.h)
18
19 add_executable (${INTEGRATION_TARGET}
20+ departmentsdb_integration.cpp
21 webclient_integration.cpp
22 )
23
24
25=== added file 'libclickscope/tests/integration/departmentsdb_integration.cpp'
26--- libclickscope/tests/integration/departmentsdb_integration.cpp 1970-01-01 00:00:00 +0000
27+++ libclickscope/tests/integration/departmentsdb_integration.cpp 2014-07-22 17:17:20 +0000
28@@ -0,0 +1,137 @@
29+/*
30+ * Copyright (C) 2014 Canonical Ltd.
31+ *
32+ * This program is free software: you can redistribute it and/or modify it
33+ * under the terms of the GNU General Public License version 3, as published
34+ * by the Free Software Foundation.
35+ *
36+ * This program is distributed in the hope that it will be useful, but
37+ * WITHOUT ANY WARRANTY; without even the implied warranties of
38+ * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
39+ * PURPOSE. See the GNU General Public License for more details.
40+ *
41+ * You should have received a copy of the GNU General Public License along
42+ * with this program. If not, see <http://www.gnu.org/licenses/>.
43+ *
44+ * In addition, as a special exception, the copyright holders give
45+ * permission to link the code of portions of this program with the
46+ * OpenSSL library under certain conditions as described in each
47+ * individual source file, and distribute linked combinations
48+ * including the two.
49+ * You must obey the GNU General Public License in all respects
50+ * for all of the code used other than OpenSSL. If you modify
51+ * file(s) with this exception, you may extend this exception to your
52+ * version of the file(s), but you are not obligated to do so. If you
53+ * do not wish to do so, delete this exception statement from your
54+ * version. If you delete this exception statement from all source
55+ * files in the program, then also delete it here.
56+ */
57+
58+#include <gtest/gtest.h>
59+
60+#include <click/departments-db.h>
61+
62+#include <memory>
63+#include <algorithm>
64+#include <unistd.h>
65+
66+using namespace click;
67+
68+
69+class DepartmentsDbConcurrencyTest: public ::testing::Test
70+{
71+public:
72+ const std::string db_path = TEST_DIR "/departments-db-test2.sqlite";
73+
74+ void TearDown() override
75+ {
76+ unlink(db_path.c_str());
77+ }
78+};
79+
80+// Keep the numbers below at a reasonable level; it takes around 20 seconds
81+// to run this test on a i7-2620M with the default values.
82+const int NUM_OF_WRITE_OPS = 50;
83+const int NUM_OF_READ_OPS = 100;
84+
85+void populate_departments(DepartmentsDb *db, int repeat_count)
86+{
87+ click::DepartmentList depts;
88+ // generate departments with one subdepartment
89+ for (int i = 0; i < 20; i++)
90+ {
91+ auto const id = std::to_string(i);
92+ auto parent = std::make_shared<click::Department>(id, "Department " + id, "href", true);
93+ parent->set_subdepartments({std::make_shared<click::Department>(id + "sub", "Subdepartment of " + id, "href", false)});
94+ depts.push_back(parent);
95+ }
96+
97+ for (int i = 0; i < repeat_count; i++)
98+ {
99+ ASSERT_NO_THROW(db->store_departments(depts, ""));
100+
101+ // generate apps
102+ for (int j = 0; j < 50; j++)
103+ {
104+ auto const id = std::to_string(j);
105+ ASSERT_NO_THROW(db->store_package_mapping("app" + id, id));
106+ }
107+ }
108+}
109+
110+TEST_F(DepartmentsDbConcurrencyTest, ConcurrentReadWrite)
111+{
112+ // populate the db initially to make sure reader doesn't fail if it's faster than writer
113+ {
114+ DepartmentsDb db(db_path, true);
115+ populate_departments(&db, 1);
116+ }
117+
118+ pid_t writer_pid = fork();
119+ if (writer_pid < 0)
120+ {
121+ FAIL();
122+ }
123+ else if (writer_pid == 0) // writer child process
124+ {
125+ SCOPED_TRACE("writer");
126+ std::unique_ptr<DepartmentsDb> db;
127+ ASSERT_NO_THROW(db.reset(new DepartmentsDb(db_path, true)));
128+
129+ populate_departments(db.get(), NUM_OF_WRITE_OPS);
130+
131+ exit(0);
132+ }
133+ else // parent process
134+ {
135+ pid_t reader_pid = fork();
136+ if (reader_pid < 0)
137+ {
138+ FAIL();
139+ }
140+ else if (reader_pid == 0) // reader child process
141+ {
142+ SCOPED_TRACE("reader");
143+ std::unique_ptr<DepartmentsDb> db;
144+ ASSERT_NO_THROW(db.reset(new DepartmentsDb(db_path, false)));
145+
146+ for (int i = 0; i < NUM_OF_READ_OPS; i++)
147+ {
148+ ASSERT_NO_THROW(db->get_department_name("1", {""}));
149+ ASSERT_NO_THROW(db->get_parent_department_id("1"));
150+ ASSERT_NO_THROW(db->get_packages_for_department("1", false));
151+ ASSERT_NO_THROW(db->get_packages_for_department("1", true));
152+ ASSERT_NO_THROW(db->get_children_departments(""));
153+ ASSERT_NO_THROW(db->department_name_count());
154+ ASSERT_NO_THROW(db->department_mapping_count());
155+ ASSERT_NO_THROW(db->package_count());
156+ }
157+ exit(0);
158+ }
159+ else // parent process
160+ {
161+ wait(nullptr);
162+ wait(nullptr);
163+ }
164+ }
165+}
166
167=== modified file 'libclickscope/tests/test_departments-db.cpp'
168--- libclickscope/tests/test_departments-db.cpp 2014-07-18 15:10:55 +0000
169+++ libclickscope/tests/test_departments-db.cpp 2014-07-22 17:17:20 +0000
170@@ -32,7 +32,6 @@
171 #include <click/departments-db.h>
172 #include <memory>
173 #include <algorithm>
174-#include <unistd.h>
175
176 using namespace click;
177
178@@ -94,16 +93,6 @@
179 std::unique_ptr<DepartmentsDbCheck> db;
180 };
181
182-class DepartmentsDbConcurrencyTest: public ::testing::Test
183-{
184-public:
185- const std::string db_path = TEST_DIR "/departments-db-test2.sqlite";
186-
187- void TearDown() override
188- {
189- unlink(db_path.c_str());
190- }
191-};
192
193 TEST_F(DepartmentsDbTest, testDepartmentNameLookup)
194 {
195@@ -290,93 +279,6 @@
196 db->check_sql_queries_finished();
197 }
198
199-// Keep the numbers below at a reasonable level; it takes around 20 seconds
200-// to run this test on a i7-2620M with the default values.
201-const int NUM_OF_WRITE_OPS = 50;
202-const int NUM_OF_READ_OPS = 100;
203-
204-void populate_departments(DepartmentsDb *db, int repeat_count)
205-{
206- click::DepartmentList depts;
207- // generate departments with one subdepartment
208- for (int i = 0; i < 20; i++)
209- {
210- auto const id = std::to_string(i);
211- auto parent = std::make_shared<click::Department>(id, "Department " + id, "href", true);
212- parent->set_subdepartments({std::make_shared<click::Department>(id + "sub", "Subdepartment of " + id, "href", false)});
213- depts.push_back(parent);
214- }
215-
216- for (int i = 0; i < repeat_count; i++)
217- {
218- ASSERT_NO_THROW(db->store_departments(depts, ""));
219-
220- // generate apps
221- for (int j = 0; j < 50; j++)
222- {
223- auto const id = std::to_string(j);
224- ASSERT_NO_THROW(db->store_package_mapping("app" + id, id));
225- }
226- }
227-}
228-
229-TEST_F(DepartmentsDbConcurrencyTest, ConcurrentReadWrite)
230-{
231- // populate the db initially to make sure reader doesn't fail if it's faster than writer
232- {
233- DepartmentsDb db(db_path, true);
234- populate_departments(&db, 1);
235- }
236-
237- pid_t writer_pid = fork();
238- if (writer_pid < 0)
239- {
240- FAIL();
241- }
242- else if (writer_pid == 0) // writer child process
243- {
244- SCOPED_TRACE("writer");
245- std::unique_ptr<DepartmentsDb> db;
246- ASSERT_NO_THROW(db.reset(new DepartmentsDb(db_path, true)));
247-
248- populate_departments(db.get(), NUM_OF_WRITE_OPS);
249-
250- exit(0);
251- }
252- else // parent process
253- {
254- pid_t reader_pid = fork();
255- if (reader_pid < 0)
256- {
257- FAIL();
258- }
259- else if (reader_pid == 0) // reader child process
260- {
261- SCOPED_TRACE("reader");
262- std::unique_ptr<DepartmentsDb> db;
263- ASSERT_NO_THROW(db.reset(new DepartmentsDb(db_path, false)));
264-
265- for (int i = 0; i < NUM_OF_READ_OPS; i++)
266- {
267- ASSERT_NO_THROW(db->get_department_name("1", {""}));
268- ASSERT_NO_THROW(db->get_parent_department_id("1"));
269- ASSERT_NO_THROW(db->get_packages_for_department("1", false));
270- ASSERT_NO_THROW(db->get_packages_for_department("1", true));
271- ASSERT_NO_THROW(db->get_children_departments(""));
272- ASSERT_NO_THROW(db->department_name_count());
273- ASSERT_NO_THROW(db->department_mapping_count());
274- ASSERT_NO_THROW(db->package_count());
275- }
276- exit(0);
277- }
278- else // parent process
279- {
280- wait(nullptr);
281- wait(nullptr);
282- }
283- }
284-}
285-
286 TEST(DepartmentsDb, testOpenFailsOnUnitializedDb)
287 {
288 ASSERT_THROW(
289
290=== modified file 'scope/tests/CMakeLists.txt'
291--- scope/tests/CMakeLists.txt 2014-07-17 16:20:24 +0000
292+++ scope/tests/CMakeLists.txt 2014-07-22 17:17:20 +0000
293@@ -102,7 +102,6 @@
294 )
295
296
297-add_subdirectory(integration)
298 add_subdirectory(download_manager_tool)
299 add_subdirectory(click_interface_tool)
300 add_subdirectory(fake_launcher)

Subscribers

People subscribed via source and target branches

to all changes: