Commit 8b9dcdb4 authored by mtomasz's avatar mtomasz Committed by Commit bot

Fix a queue for FSP API.

Due to a bug the queue was running more tasks than maximum capacity of the
queue. That made the browser tests flaky.

Unfortunatley this case wasn't covered by unit tests. This CL adds it.

TEST=None
BUG=None

Review URL: https://codereview.chromium.org/925873002

Cr-Commit-Position: refs/heads/master@{#316191}
parent 27abec11
......@@ -75,11 +75,12 @@ void Queue::Remove(size_t token) {
}
void Queue::MaybeRun() {
if (executed_.size() == max_in_parallel_ || !pending_.size()) {
if (executed_.size() + completed_.size() == max_in_parallel_ ||
!pending_.size()) {
return;
}
DCHECK_GT(max_in_parallel_, executed_.size());
DCHECK_GT(max_in_parallel_, executed_.size() + completed_.size());
Task task = pending_.front();
pending_.pop_front();
......
......@@ -113,6 +113,30 @@ TEST_F(FileSystemProviderQueueTest, Enqueue_OneAtOnce) {
EXPECT_EQ(0, third_abort_counter);
}
TEST_F(FileSystemProviderQueueTest, Enqueue_WhilePreviousNotRemoved) {
Queue queue(1);
const size_t first_token = queue.NewToken();
int first_counter = 0;
int first_abort_counter = 0;
queue.Enqueue(first_token,
base::Bind(&OnRun, &first_counter, &first_abort_counter));
base::RunLoop().RunUntilIdle();
queue.Complete(first_token);
// Enqueuing a new task must not start it, once the queue is filled with a
// completed task.
const size_t second_token = queue.NewToken();
int second_counter = 0;
int second_abort_counter = 0;
queue.Enqueue(second_token,
base::Bind(&OnRun, &second_counter, &second_abort_counter));
base::RunLoop().RunUntilIdle();
EXPECT_EQ(0, second_counter);
EXPECT_EQ(0, second_abort_counter);
}
TEST_F(FileSystemProviderQueueTest, Enqueue_MultipleAtOnce) {
Queue queue(2);
const size_t first_token = queue.NewToken();
......
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