Skip to content

Commit af893ec

Browse files
committed
Make timing checks more robust
Estimating the exact execution time in CI is very hard, so we restrict it by bounds to check whether the right parameters are actually being used. This could be greatly improved by faking / mocking the actual execution for a unit test instead of using URSim in an integration test.
1 parent 04f65da commit af893ec

File tree

1 file changed

+21
-10
lines changed

1 file changed

+21
-10
lines changed

tests/test_instruction_executor.cpp

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -170,26 +170,32 @@ TEST_F(InstructionExecutorTest, execute_movej_success)
170170
ASSERT_TRUE(executor_->moveJ({ -1.57, -1.57, 0, 0, 0, 0 }, 3.4, 3.1, 0));
171171
auto end = std::chrono::steady_clock::now();
172172
auto duration = std::chrono::duration_cast<std::chrono::milliseconds>(end - start);
173-
ASSERT_NEAR(duration.count(), 1550, 100);
173+
// With this parametrization execution should take about 1.55 seconds plus some overhead. We test
174+
// time parametrization below with a motion time of 2.5 seconds, so this is the upper bound to
175+
// distinguish between the two. This large range is necessary, as the actual overhead is not
176+
// known.
177+
ASSERT_GT(duration.count(), 1550);
178+
ASSERT_LT(duration.count(), 2500);
174179

175180
start = std::chrono::steady_clock::now();
176181
ASSERT_TRUE(executor_->moveJ({ -1.57, -1.6, 1.6, -0.7, 0.7, 0.2 }, 3.4, 3.1, 0));
177182
end = std::chrono::steady_clock::now();
178183
duration = std::chrono::duration_cast<std::chrono::milliseconds>(end - start);
179-
ASSERT_NEAR(duration.count(), 1550, 100);
184+
ASSERT_GT(duration.count(), 1550);
185+
ASSERT_LT(duration.count(), 2500);
180186

181187
// time parametrization
182188
start = std::chrono::steady_clock::now();
183-
ASSERT_TRUE(executor_->moveJ({ -1.57, -1.57, 0, 0, 0, 0 }, 1.4, 1.04, 3));
189+
ASSERT_TRUE(executor_->moveJ({ -1.57, -1.57, 0, 0, 0, 0 }, 1.4, 1.04, 3)); // 3 seconds
184190
end = std::chrono::steady_clock::now();
185191
duration = std::chrono::duration_cast<std::chrono::milliseconds>(end - start);
186-
ASSERT_NEAR(duration.count(), 3100, 200);
192+
ASSERT_GE(duration.count(), 3000);
187193

188194
start = std::chrono::steady_clock::now();
189-
ASSERT_TRUE(executor_->moveJ({ -1.57, -1.6, 1.6, -0.7, 0.7, 0.2 }, 1.4, 1.04, 2.5));
195+
ASSERT_TRUE(executor_->moveJ({ -1.57, -1.6, 1.6, -0.7, 0.7, 0.2 }, 1.4, 1.04, 2.5)); // 2.5 seconds
190196
end = std::chrono::steady_clock::now();
191197
duration = std::chrono::duration_cast<std::chrono::milliseconds>(end - start);
192-
ASSERT_NEAR(duration.count(), 2600, 150);
198+
ASSERT_GE(duration.count(), 2500);
193199
}
194200

195201
TEST_F(InstructionExecutorTest, execute_movel_success)
@@ -204,26 +210,31 @@ TEST_F(InstructionExecutorTest, execute_movel_success)
204210
ASSERT_TRUE(executor_->moveL({ -0.203, 0.263, 0.559, 0.68, -1.083, -2.076 }, 1.5, 1.5));
205211
auto end = std::chrono::steady_clock::now();
206212
auto duration = std::chrono::duration_cast<std::chrono::milliseconds>(end - start);
207-
ASSERT_NEAR(duration.count(), 800, 150);
213+
// With this parametrization execution should take about 700 milliseconds plus some overhead. We test
214+
// time parametrization below with a motion time of 0.3 seconds, so checking that we take longer
215+
// should be sufficient to distinguish between the two.
216+
ASSERT_GT(duration.count(), 700);
208217

209218
start = std::chrono::steady_clock::now();
210219
ASSERT_TRUE(executor_->moveL({ -0.203, 0.463, 0.559, 0.68, -1.083, -2.076 }, 1.5, 1.5));
211220
end = std::chrono::steady_clock::now();
212221
duration = std::chrono::duration_cast<std::chrono::milliseconds>(end - start);
213-
ASSERT_NEAR(duration.count(), 800, 150);
222+
ASSERT_GT(duration.count(), 700);
214223

215224
// time parametrization
216225
start = std::chrono::steady_clock::now();
217226
ASSERT_TRUE(executor_->moveL({ -0.203, 0.263, 0.559, 0.68, -1.083, -2.076 }, 1.5, 1.5, 0.3));
218227
end = std::chrono::steady_clock::now();
219228
duration = std::chrono::duration_cast<std::chrono::milliseconds>(end - start);
220-
ASSERT_NEAR(duration.count(), 400, 50);
229+
ASSERT_GT(duration.count(), 300);
230+
ASSERT_LT(duration.count(), 700);
221231

222232
start = std::chrono::steady_clock::now();
223233
ASSERT_TRUE(executor_->moveL({ -0.203, 0.463, 0.559, 0.68, -1.083, -2.076 }, 1.5, 1.5, 0.3));
224234
end = std::chrono::steady_clock::now();
225235
duration = std::chrono::duration_cast<std::chrono::milliseconds>(end - start);
226-
ASSERT_NEAR(duration.count(), 400, 50);
236+
ASSERT_GT(duration.count(), 300);
237+
ASSERT_LT(duration.count(), 700);
227238
}
228239

229240
TEST_F(InstructionExecutorTest, sending_commands_without_reverse_interface_connected_fails)

0 commit comments

Comments
 (0)