Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cherry pick PR #1036: Increase sleep to address Watchdog test flakiness. #1065

Merged
merged 1 commit into from
Jul 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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',
],
}