Skip to content

Commit

Permalink
Increase sleep to address Watchdog test flakiness. (#1036)
Browse files Browse the repository at this point in the history
Watchdog test flakiness occurs when expected Watchdog violations are
missing or late caused by platforms randomness. Increasing the sleep
from 2 to 4 times kWatchdogMonitorFrequency reduces the chances of
missing or late Watchdog violations caused by platforms randomness.

b/292027298
b/292300293

Change-Id: I9e4ca05533f71cad997b88edb04e23114ab4c74a
(cherry picked from commit d955333)
  • Loading branch information
briantting authored and anonymous1-me committed Jul 28, 2023
1 parent 0ad4522 commit 5c6c2fd
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 24 deletions.
32 changes: 17 additions & 15 deletions cobalt/watchdog/watchdog_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ namespace {

const char kWatchdogViolationsJson[] = "watchdog_test.json";
const int64_t kWatchdogMonitorFrequency = 100000;
const int64_t kWatchdogSleepDuration = kWatchdogMonitorFrequency * 4;

} // namespace

Expand Down Expand Up @@ -163,7 +164,7 @@ TEST_F(WatchdogTest, ViolationsJsonShouldPersistAndBeValid) {
base::kApplicationStateStarted,
kWatchdogMonitorFrequency));
ASSERT_TRUE(watchdog_->Ping("test-name", "test-ping"));
SbThreadSleep(kWatchdogMonitorFrequency * 2);
SbThreadSleep(kWatchdogSleepDuration);
ASSERT_TRUE(watchdog_->Unregister("test-name"));
TearDown();
watchdog_ = new watchdog::Watchdog();
Expand Down Expand Up @@ -233,7 +234,7 @@ TEST_F(WatchdogTest, RedundantViolationsShouldStack) {
ASSERT_TRUE(watchdog_->Register("test-name", "test-desc",
base::kApplicationStateStarted,
kWatchdogMonitorFrequency));
SbThreadSleep(kWatchdogMonitorFrequency * 2);
SbThreadSleep(kWatchdogSleepDuration);
std::string json = watchdog_->GetWatchdogViolations(false);
ASSERT_NE(json, "");
std::unique_ptr<base::Value> uncleared_violations_map =
Expand All @@ -250,7 +251,7 @@ TEST_F(WatchdogTest, RedundantViolationsShouldStack) {
std::stoll(violations->GetList()[0]
.FindKey("violationDurationMilliseconds")
->GetString());
SbThreadSleep(kWatchdogMonitorFrequency * 2);
SbThreadSleep(kWatchdogSleepDuration);
json = watchdog_->GetWatchdogViolations(false);
ASSERT_NE(json, "");
std::unique_ptr<base::Value> violations_map = base::JSONReader::Read(json);
Expand All @@ -273,15 +274,15 @@ TEST_F(WatchdogTest, ViolationsShouldResetAfterFetch) {
ASSERT_TRUE(watchdog_->Register("test-name-1", "test-desc-1",
base::kApplicationStateStarted,
kWatchdogMonitorFrequency));
SbThreadSleep(kWatchdogMonitorFrequency * 2);
SbThreadSleep(kWatchdogSleepDuration);
ASSERT_TRUE(watchdog_->Unregister("test-name-1"));
std::string json = watchdog_->GetWatchdogViolations();
ASSERT_NE(json.find("test-name-1"), std::string::npos);
ASSERT_EQ(json.find("test-name-2"), std::string::npos);
ASSERT_TRUE(watchdog_->Register("test-name-2", "test-desc-2",
base::kApplicationStateStarted,
kWatchdogMonitorFrequency));
SbThreadSleep(kWatchdogMonitorFrequency * 2);
SbThreadSleep(kWatchdogSleepDuration);
ASSERT_TRUE(watchdog_->Unregister("test-name-2"));
json = watchdog_->GetWatchdogViolations();
ASSERT_EQ(json.find("test-name-1"), std::string::npos);
Expand All @@ -296,7 +297,7 @@ TEST_F(WatchdogTest, PingInfosAreEvictedAfterMax) {
for (int i = 0; i < 21; i++) {
ASSERT_TRUE(watchdog_->Ping("test-name", std::to_string(i)));
}
SbThreadSleep(kWatchdogMonitorFrequency * 2);
SbThreadSleep(kWatchdogSleepDuration);
std::string json = watchdog_->GetWatchdogViolations();
ASSERT_NE(json, "");
std::unique_ptr<base::Value> violations_map = base::JSONReader::Read(json);
Expand Down Expand Up @@ -329,7 +330,7 @@ TEST_F(WatchdogTest, ViolationsAreEvictedAfterMax) {
ASSERT_TRUE(watchdog_->Register("test-name-4", "test-desc-4",
base::kApplicationStateStarted,
kWatchdogMonitorFrequency));
SbThreadSleep(kWatchdogMonitorFrequency * 2);
SbThreadSleep(kWatchdogSleepDuration);

json = watchdog_->GetWatchdogViolations(false);
ASSERT_NE(json, "");
Expand All @@ -355,7 +356,7 @@ TEST_F(WatchdogTest, ViolationsAreEvictedAfterMax) {
ASSERT_EQ(violations->GetList().size(), 1);

ASSERT_TRUE(watchdog_->Ping("test-name-3"));
SbThreadSleep(kWatchdogMonitorFrequency * 2);
SbThreadSleep(kWatchdogSleepDuration);

json = watchdog_->GetWatchdogViolations();
ASSERT_NE(json, "");
Expand Down Expand Up @@ -387,16 +388,17 @@ TEST_F(WatchdogTest, UpdateStateShouldPreventViolations) {
base::kApplicationStateStarted,
kWatchdogMonitorFrequency));
watchdog_->UpdateState(base::kApplicationStateBlurred);
SbThreadSleep(kWatchdogMonitorFrequency * 2);
SbThreadSleep(kWatchdogSleepDuration);
ASSERT_EQ(watchdog_->GetWatchdogViolations(), "");
ASSERT_TRUE(watchdog_->Unregister("test-name"));
}

TEST_F(WatchdogTest, TimeWaitShouldPreventViolations) {
ASSERT_TRUE(watchdog_->Register(
"test-name", "test-desc", base::kApplicationStateStarted,
kWatchdogMonitorFrequency, kWatchdogMonitorFrequency * 3));
SbThreadSleep(kWatchdogMonitorFrequency * 2);
kWatchdogMonitorFrequency,
kWatchdogSleepDuration + kWatchdogMonitorFrequency));
SbThreadSleep(kWatchdogSleepDuration);
ASSERT_EQ(watchdog_->GetWatchdogViolations(), "");
ASSERT_TRUE(watchdog_->Unregister("test-name"));
}
Expand Down Expand Up @@ -436,7 +438,7 @@ TEST_F(WatchdogTest, UnregisterShouldPreventViolations) {
base::kApplicationStateStarted,
kWatchdogMonitorFrequency));
ASSERT_TRUE(watchdog_->Unregister("test-name"));
SbThreadSleep(kWatchdogMonitorFrequency * 2);
SbThreadSleep(kWatchdogSleepDuration);
ASSERT_EQ(watchdog_->GetWatchdogViolations(), "");
}

