Bug 1520241 - Avoid slow sleeps on Windows in TestSPSCQueue.exe r=padenot

Differential Revision: https://phabricator.services.mozilla.com/D16583

--HG--
extra : moz-landing-system : lando
This commit is contained in:
David Major 2019-01-16 12:04:13 +00:00
parent c89256299a
commit d3a71fc36a

View File

@ -13,6 +13,10 @@
#include <memory>
#include <string>
#ifdef _WIN32
#include <windows.h>
#endif
using namespace mozilla;
/* Generate a monotonically increasing sequence of numbers. */
@ -75,6 +79,17 @@ void TestRing(int capacity) {
}
}
void Delay() {
// On Windows, the timer resolution is so bad that, even if we used
// `timeBeginPeriod(1)`, any nonzero sleep from the test's inner loops
// would make this program take far too long.
#ifdef _WIN32
Sleep(0);
#else
std::this_thread::sleep_for(std::chrono::microseconds(10));
#endif
}
template <typename T>
void TestRingMultiThread(int capacity) {
SPSCQueue<T> buf(capacity);
@ -87,7 +102,7 @@ void TestRingMultiThread(int capacity) {
SequenceGenerator<T> gen;
while (iterations--) {
std::this_thread::sleep_for(std::chrono::microseconds(10));
Delay();
gen.Get(inBuffer.get(), BLOCK_SIZE);
int rv = buf.Enqueue(inBuffer.get(), BLOCK_SIZE);
MOZ_RELEASE_ASSERT(rv <= BLOCK_SIZE);
@ -100,7 +115,7 @@ void TestRingMultiThread(int capacity) {
int remaining = 1002;
while (remaining--) {
std::this_thread::sleep_for(std::chrono::microseconds(10));
Delay();
int rv = buf.Dequeue(outBuffer.get(), BLOCK_SIZE);
MOZ_RELEASE_ASSERT(rv <= BLOCK_SIZE);
checker.Check(outBuffer.get(), rv);