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
=== modified file 'libclickscope/tests/CMakeLists.txt'
--- libclickscope/tests/CMakeLists.txt 2014-07-14 08:49:19 +0000
+++ libclickscope/tests/CMakeLists.txt 2014-07-22 17:17:20 +0000
@@ -70,3 +70,6 @@
70 COMMAND valgrind --tool=memcheck --track-origins=yes --num-callers=40 --leak-resolution=high --leak-check=full ${CMAKE_CURRENT_BINARY_DIR}/${LIBCLICKSCOPE_TESTS_TARGET}70 COMMAND valgrind --tool=memcheck --track-origins=yes --num-callers=40 --leak-resolution=high --leak-check=full ${CMAKE_CURRENT_BINARY_DIR}/${LIBCLICKSCOPE_TESTS_TARGET}
71 DEPENDS ${LIBCLICKSCOPE_TESTS_TARGET}71 DEPENDS ${LIBCLICKSCOPE_TESTS_TARGET}
72)72)
73
74
75add_subdirectory(integration)
7376
=== renamed directory 'scope/tests/integration' => 'libclickscope/tests/integration'
=== modified file 'libclickscope/tests/integration/CMakeLists.txt'
--- scope/tests/integration/CMakeLists.txt 2014-05-26 15:56:40 +0000
+++ libclickscope/tests/integration/CMakeLists.txt 2014-07-22 17:17:20 +0000
@@ -11,6 +11,7 @@
11FILE (GLOB TEST_HEADERS *.h)11FILE (GLOB TEST_HEADERS *.h)
1212
13add_executable (${INTEGRATION_TARGET}13add_executable (${INTEGRATION_TARGET}
14 departmentsdb_integration.cpp
14 webclient_integration.cpp15 webclient_integration.cpp
15)16)
1617
1718
=== added file 'libclickscope/tests/integration/departmentsdb_integration.cpp'
--- libclickscope/tests/integration/departmentsdb_integration.cpp 1970-01-01 00:00:00 +0000
+++ libclickscope/tests/integration/departmentsdb_integration.cpp 2014-07-22 17:17:20 +0000
@@ -0,0 +1,137 @@
1/*
2 * Copyright (C) 2014 Canonical Ltd.
3 *
4 * This program is free software: you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License version 3, as published
6 * by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranties of
10 * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
11 * PURPOSE. See the GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License along
14 * with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * In addition, as a special exception, the copyright holders give
17 * permission to link the code of portions of this program with the
18 * OpenSSL library under certain conditions as described in each
19 * individual source file, and distribute linked combinations
20 * including the two.
21 * You must obey the GNU General Public License in all respects
22 * for all of the code used other than OpenSSL. If you modify
23 * file(s) with this exception, you may extend this exception to your
24 * version of the file(s), but you are not obligated to do so. If you
25 * do not wish to do so, delete this exception statement from your
26 * version. If you delete this exception statement from all source
27 * files in the program, then also delete it here.
28 */
29
30#include <gtest/gtest.h>
31
32#include <click/departments-db.h>
33
34#include <memory>
35#include <algorithm>
36#include <unistd.h>
37
38using namespace click;
39
40
41class DepartmentsDbConcurrencyTest: public ::testing::Test
42{
43public:
44 const std::string db_path = TEST_DIR "/departments-db-test2.sqlite";
45
46 void TearDown() override
47 {
48 unlink(db_path.c_str());
49 }
50};
51
52// Keep the numbers below at a reasonable level; it takes around 20 seconds
53// to run this test on a i7-2620M with the default values.
54const int NUM_OF_WRITE_OPS = 50;
55const int NUM_OF_READ_OPS = 100;
56
57void populate_departments(DepartmentsDb *db, int repeat_count)
58{
59 click::DepartmentList depts;
60 // generate departments with one subdepartment
61 for (int i = 0; i < 20; i++)
62 {
63 auto const id = std::to_string(i);
64 auto parent = std::make_shared<click::Department>(id, "Department " + id, "href", true);
65 parent->set_subdepartments({std::make_shared<click::Department>(id + "sub", "Subdepartment of " + id, "href", false)});
66 depts.push_back(parent);
67 }
68
69 for (int i = 0; i < repeat_count; i++)
70 {
71 ASSERT_NO_THROW(db->store_departments(depts, ""));
72
73 // generate apps
74 for (int j = 0; j < 50; j++)
75 {
76 auto const id = std::to_string(j);
77 ASSERT_NO_THROW(db->store_package_mapping("app" + id, id));
78 }
79 }
80}
81
82TEST_F(DepartmentsDbConcurrencyTest, ConcurrentReadWrite)
83{
84 // populate the db initially to make sure reader doesn't fail if it's faster than writer
85 {
86 DepartmentsDb db(db_path, true);
87 populate_departments(&db, 1);
88 }
89
90 pid_t writer_pid = fork();
91 if (writer_pid < 0)
92 {
93 FAIL();
94 }
95 else if (writer_pid == 0) // writer child process
96 {
97 SCOPED_TRACE("writer");
98 std::unique_ptr<DepartmentsDb> db;
99 ASSERT_NO_THROW(db.reset(new DepartmentsDb(db_path, true)));
100
101 populate_departments(db.get(), NUM_OF_WRITE_OPS);
102
103 exit(0);
104 }
105 else // parent process
106 {
107 pid_t reader_pid = fork();
108 if (reader_pid < 0)
109 {
110 FAIL();
111 }
112 else if (reader_pid == 0) // reader child process
113 {
114 SCOPED_TRACE("reader");
115 std::unique_ptr<DepartmentsDb> db;
116 ASSERT_NO_THROW(db.reset(new DepartmentsDb(db_path, false)));
117
118 for (int i = 0; i < NUM_OF_READ_OPS; i++)
119 {
120 ASSERT_NO_THROW(db->get_department_name("1", {""}));
121 ASSERT_NO_THROW(db->get_parent_department_id("1"));
122 ASSERT_NO_THROW(db->get_packages_for_department("1", false));
123 ASSERT_NO_THROW(db->get_packages_for_department("1", true));
124 ASSERT_NO_THROW(db->get_children_departments(""));
125 ASSERT_NO_THROW(db->department_name_count());
126 ASSERT_NO_THROW(db->department_mapping_count());
127 ASSERT_NO_THROW(db->package_count());
128 }
129 exit(0);
130 }
131 else // parent process
132 {
133 wait(nullptr);
134 wait(nullptr);
135 }
136 }
137}
0138
=== modified file 'libclickscope/tests/test_departments-db.cpp'
--- libclickscope/tests/test_departments-db.cpp 2014-07-18 15:10:55 +0000
+++ libclickscope/tests/test_departments-db.cpp 2014-07-22 17:17:20 +0000
@@ -32,7 +32,6 @@
32#include <click/departments-db.h>32#include <click/departments-db.h>
33#include <memory>33#include <memory>
34#include <algorithm>34#include <algorithm>
35#include <unistd.h>
3635
37using namespace click;36using namespace click;
3837
@@ -94,16 +93,6 @@
94 std::unique_ptr<DepartmentsDbCheck> db;93 std::unique_ptr<DepartmentsDbCheck> db;
95};94};
9695
97class DepartmentsDbConcurrencyTest: public ::testing::Test
98{
99public:
100 const std::string db_path = TEST_DIR "/departments-db-test2.sqlite";
101
102 void TearDown() override
103 {
104 unlink(db_path.c_str());
105 }
106};
10796
108TEST_F(DepartmentsDbTest, testDepartmentNameLookup)97TEST_F(DepartmentsDbTest, testDepartmentNameLookup)
109{98{
@@ -290,93 +279,6 @@
290 db->check_sql_queries_finished();279 db->check_sql_queries_finished();
291}280}
292281
293// Keep the numbers below at a reasonable level; it takes around 20 seconds
294// to run this test on a i7-2620M with the default values.
295const int NUM_OF_WRITE_OPS = 50;
296const int NUM_OF_READ_OPS = 100;
297
298void populate_departments(DepartmentsDb *db, int repeat_count)
299{
300 click::DepartmentList depts;
301 // generate departments with one subdepartment
302 for (int i = 0; i < 20; i++)
303 {
304 auto const id = std::to_string(i);
305 auto parent = std::make_shared<click::Department>(id, "Department " + id, "href", true);
306 parent->set_subdepartments({std::make_shared<click::Department>(id + "sub", "Subdepartment of " + id, "href", false)});
307 depts.push_back(parent);
308 }
309
310 for (int i = 0; i < repeat_count; i++)
311 {
312 ASSERT_NO_THROW(db->store_departments(depts, ""));
313
314 // generate apps
315 for (int j = 0; j < 50; j++)
316 {
317 auto const id = std::to_string(j);
318 ASSERT_NO_THROW(db->store_package_mapping("app" + id, id));
319 }
320 }
321}
322
323TEST_F(DepartmentsDbConcurrencyTest, ConcurrentReadWrite)
324{
325 // populate the db initially to make sure reader doesn't fail if it's faster than writer
326 {
327 DepartmentsDb db(db_path, true);
328 populate_departments(&db, 1);
329 }
330
331 pid_t writer_pid = fork();
332 if (writer_pid < 0)
333 {
334 FAIL();
335 }
336 else if (writer_pid == 0) // writer child process
337 {
338 SCOPED_TRACE("writer");
339 std::unique_ptr<DepartmentsDb> db;
340 ASSERT_NO_THROW(db.reset(new DepartmentsDb(db_path, true)));
341
342 populate_departments(db.get(), NUM_OF_WRITE_OPS);
343
344 exit(0);
345 }
346 else // parent process
347 {
348 pid_t reader_pid = fork();
349 if (reader_pid < 0)
350 {
351 FAIL();
352 }
353 else if (reader_pid == 0) // reader child process
354 {
355 SCOPED_TRACE("reader");
356 std::unique_ptr<DepartmentsDb> db;
357 ASSERT_NO_THROW(db.reset(new DepartmentsDb(db_path, false)));
358
359 for (int i = 0; i < NUM_OF_READ_OPS; i++)
360 {
361 ASSERT_NO_THROW(db->get_department_name("1", {""}));
362 ASSERT_NO_THROW(db->get_parent_department_id("1"));
363 ASSERT_NO_THROW(db->get_packages_for_department("1", false));
364 ASSERT_NO_THROW(db->get_packages_for_department("1", true));
365 ASSERT_NO_THROW(db->get_children_departments(""));
366 ASSERT_NO_THROW(db->department_name_count());
367 ASSERT_NO_THROW(db->department_mapping_count());
368 ASSERT_NO_THROW(db->package_count());
369 }
370 exit(0);
371 }
372 else // parent process
373 {
374 wait(nullptr);
375 wait(nullptr);
376 }
377 }
378}
379
380TEST(DepartmentsDb, testOpenFailsOnUnitializedDb)282TEST(DepartmentsDb, testOpenFailsOnUnitializedDb)
381{283{
382 ASSERT_THROW(284 ASSERT_THROW(
383285
=== modified file 'scope/tests/CMakeLists.txt'
--- scope/tests/CMakeLists.txt 2014-07-17 16:20:24 +0000
+++ scope/tests/CMakeLists.txt 2014-07-22 17:17:20 +0000
@@ -102,7 +102,6 @@
102)102)
103103
104104
105add_subdirectory(integration)
106add_subdirectory(download_manager_tool)105add_subdirectory(download_manager_tool)
107add_subdirectory(click_interface_tool)106add_subdirectory(click_interface_tool)
108add_subdirectory(fake_launcher)107add_subdirectory(fake_launcher)

Subscribers

People subscribed via source and target branches

to all changes: