Merge lp:~mhr3/unity/safer-tests into lp:unity

Proposed by Michal Hruby on 2012-03-05
Status: Merged
Approved by: Gord Allott on 2012-03-05
Approved revision: 2053
Merged at revision: 2081
Proposed branch: lp:~mhr3/unity/safer-tests
Merge into: lp:unity
Diff against target: 155 lines (+17/-13)
7 files modified
UnityCore/FilesystemLenses.cpp (+6/-2)
tests/TestPlacesResults.cpp (+1/-1)
tests/test_filesystem_lenses.cpp (+1/-1)
tests/test_gdbus_proxy.cpp (+3/-3)
tests/test_hud.cpp (+3/-3)
tests/test_main_dbus.cpp (+1/-1)
tests/test_utils.h (+2/-2)
To merge this branch: bzr merge lp:~mhr3/unity/safer-tests
Reviewer Review Type Date Requested Status
Gord Allott (community) 2012-03-05 Approve on 2012-03-05
Review via email: mp+95949@code.launchpad.net

Description of the Change

Makes the tests less racy by using g_timeout_add instead of the add_seconds which tries to fire multiple timeouts at once at the cost of precision. Also fixes a possible crash in the tests caused by FilesystemLenses.

To post a comment you must log in.
Gord Allott (gordallott) wrote :