Expand All @@ -447,7 +449,7 @@ TEST_F(WatchdogTest, KillSwitchShouldPreventViolations) {
ASSERT_TRUE(watchdog_->Register("test-name", "test-desc",
base::kApplicationStateStarted,
kWatchdogMonitorFrequency));
SbThreadSleep(kWatchdogMonitorFrequency * 2);
SbThreadSleep(kWatchdogSleepDuration);
ASSERT_EQ(watchdog_->GetWatchdogViolations(), "");
ASSERT_TRUE(watchdog_->Unregister("test-name"));
}
Expand All @@ -456,7 +458,7 @@ TEST_F(WatchdogTest, FrequentConsecutiveViolationsShouldNotWrite) {
ASSERT_TRUE(watchdog_->Register("test-name", "test-desc",
base::kApplicationStateStarted,
kWatchdogMonitorFrequency));
SbThreadSleep(kWatchdogMonitorFrequency * 2);
SbThreadSleep(kWatchdogSleepDuration);
std::string write_json = "";
starboard::ScopedFile read_file(watchdog_->GetWatchdogFilePath().c_str(),
kSbFileOpenOnly | kSbFileRead);
Expand All @@ -468,7 +470,7 @@ TEST_F(WatchdogTest, FrequentConsecutiveViolationsShouldNotWrite) {
}
ASSERT_NE(write_json, "");
ASSERT_TRUE(watchdog_->Ping("test-name"));
SbThreadSleep(kWatchdogMonitorFrequency * 2);
SbThreadSleep(kWatchdogSleepDuration);
ASSERT_TRUE(watchdog_->Unregister("test-name"));
std::string no_write_json = "";
starboard::ScopedFile read_file_again(
Expand Down
9 changes: 0 additions & 9 deletions starboard/win/win32/cobalt/configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,4 @@ def GetWebPlatformTestFilters(self):
# Flaky test to be re-enabled after b/271006511 is fixed.
'CookieMonsterTest.PredicateSeesAllCookies',
],
'watchdog_test': [
# TODO(b/292027298): Enable once test failure is fixed.
'WatchdogTest.FrequentConsecutiveViolationsShouldNotWrite'
'WatchdogTest.PingInfosAreEvictedAfterMax',
'WatchdogTest.RedundantViolationsShouldStack',
'WatchdogTest.ViolationsAreEvictedAfterMax',
'WatchdogTest.ViolationsJsonShouldPersistAndBeValid',
'WatchdogTest.ViolationsShouldResetAfterFetch',
],
}

0 comments on commit 5c6c2fd

Please sign in to comment.