Commit c2843fe1 authored by Sigurdur Asgeirsson's avatar Sigurdur Asgeirsson Committed by Commit Bot

RC: Use ScopedTimeClockOverrides to avoid Sleep and test flakes.

Bug: 755840
Change-Id: I4f693945cb65b7be8360636307dc165a7c317f4f
Reviewed-on: https://chromium-review.googlesource.com/1104868
Commit-Queue: Sigurður Ásgeirsson <siggi@chromium.org>
Reviewed-by: default avatarFrançois Doray <fdoray@chromium.org>
Cr-Commit-Position: refs/heads/master@{#568433}
parent 74271034
......@@ -10,6 +10,7 @@
#include "base/test/trace_event_analyzer.h"
#include "base/threading/platform_thread.h"
#include "base/time/time.h"
#include "base/time/time_override.h"
#include "base/trace_event/memory_dump_request_args.h"
#include "build/build_config.h"
#include "mojo/public/cpp/bindings/binding.h"
......@@ -305,6 +306,17 @@ TEST_F(CoordinatorImplTest, SeveralClients) {
TEST_F(CoordinatorImplTest, QueuedRequest) {
base::RunLoop run_loop;
// Override TimeTicks::Now with a timer that has extra_time added.
// This variable to be static as the lambda below has to convert to a function
// pointer rather than a functor.
static base::TimeDelta extra_time;
base::subtle::ScopedTimeClockOverrides time_override(
nullptr,
[]() {
return base::subtle::TimeTicksNowIgnoringOverride() + extra_time;
},
nullptr);
NiceMock<MockClientProcess> client_process_1(this, 1,
mojom::ProcessType::BROWSER);
NiceMock<MockClientProcess> client_process_2(this);
......@@ -316,9 +328,9 @@ TEST_F(CoordinatorImplTest, QueuedRequest) {
.WillRepeatedly(Invoke(
[](const MemoryDumpRequestArgs& args,
MockClientProcess::RequestChromeMemoryDumpCallback& callback) {
// Delay the response here to make sure the start times are strictly
// increasing.
base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds(10));
// Skip the wall clock time-ticks forward to make sure start_time
// is strictly increasing.
extra_time += base::TimeDelta::FromMilliseconds(10);
MemoryDumpArgs dump_args{MemoryDumpLevelOfDetail::DETAILED};
auto pmd = std::make_unique<ProcessMemoryDump>(dump_args);
std::move(callback).Run(true, args.dump_guid, std::move(pmd));
......
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