Commit a9696d29 authored by Etienne Pierre-doray's avatar Etienne Pierre-doray Committed by Commit Bot

[ThreadPool]: Use mock time in priority queue unittests. Take 2.

To avoid having 2 tasks with same queue_time, each PushTask is preceded by
a FastForward().
In previous CL 1778925, I put FastForward at the wrong place. This moves
it to right before PushTask().

Bug: 998477
Change-Id: Ifb87e46d364b3bc3e4d555f11f09ad3a34ce4b19
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1784627Reviewed-by: default avatarGabriel Charette <gab@chromium.org>
Commit-Queue: Etienne Pierre-Doray <etiennep@chromium.org>
Cr-Commit-Position: refs/heads/master@{#693186}
parent 36db1e09
......@@ -24,15 +24,6 @@ namespace internal {
namespace {
scoped_refptr<TaskSource> MakeSequenceWithTraitsAndTask(
const TaskTraits& traits) {
scoped_refptr<Sequence> sequence = MakeRefCounted<Sequence>(
traits, nullptr, TaskSourceExecutionMode::kParallel);
sequence->BeginTransaction().PushTask(
Task(FROM_HERE, DoNothing(), TimeDelta()));
return sequence;
}
class PriorityQueueWithSequencesTest : public testing::Test {
protected:
void ExpectNumSequences(size_t num_best_effort,
......@@ -46,14 +37,26 @@ class PriorityQueueWithSequencesTest : public testing::Test {
num_user_blocking);
}
void Push(scoped_refptr<TaskSource> task_source) {
scoped_refptr<TaskSource> MakeSequenceWithTraitsAndTask(
const TaskTraits& traits) {
// FastForward time to ensure that queue order between task sources is well
// defined.
task_environment.FastForwardBy(TimeDelta::FromMicroseconds(1));
scoped_refptr<Sequence> sequence = MakeRefCounted<Sequence>(
traits, nullptr, TaskSourceExecutionMode::kParallel);
sequence->BeginTransaction().PushTask(
Task(FROM_HERE, DoNothing(), TimeDelta()));
return sequence;
}
void Push(scoped_refptr<TaskSource> task_source) {
pq.Push(TransactionWithRegisteredTaskSource::FromTaskSource(
RegisteredTaskSource::CreateForTesting(std::move(task_source))));
}
test::TaskEnvironment task_environment{
test::ScopedTaskEnvironment::TimeSource::MOCK_TIME};
scoped_refptr<TaskSource> sequence_a = MakeSequenceWithTraitsAndTask(
TaskTraits(ThreadPool(), TaskPriority::USER_VISIBLE));
SequenceSortKey sort_key_a = sequence_a->BeginTransaction().GetSortKey();
......@@ -71,8 +74,6 @@ class PriorityQueueWithSequencesTest : public testing::Test {
SequenceSortKey sort_key_d = sequence_d->BeginTransaction().GetSortKey();
PriorityQueue pq;
test::TaskEnvironment task_environment{
test::ScopedTaskEnvironment::TimeSource::MOCK_TIME};
};
} // namespace
......
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