Reduce clock skew in flaky duration tests
There are three changes here that should help reduce the amount of duration test failures caused by clock skew. First, we reported some skew when the test expected playback to start immediately after loading the license. However, with round-off, this could easily be more than 1 second. So this does not warrent even a warning. Second, the fake and real clocks were only synced after computing how long to sleep. This is fixed by moving SleepUntil to the TestSleep class and having it sync before computing the delta and after doing the sleep. Third, I am guessing that some failures due to unexpected lenience were caused by the rental or playback clock being started at the end of signing the license or the end of the first decrypt instead of the beginning. We work around this by recording how long these operations take, and then adding this extra time at the end of the check for FailDecrypt. Bug: 275003529 Bug: 279249646 Bug: 207500749 Test: Luci tests Change-Id: I6a973565edfbebca53ee7f239b4b93f8f73d1e0a
This commit is contained in:
@@ -14,6 +14,7 @@
|
||||
#endif
|
||||
|
||||
#include <errno.h>
|
||||
#include <inttypes.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
@@ -53,6 +54,18 @@ void TestSleep::Sleep(unsigned int seconds) {
|
||||
if (callback_ != nullptr) callback_->ElapseTime(milliseconds);
|
||||
}
|
||||
|
||||
void TestSleep::SleepUntil(int64_t desired_time) {
|
||||
SyncFakeClock();
|
||||
const int64_t now = Clock().GetCurrentTime();
|
||||
if (desired_time < now) {
|
||||
LOGE("Test Clock skew sleeping from time %" PRId64 " to %" PRId64, now,
|
||||
desired_time);
|
||||
return;
|
||||
}
|
||||
const unsigned int sleep_time = static_cast<unsigned int>(desired_time - now);
|
||||
TestSleep::Sleep(sleep_time);
|
||||
}
|
||||
|
||||
void TestSleep::SyncFakeClock() {
|
||||
// Syncing can be done by sleeping 0 seconds.
|
||||
Sleep(0);
|
||||
|
||||
Reference in New Issue
Block a user