Skip to content

Commit

Permalink
improve tests so they don't hang when failing
Browse files Browse the repository at this point in the history
also, give better errors

Co-Authored-By: Joseph Eng <[email protected]>
  • Loading branch information
kytpbs and KangarooKoala committed Dec 16, 2024
1 parent da6c11b commit eb91b21
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -450,13 +450,15 @@ void repeatForTest() {
Command group = command.repeatedly(3);

scheduler.schedule(group);
for (int i = 0;
scheduler.isScheduled(group);
i++) { // If this causes an infinite loop, repeatedly is cooked
assertEquals(1, counter.get());
for (int i = 1; i < 3; i++) {
scheduler.run();
assertEquals(i + 1, counter.get());
assertEquals(i, counter.get());
assertTrue(scheduler.isScheduled(group), "Expected group to be scheduled with i = " + i);
}
assertEquals(3, counter.get());
scheduler.run();
assertEquals(3, counter.get(), "Loop should have run 3 times something went wrong");
assertFalse(scheduler.isScheduled(group), "This command should have gotten unscheduled");
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -408,12 +408,16 @@ TEST_F(CommandDecoratorTest, RepeatFor) {
auto command = InstantCommand([&counter] { counter++; }, {}).Repeatedly(3);

scheduler.Schedule(command);
for (int i = 0; scheduler.IsScheduled(command); i++) {
EXPECT_TRUE(scheduler.IsScheduled(command));
for (int i = 1; i < 3; i++) {
scheduler.Run();
EXPECT_EQ(i + 1, counter);
EXPECT_EQ(i, counter);
EXPECT_TRUE(scheduler.IsScheduled(command));
}

scheduler.Run();
EXPECT_EQ(3, counter);
EXPECT_FALSE(scheduler.IsScheduled(command));
}

TEST_F(CommandDecoratorTest, Unless) {
Expand Down

0 comments on commit eb91b21

Please sign in to comment.