Skip to content

Commit 0321d2a

Browse files
committed
test_sdo_scheduler.cpp: add test for retryable failure
1 parent a8365f7 commit 0321d2a

1 file changed

Lines changed: 44 additions & 0 deletions

File tree

rise_motion_dev_ws/src/rise_motion/test/test_sdo_scheduler.cpp

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,3 +79,47 @@ TEST(SdoSchedulerTest, SUCCESSFUL_WRITE)
7979

8080
EXPECT_EQ(scheduler.num_jobs_pending(), 0);
8181
}
82+
83+
84+
TEST(SdoSchedulerTest, RETRYABLE_FAILURE)
85+
{
86+
SdoScheduler scheduler;
87+
88+
auto retry_options = SdoScheduler::get_default_retry_options();
89+
retry_options.max_attempts = 2;
90+
91+
auto submission = scheduler.enqueue_read(1, 0x6064, 0x00, 1, retry_options);
92+
93+
ASSERT_NE(submission.id, SdoScheduler::INVALID_JOB_ID);
94+
EXPECT_EQ(scheduler.num_jobs_pending(), 1);
95+
96+
auto first_job = scheduler.get_job();
97+
98+
ASSERT_TRUE(first_job.has_value());
99+
EXPECT_EQ(first_job->attempts, 1);
100+
101+
auto first_reply = SdoScheduler::AttemptResult{SdoScheduler::AttemptStatus::RETRYABLE_FAILURE};
102+
bool first_completed = scheduler.complete_attempt(first_job->id, first_reply);
103+
104+
ASSERT_TRUE(first_completed);
105+
EXPECT_EQ(scheduler.pending_count(), 1);
106+
107+
auto second_job = scheduler.get_job();
108+
109+
ASSERT_TRUE(second_job.has_value());
110+
EXPECT_EQ(second_job->id, submission.id);
111+
EXPECT_EQ(second_job->attempts, 2);
112+
113+
auto second_reply = SdoScheduler::AttemptResult{SdoScheduler::AttemptStatus::SUCCESS, {0x11}};
114+
bool second_completed = scheduler.complete_attempt(first_job->id, second_reply);
115+
116+
ASSERT_TRUE(second_completed);
117+
ASSERT_EQ(submission.future.wait_for(std::chrono::milliseconds{1}), std::future_status::ready);
118+
119+
const auto result = submission.future.get();
120+
121+
ASSERT_TRUE(result);
122+
EXPECT_EQ(result.value, std::vector<std::uint8_t>{0x11});
123+
124+
EXPECT_EQ(scheduler.num_jobs_pending(), 0);
125+
}

0 commit comments

Comments
 (0)