* commit 'c1799e33c60e84d6f4c0cb0beb0f62b6f87600cf': metricsd: Fix race condition in the tests.
This commit is contained in:
commit
4a014d408d
3 changed files with 8 additions and 5 deletions
|
@ -142,10 +142,10 @@ class MetricsLibrary : public MetricsLibraryInterface {
|
|||
bool* result);
|
||||
|
||||
// Time at which we last checked if metrics were enabled.
|
||||
static time_t cached_enabled_time_;
|
||||
time_t cached_enabled_time_;
|
||||
|
||||
// Cached state of whether or not metrics were enabled.
|
||||
static bool cached_enabled_;
|
||||
bool cached_enabled_;
|
||||
|
||||
base::FilePath uma_events_file_;
|
||||
base::FilePath consent_file_;
|
||||
|
|
|
@ -53,9 +53,6 @@ static const char *kCrosEventNames[] = {
|
|||
"TPM.EarlyResetDuringCommand", // 12
|
||||
};
|
||||
|
||||
time_t MetricsLibrary::cached_enabled_time_ = 0;
|
||||
bool MetricsLibrary::cached_enabled_ = false;
|
||||
|
||||
MetricsLibrary::MetricsLibrary() {}
|
||||
MetricsLibrary::~MetricsLibrary() {}
|
||||
|
||||
|
@ -140,11 +137,15 @@ void MetricsLibrary::Init() {
|
|||
base::FilePath dir = base::FilePath(metrics::kMetricsDirectory);
|
||||
uma_events_file_ = dir.Append(metrics::kMetricsEventsFileName);
|
||||
consent_file_ = dir.Append(metrics::kConsentFileName);
|
||||
cached_enabled_ = false;
|
||||
cached_enabled_time_ = 0;
|
||||
}
|
||||
|
||||
void MetricsLibrary::InitForTest(const base::FilePath& metrics_directory) {
|
||||
uma_events_file_ = metrics_directory.Append(metrics::kMetricsEventsFileName);
|
||||
consent_file_ = metrics_directory.Append(metrics::kConsentFileName);
|
||||
cached_enabled_ = false;
|
||||
cached_enabled_time_ = 0;
|
||||
}
|
||||
|
||||
bool MetricsLibrary::SendToUMA(const std::string& name,
|
||||
|
|
|
@ -42,6 +42,8 @@ class UploadServiceTest : public testing::Test {
|
|||
chromeos_metrics::PersistentInteger::SetMetricsDirectory(
|
||||
dir_.path().value());
|
||||
metrics_lib_.InitForTest(dir_.path());
|
||||
ASSERT_EQ(0, base::WriteFile(
|
||||
dir_.path().Append(metrics::kConsentFileName), "", 0));
|
||||
upload_service_.reset(new UploadService(new MockSystemProfileSetter(),
|
||||
&metrics_lib_, "", true));
|
||||
|
||||
|
|
Loading…
Reference in a new issue