Skip to content
This repository was archived by the owner on Jul 8, 2022. It is now read-only.

Commit 6c22521

Browse files
committed
Add test for event recovery after restart (#496)
Tests that event subscription is restored immediately after the device restart.
1 parent d02c52b commit 6c22521

File tree

1 file changed

+52
-0
lines changed

1 file changed

+52
-0
lines changed

cpp_test_suite/new_tests/cxx_dserver_misc.cpp

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,26 @@ using namespace std;
1414
#undef SUITE_NAME
1515
#define SUITE_NAME DServerMiscTestSuite
1616

17+
struct EventCallback : public Tango::CallBack
18+
{
19+
EventCallback()
20+
: num_of_all_events(0)
21+
, num_of_error_events(0)
22+
{}
23+
24+
void push_event(Tango::EventData* event)
25+
{
26+
num_of_all_events++;
27+
if (event->err)
28+
{
29+
num_of_error_events++;
30+
}
31+
}
32+
33+
int num_of_all_events;
34+
int num_of_error_events;
35+
};
36+
1737
class DServerMiscTestSuite: public CxxTest::TestSuite
1838
{
1939
protected:
@@ -211,6 +231,38 @@ cout << "str = " << str << endl;
211231
TS_ASSERT(dserver->info().server_id == full_ds_name);
212232
TS_ASSERT(dserver->info().server_version == server_version);
213233
}
234+
235+
/* Tests that subscriber can receive events immediately after
236+
* a device restart without a need to wait for re-subscription.
237+
*/
238+
void test_event_subscription_recovery_after_device_restart()
239+
{
240+
EventCallback callback{};
241+
242+
std::string attribute_name = "event_change_tst";
243+
244+
TS_ASSERT_THROWS_NOTHING(device1->subscribe_event(
245+
attribute_name,
246+
Tango::USER_EVENT,
247+
&callback));
248+
249+
TS_ASSERT_THROWS_NOTHING(device1->command_inout("IOPushEvent"));
250+
Tango_sleep(2);
251+
TS_ASSERT_EQUALS(2, callback.num_of_all_events);
252+
TS_ASSERT_EQUALS(0, callback.num_of_error_events);
253+
254+
{
255+
Tango::DeviceData input{};
256+
input << device1_name;
257+
TS_ASSERT_THROWS_NOTHING(dserver->command_inout("DevRestart", input));
258+
}
259+
260+
TS_ASSERT_THROWS_NOTHING(device1->command_inout("IOPushEvent"));
261+
Tango_sleep(2);
262+
TS_ASSERT_EQUALS(3, callback.num_of_all_events);
263+
TS_ASSERT_EQUALS(0, callback.num_of_error_events);
264+
}
265+
214266
};
215267
#undef cout
216268
#endif // DServerMiscTestSuite_h

0 commit comments

Comments
 (0)