+1, makes tests work again :)

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'UnityCore/FilesystemLenses.cpp'
2--- UnityCore/FilesystemLenses.cpp 2012-02-22 08:53:20 +0000
3+++ UnityCore/FilesystemLenses.cpp 2012-03-05 17:03:24 +0000
4@@ -236,7 +236,7 @@
5 gboolean result = g_file_load_contents_finish(file, res,
6 &contents, &length,
7 NULL, error.AsOutParam());
8- if (result && !error)
9+ if (result)
10 {
11 self->GetLensDataFromKeyFile(file, contents.Value(), length);
12 self->SortLensList();
13@@ -246,6 +246,8 @@
14 LOG_WARN(logger) << "Unable to read lens file "
15 << path.Str() << ": "
16 << error;
17+ if (g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED))
18+ return; // self is invalid now
19 }
20
21 self->cancel_map_.erase(file);
22@@ -350,6 +352,7 @@
23 ~Impl()
24 {
25 if (timeout_id != 0) g_source_remove (timeout_id);
26+ finished_slot_.disconnect();
27 }
28
29 void OnLoadingFinished();
30@@ -363,6 +366,7 @@
31 FilesystemLenses* owner_;
32 LensDirectoryReader::Ptr reader_;
33 LensList lenses_;
34+ sigc::connection finished_slot_;
35 guint timeout_id;
36 };
37
38@@ -371,7 +375,7 @@
39 , reader_(reader)
40 , timeout_id(0)
41 {
42- reader_->load_finished.connect(sigc::mem_fun(this, &Impl::OnLoadingFinished));
43+ finished_slot_ = reader_->load_finished.connect(sigc::mem_fun(this, &Impl::OnLoadingFinished));
44 if (reader_->IsDataLoaded())
45 {
46 // we won't get any signal, so let's just emit our signals after construction
47
48=== modified file 'tests/TestPlacesResults.cpp'
49--- tests/TestPlacesResults.cpp 2012-01-09 16:49:50 +0000
50+++ tests/TestPlacesResults.cpp 2012-03-05 17:03:24 +0000
51@@ -119,7 +119,7 @@
52
53 nux::GetGraphicsThread()->SetLayout(layout);
54 #endif
55- g_timeout_add_seconds(2, (GSourceFunc)remove_timeout, NULL);
56+ g_timeout_add(2000, (GSourceFunc)remove_timeout, NULL);
57 }
58
59 void TestRunner::InitWindowThread(nux::NThread* thread, void* InitData)
60
61=== modified file 'tests/test_filesystem_lenses.cpp'
62--- tests/test_filesystem_lenses.cpp 2012-02-22 08:53:20 +0000
63+++ tests/test_filesystem_lenses.cpp 2012-03-05 17:03:24 +0000
64@@ -18,7 +18,7 @@
65 return FALSE;
66 };
67
68- guint32 timeout_id = g_timeout_add_seconds(10, timeout_cb, &timeout_reached);
69+ guint32 timeout_id = g_timeout_add(10000, timeout_cb, &timeout_reached);
70
71 while (!result && !timeout_reached)
72 {
73
74=== modified file 'tests/test_gdbus_proxy.cpp'
75--- tests/test_gdbus_proxy.cpp 2012-02-21 17:13:56 +0000
76+++ tests/test_gdbus_proxy.cpp 2012-03-05 17:03:24 +0000
77@@ -60,8 +60,8 @@
78 return FALSE;
79 };
80
81- guint timeout_source = g_timeout_add_seconds(1, timeout_check, this); // check once a second
82- guint bailout_source = g_timeout_add_seconds(10, timeout_bailout, this); // bail out after ten
83+ guint timeout_source = g_timeout_add(1000, timeout_check, this); // check once a second
84+ guint bailout_source = g_timeout_add(10000, timeout_bailout, this); // bail out after ten
85
86 g_main_loop_run(loop_);
87 g_source_remove(timeout_source);
88@@ -114,7 +114,7 @@
89 return FALSE;
90 };
91
92- guint bailout_source = g_timeout_add_seconds(10, timeout_bailout, this);
93+ guint bailout_source = g_timeout_add(10000, timeout_bailout, this);
94
95 EXPECT_EQ(proxy->IsConnected(), true); // fail if we are not connected
96 proxy->Connect("TestSignal", signal_connection);
97
98=== modified file 'tests/test_hud.cpp'
99--- tests/test_hud.cpp 2012-01-12 11:45:05 +0000
100+++ tests/test_hud.cpp 2012-03-05 17:03:24 +0000
101@@ -57,8 +57,8 @@
102 return FALSE;
103 };
104
105- g_timeout_add_seconds(1, timeout_check, this);
106- g_timeout_add_seconds(10, timeout_bailout, this);
107+ g_timeout_add(1000, timeout_check, this);
108+ g_timeout_add(10000, timeout_bailout, this);
109
110 g_main_loop_run(loop_);
111
112@@ -87,7 +87,7 @@
113
114 hud->queries_updated.connect(query_connection);
115
116- guint source_id = g_timeout_add_seconds(10, timeout_bailout, this);
117+ guint source_id = g_timeout_add(10000, timeout_bailout, this);
118
119 // next check we get 30 entries from this specific known callback
120 hud->RequestQuery("Request30Queries");
121
122=== modified file 'tests/test_main_dbus.cpp'
123--- tests/test_main_dbus.cpp 2012-01-09 16:49:50 +0000
124+++ tests/test_main_dbus.cpp 2012-03-05 17:03:24 +0000
125@@ -59,7 +59,7 @@
126 NULL,
127 &have_name,
128 NULL);
129- g_timeout_add_seconds(10, timeout_cb, &timeout_reached);
130+ g_timeout_add(10000, timeout_cb, &timeout_reached);
131
132 while (!have_name && !timeout_reached)
133 g_main_context_iteration(g_main_context_get_thread_default(), TRUE);
134
135=== modified file 'tests/test_utils.h'
136--- tests/test_utils.h 2012-02-04 05:28:23 +0000
137+++ tests/test_utils.h 2012-03-05 17:03:24 +0000
138@@ -22,7 +22,7 @@
139 return FALSE;
140 };
141
142- guint32 timeout_id = g_timeout_add_seconds(10, timeout_cb, &timeout_reached);
143+ guint32 timeout_id = g_timeout_add(10000, timeout_cb, &timeout_reached);
144
145 while (model.count != n_rows && !timeout_reached)
146 {
147@@ -48,7 +48,7 @@
148
149 static guint32 ScheduleTimeout(bool* timeout_reached, unsigned int timeout_duration = 10)
150 {
151- return g_timeout_add_seconds(timeout_duration, TimeoutCallback, timeout_reached);
152+ return g_timeout_add(timeout_duration*1000, TimeoutCallback, timeout_reached);
153 }
154
155 static guint32 ScheduleTimeoutMSec(bool* timeout_reached, unsigned int timeout_duration = 10)