Commit 8ce4050d authored by Finnur Thorarinsson's avatar Finnur Thorarinsson Committed by Commit Bot

[Android] Photo Picker: Deflake 2 DecoderServiceHost tests.

The order of decoding is determined by a few things, which
(if all else is equal) falls back on creation time (Date()
timestamp) to enforce FIFO decoding.

However, the granularity of that is milliseconds, so back to back
requests occasionally have the same timestamp and then the decoding
order is no longer deterministic, which messes up the tests.

This CL removes the timestamp and replaces it with an ordinal,
to ensure FIFO order for identical requests.

Bug: 1054520, 1054502, 656015
Change-Id: Ia745548619f866b53dc7e9071c191eea6d4d1fbe
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2116055
Auto-Submit: Finnur Thorarinsson <finnur@chromium.org>
Reviewed-by: default avatarTheresa  <twellington@chromium.org>
Commit-Queue: Finnur Thorarinsson <finnur@chromium.org>
Cr-Commit-Position: refs/heads/master@{#753155}
parent 4853f5b2
......@@ -35,7 +35,6 @@ import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.Date;
import java.util.Iterator;
import java.util.List;
import java.util.PriorityQueue;
......@@ -78,6 +77,9 @@ public class DecoderServiceHost
// A worker task for asynchronously handling video decode requests.
private DecodeVideoTask mWorkerTask;
// Keeps track of the last decoding ordinal issued.
static int sLastDecodingOrdinal = 0;
// A callback to use for testing to see if decoder is ready.
static DecoderStatusCallback sStatusCallbackForTesting;
......@@ -151,8 +153,9 @@ public class DecoderServiceHost
// ignored for non-videos.
final boolean mFirstFrame;
// When the request was added.
final Date mCreateTime;
// An ordinal used to enforce FIFO decoding, in the case where all other things are equal
// (when it comes to determining which record to decode first).
private int mRequestOrdinal;
// The callback to use to communicate the results of the decoding.
final ImagesDecodedCallback mCallback;
......@@ -168,7 +171,7 @@ public class DecoderServiceHost
mFullWidth = fullWidth;
mFileType = fileType;
mFirstFrame = firstFrame;
mCreateTime = new Date();
mRequestOrdinal = sLastDecodingOrdinal++;
mCallback = callback;
}
}
......@@ -190,7 +193,7 @@ public class DecoderServiceHost
// The two requests share the same file type, or are identical video requests (both
// requesting first frame or both requesting additional frames) so they can be considered
// equal. Go with first in first out.
return r1.mCreateTime.compareTo(r2.mCreateTime);
return r1.mRequestOrdinal - r2.mRequestOrdinal;
};
// A queue of pending requests.
......
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