forked from qt-creator/qt-creator
QmlDesigner: Fix flacky test AsynchronousImageCache.WaitForFinished
Change-Id: I94afa8ec2925b85f5dbf44e7b2ad5db484f48148 Reviewed-by: Thomas Hartmann <thomas.hartmann@qt.io>
This commit is contained in:
@@ -158,8 +158,8 @@ std::tuple<bool, AsynchronousImageCache::Entry> AsynchronousImageCache::getEntry
|
|||||||
if (m_entries.empty())
|
if (m_entries.empty())
|
||||||
return {false, Entry{}};
|
return {false, Entry{}};
|
||||||
|
|
||||||
Entry entry = m_entries.back();
|
Entry entry = m_entries.front();
|
||||||
m_entries.pop_back();
|
m_entries.pop_front();
|
||||||
|
|
||||||
return {true, entry};
|
return {true, entry};
|
||||||
}
|
}
|
||||||
|
@@ -28,6 +28,7 @@
|
|||||||
#include "asynchronousimagecacheinterface.h"
|
#include "asynchronousimagecacheinterface.h"
|
||||||
|
|
||||||
#include <condition_variable>
|
#include <condition_variable>
|
||||||
|
#include <deque>
|
||||||
#include <functional>
|
#include <functional>
|
||||||
#include <mutex>
|
#include <mutex>
|
||||||
#include <thread>
|
#include <thread>
|
||||||
@@ -117,7 +118,7 @@ private:
|
|||||||
void wait();
|
void wait();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::vector<Entry> m_entries;
|
std::deque<Entry> m_entries;
|
||||||
mutable std::mutex m_mutex;
|
mutable std::mutex m_mutex;
|
||||||
std::condition_variable m_condition;
|
std::condition_variable m_condition;
|
||||||
std::thread m_backgroundThread;
|
std::thread m_backgroundThread;
|
||||||
|
@@ -323,7 +323,11 @@ TEST_F(AsynchronousImageCache, AfterCleanNewJobsWorks)
|
|||||||
|
|
||||||
TEST_F(AsynchronousImageCache, WaitForFinished)
|
TEST_F(AsynchronousImageCache, WaitForFinished)
|
||||||
{
|
{
|
||||||
ON_CALL(mockStorage, fetchImage(_, _))
|
ON_CALL(mockStorage, fetchImage(Eq("/path/to/Component1.qml"), _)).WillByDefault([&](auto, auto) {
|
||||||
|
waitInThread.notify();
|
||||||
|
return QmlDesigner::ImageCacheStorageInterface::ImageEntry{image1, true};
|
||||||
|
});
|
||||||
|
ON_CALL(mockStorage, fetchImage(Eq("/path/to/Component2.qml"), _))
|
||||||
.WillByDefault(Return(QmlDesigner::ImageCacheStorageInterface::ImageEntry{image1, true}));
|
.WillByDefault(Return(QmlDesigner::ImageCacheStorageInterface::ImageEntry{image1, true}));
|
||||||
cache.requestImage("/path/to/Component1.qml",
|
cache.requestImage("/path/to/Component1.qml",
|
||||||
mockCaptureCallback.AsStdFunction(),
|
mockCaptureCallback.AsStdFunction(),
|
||||||
@@ -334,6 +338,7 @@ TEST_F(AsynchronousImageCache, WaitForFinished)
|
|||||||
|
|
||||||
EXPECT_CALL(mockCaptureCallback, Call(_)).Times(2);
|
EXPECT_CALL(mockCaptureCallback, Call(_)).Times(2);
|
||||||
|
|
||||||
|
waitInThread.wait();
|
||||||
cache.waitForFinished();
|
cache.waitForFinished();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user