Don't apply backoff time if the last compilation succeeded.
This change is supposed to be a no-op change, but it makes the logic
more straghtforward and therefore avoids potential pitfalls that can be
introduced by future changes.
Bug: 241512616
Change-Id: I4623b1f2cc1169d6405d850564d33a2f8c697524
Test: Presubmit
diff --git a/odrefresh/odr_compilation_log.cc b/odrefresh/odr_compilation_log.cc
index 9c50817..0c8dda8 100644
--- a/odrefresh/odr_compilation_log.cc
+++ b/odrefresh/odr_compilation_log.cc
@@ -185,6 +185,12 @@
return true;
}
+ // The backoff time is for avoiding too many failed attempts. It should not be applied if the last
+ // compilation was successful.
+ if (entries_.back().exit_code == ExitCode::kCompilationSuccess) {
+ return true;
+ }
+
if (trigger == OdrMetrics::Trigger::kApexVersionMismatch ||
trigger == OdrMetrics::Trigger::kDexFilesChanged) {
// Things have changed since the last run.
diff --git a/odrefresh/odr_compilation_log_test.cc b/odrefresh/odr_compilation_log_test.cc
index 46cea79..f28d849 100644
--- a/odrefresh/odr_compilation_log_test.cc
+++ b/odrefresh/odr_compilation_log_test.cc
@@ -109,7 +109,7 @@
/*apex_version=*/1,
/*last_update_millis=*/762,
OdrMetrics::Trigger::kApexVersionMismatch,
- ExitCode::kCompilationSuccess);
+ ExitCode::kCompilationFailed);
ASSERT_TRUE(ocl.ShouldAttemptCompile(OdrMetrics::Trigger::kApexVersionMismatch));
ASSERT_TRUE(ocl.ShouldAttemptCompile(OdrMetrics::Trigger::kDexFilesChanged));
ASSERT_FALSE(ocl.ShouldAttemptCompile(OdrMetrics::Trigger::kUnknown));
@@ -180,8 +180,8 @@
OdrMetrics::Trigger::kApexVersionMismatch,
start_time,
ExitCode::kCompilationSuccess);
- ASSERT_FALSE(ocl.ShouldAttemptCompile(OdrMetrics::Trigger::kUnknown, start_time));
- ASSERT_FALSE(
+ ASSERT_TRUE(ocl.ShouldAttemptCompile(OdrMetrics::Trigger::kUnknown, start_time));
+ ASSERT_TRUE(
ocl.ShouldAttemptCompile(OdrMetrics::Trigger::kUnknown, start_time + kSecondsPerDay / 4));
ASSERT_TRUE(
ocl.ShouldAttemptCompile(OdrMetrics::Trigger::kUnknown, start_time + kSecondsPerDay / 2));
@@ -382,7 +382,7 @@
kLastUpdateMillis,
OdrMetrics::Trigger::kApexVersionMismatch,
start_time,
- ExitCode::kCompilationSuccess);
+ ExitCode::kCompilationFailed);
ASSERT_FALSE(ocl.ShouldAttemptCompile(OdrMetrics::Trigger::kUnknown, start_time));
}
}