Commit 9d23034c authored by Lutz Justen's avatar Lutz Justen Committed by Commit Bot

Fix flakyness in DeviceStatusCollectorTest

DeviceStatusCollector collects resource usage stats every 2 minutes.
The ActivityTimesKeptUntilSubmittedSuccessfully test compared two
full instances of DeviceStatusReportRequest. In one run of the test,
the test failed because the resource usage collection happened right
in between. This CL compares activity times only (aka what the test
is interested in) and removes the full status comparison.

Also fixes an uninteresting mock function call and moves some
functions from public to protected.

BUG=chromium:743061
TEST=out/Release/browser_tests --gtest_filter=DeviceStatusCollectorTest.*

Change-Id: I39d65260794326cae90d57ec583ff28e2d9a9092
Reviewed-on: https://chromium-review.googlesource.com/573901Reviewed-by: default avatarDrew Wilson <atwilson@chromium.org>
Commit-Queue: Lutz Justen <ljusten@chromium.org>
Cr-Commit-Position: refs/heads/master@{#487034}
parent 2be350d5
......@@ -287,6 +287,8 @@ class DeviceStatusCollectorTest : public testing::Test {
std::string() /* kiosk_app_update_url */),
user_data_dir_override_(chrome::DIR_USER_DATA),
update_engine_client_(new chromeos::FakeUpdateEngineClient) {
EXPECT_CALL(*user_manager_, Shutdown()).Times(1);
// Although this is really a unit test which runs in the browser_tests
// binary, it doesn't get the unit setup which normally happens in the unit
// test binary.
......@@ -348,14 +350,6 @@ class DeviceStatusCollectorTest : public testing::Test {
chromeos::LoginState::Initialize();
}
void AddMountPoint(const std::string& mount_point) {
mount_point_map_.insert(DiskMountManager::MountPointMap::value_type(
mount_point,
DiskMountManager::MountPointInfo(
mount_point, mount_point, chromeos::MOUNT_TYPE_DEVICE,
chromeos::disks::MOUNT_CONDITION_NONE)));
}
~DeviceStatusCollectorTest() override {
chromeos::LoginState::Shutdown();
chromeos::CrasAudioHandler::Shutdown();
......@@ -378,6 +372,14 @@ class DeviceStatusCollectorTest : public testing::Test {
settings_helper_.RestoreProvider();
}
protected:
void AddMountPoint(const std::string& mount_point) {
mount_point_map_.insert(DiskMountManager::MountPointMap::value_type(
mount_point, DiskMountManager::MountPointInfo(
mount_point, mount_point, chromeos::MOUNT_TYPE_DEVICE,
chromeos::disks::MOUNT_CONDITION_NONE)));
}
void RestartStatusCollector(
const policy::DeviceStatusCollector::VolumeInfoFetcher& volume_info,
const policy::DeviceStatusCollector::CPUStatisticsFetcher& cpu_stats,
......@@ -479,7 +481,6 @@ class DeviceStatusCollectorTest : public testing::Test {
manager->GetAutoLaunchAppRequiredPlatformVersion());
}
protected:
// Convenience method.
int64_t ActivePeriodMilliseconds() {
return policy::DeviceStatusCollector::kIdlePollIntervalSeconds * 1000;
......@@ -762,8 +763,7 @@ TEST_F(DeviceStatusCollectorTest, ActivityCrossingMidnight) {
TEST_F(DeviceStatusCollectorTest, ActivityTimesKeptUntilSubmittedSuccessfully) {
ui::IdleState test_states[] = {
ui::IDLE_STATE_ACTIVE,
ui::IDLE_STATE_ACTIVE,
ui::IDLE_STATE_ACTIVE, ui::IDLE_STATE_ACTIVE,
};
// Make sure CPU stats get reported in time. If we don't run this, the second
// call to |GetStatus()| will contain these stats, but the first call won't
......@@ -778,10 +778,14 @@ TEST_F(DeviceStatusCollectorTest, ActivityTimesKeptUntilSubmittedSuccessfully) {
GetActiveMilliseconds(device_status_));
em::DeviceStatusReportRequest first_status(device_status_);
// The collector returns the same status again.
// The collector returns the same activity times again.
GetStatus();
EXPECT_EQ(first_status.SerializeAsString(),
device_status_.SerializeAsString());
int period_count = first_status.active_period_size();
EXPECT_EQ(period_count, device_status_.active_period_size());
for (int n = 0; n < period_count; ++n) {
EXPECT_EQ(first_status.active_period(n).SerializeAsString(),
device_status_.active_period(n).SerializeAsString());
}
// After indicating a successful submit, the submitted status gets cleared,
// but what got collected meanwhile sticks around.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment