AU/unittest: fix to OmahaResponseHandlerAction unit tests
The said class uses a fixed named file for communicating data (in this
case, a deadline marker) to Chrome, which causes unit tests to fail when
run in parallel. This change makes this file parametric for testing
purposes, allowing the tests to be run in parallel.
Note that we only override the file name for tests that actually examine
the file. For other invocations there may still be race conditions when
writing to the marker file, but they should not affect the outcome of
the tests.
BUG=chromium:236465
TEST=Tests successful
Change-Id: Ieb2a3ef1b4d9c5d5d2e06cf8e281eb832b2a9ff8
Reviewed-on: https://gerrit.chromium.org/gerrit/62825
Tested-by: Gilad Arnold <garnold@chromium.org>
Reviewed-by: Chris Sosa <sosa@chromium.org>
Commit-Queue: Gilad Arnold <garnold@chromium.org>
diff --git a/omaha_response_handler_action.cc b/omaha_response_handler_action.cc
index 21832c5..923c62d 100644
--- a/omaha_response_handler_action.cc
+++ b/omaha_response_handler_action.cc
@@ -26,7 +26,15 @@
SystemState* system_state)
: system_state_(system_state),
got_no_update_response_(false),
- key_path_(DeltaPerformer::kUpdatePayloadPublicKeyPath) {}
+ key_path_(DeltaPerformer::kUpdatePayloadPublicKeyPath),
+ deadline_file_(kDeadlineFile) {}
+
+OmahaResponseHandlerAction::OmahaResponseHandlerAction(
+ SystemState* system_state, const string& deadline_file)
+ : system_state_(system_state),
+ got_no_update_response_(false),
+ key_path_(DeltaPerformer::kUpdatePayloadPublicKeyPath),
+ deadline_file_(deadline_file) {}
void OmahaResponseHandlerAction::PerformAction() {
CHECK(HasInputObject());
@@ -104,10 +112,10 @@
// file. Ideally, we would include this information in D-Bus's GetStatus
// method and UpdateStatus signal. A potential issue is that update_engine may
// be unresponsive during an update download.
- utils::WriteFile(kDeadlineFile,
+ utils::WriteFile(deadline_file_.c_str(),
response.deadline.data(),
response.deadline.size());
- chmod(kDeadlineFile, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
+ chmod(deadline_file_.c_str(), S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
completer.set_code(kErrorCodeSuccess);
}