Skip to content

Commit

Permalink
test fix
Browse files Browse the repository at this point in the history
  • Loading branch information
renukamanavalan committed Aug 11, 2022
1 parent 6c1c90f commit d16cc76
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 29 deletions.
53 changes: 25 additions & 28 deletions src/sonic-eventd/tests/eventd_ut.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -703,24 +703,15 @@ TEST(eventd, service)
printf("Service TEST completed\n");
}


TEST(eventd, heartbeat)
void
wait_for_heartbeat(stats_collector &stats_instance, int cnt)
{
printf("heartbeat TEST started\n");

int rc, cnt;
stats_collector stats_instance;

debug_on();

rc = stats_instance.start();
EXPECT_EQ(rc, 0);

auto st = duration_cast<milliseconds>(system_clock::now().time_since_epoch()).count();
while (stats_instance.heartbeats_cnt() != 0) {
while (stats_instance.heartbeats_cnt() != cnt) {
auto en = duration_cast<milliseconds>(system_clock::now().time_since_epoch()).count();
if ((en -st) > 3000) {
EXPECT_LE((en -st), 3000);
EXPECT_EQ(cnt, stats_instance.heartbeats_cnt());
break;
}
else {
Expand All @@ -729,10 +720,27 @@ TEST(eventd, heartbeat)
printf("DROP:Waiting for heartbeat. duration:%s ms", ss.str().c_str());
}
}
}

TEST(eventd, heartbeat)
{
printf("heartbeat TEST started\n");

int rc, cnt;
stats_collector stats_instance;

debug_on();

rc = stats_instance.start();
EXPECT_EQ(rc, 0);

/* Wait for any non-zero heartbeat */
wait_for_heartbeat(stats_instance, 0);

/* Pause heartbeat */
stats_instance.heartbeat_ctrl(true);

/* Sleep to ensure the other thread noticed the update. */
/* Sleep to ensure the other thread noticed the pause request. */
this_thread::sleep_for(chrono::milliseconds(200));

/* Get current count */
Expand All @@ -746,20 +754,9 @@ TEST(eventd, heartbeat)
/* Turn on heartbeat
stats_instance.heartbeat_ctrl();
st = duration_cast<milliseconds>(system_clock::now().time_since_epoch()).count();
/* Wait for a heartbeat */
while (stats_instance.heartbeats_cnt() == cnt) {
auto en = duration_cast<milliseconds>(system_clock::now().time_since_epoch()).count();
if ((en -st) > 3000) {
EXPECT_LE((en -st), 3000);
break;
}
else {
stringstream ss;
ss << (en -st);
printf("DROP:Waiting for NO heartbeat for 3secs. duration:%s ms", ss.str().c_str());
}
}
/* Wait for heartbeat count to change from last count */
wait_for_heartbeat(stats_instance, cnt);

stats_instance.stop();
printf("heartbeat TEST completed\n");
}
Expand Down
4 changes: 3 additions & 1 deletion src/sonic-eventd/tests/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ string global_existing_file = "./tests/redis_multi_db_ut_config/database_global.
#define TEST_NAMESPACE "asic0"
#define INVALID_NAMESPACE "invalid"

SwsscommonEnvironment* const env = NULL;

class SwsscommonEnvironment : public ::testing::Environment {
public:
// Override this to define how to set up the environment.
Expand Down Expand Up @@ -86,7 +88,7 @@ int main(int argc, char* argv[])
testing::InitGoogleTest(&argc, argv);
// Registers a global test environment, and verifies that the
// registration function returns its argument.
SwsscommonEnvironment* const env = new SwsscommonEnvironment;
env = new SwsscommonEnvironment;
testing::AddGlobalTestEnvironment(env);
return RUN_ALL_TESTS();
}

0 comments on commit d16cc76

Please sign in to comment.