From 62582877f6b58c24c28a1059093c487510983620 Mon Sep 17 00:00:00 2001 From: Marco Bubke Date: Wed, 27 Jan 2021 14:13:42 +0100 Subject: [PATCH] QmlDesigner: Fix flacky test AsynchronousImageCache.WaitForFinished Change-Id: I94afa8ec2925b85f5dbf44e7b2ad5db484f48148 Reviewed-by: Thomas Hartmann --- .../designercore/imagecache/asynchronousimagecache.cpp | 4 ++-- .../designercore/include/asynchronousimagecache.h | 3 ++- tests/unit/unittest/asynchronousimagecache-test.cpp | 7 ++++++- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/plugins/qmldesigner/designercore/imagecache/asynchronousimagecache.cpp b/src/plugins/qmldesigner/designercore/imagecache/asynchronousimagecache.cpp index 7dd228329b7..f1d4f4cfb6d 100644 --- a/src/plugins/qmldesigner/designercore/imagecache/asynchronousimagecache.cpp +++ b/src/plugins/qmldesigner/designercore/imagecache/asynchronousimagecache.cpp @@ -158,8 +158,8 @@ std::tuple AsynchronousImageCache::getEntry if (m_entries.empty()) return {false, Entry{}}; - Entry entry = m_entries.back(); - m_entries.pop_back(); + Entry entry = m_entries.front(); + m_entries.pop_front(); return {true, entry}; } diff --git a/src/plugins/qmldesigner/designercore/include/asynchronousimagecache.h b/src/plugins/qmldesigner/designercore/include/asynchronousimagecache.h index 00132139be7..271dac16203 100644 --- a/src/plugins/qmldesigner/designercore/include/asynchronousimagecache.h +++ b/src/plugins/qmldesigner/designercore/include/asynchronousimagecache.h @@ -28,6 +28,7 @@ #include "asynchronousimagecacheinterface.h" #include +#include #include #include #include @@ -117,7 +118,7 @@ private: void wait(); private: - std::vector m_entries; + std::deque m_entries; mutable std::mutex m_mutex; std::condition_variable m_condition; std::thread m_backgroundThread; diff --git a/tests/unit/unittest/asynchronousimagecache-test.cpp b/tests/unit/unittest/asynchronousimagecache-test.cpp index be60a412416..bd73d5f77de 100644 --- a/tests/unit/unittest/asynchronousimagecache-test.cpp +++ b/tests/unit/unittest/asynchronousimagecache-test.cpp @@ -323,7 +323,11 @@ TEST_F(AsynchronousImageCache, AfterCleanNewJobsWorks) 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})); cache.requestImage("/path/to/Component1.qml", mockCaptureCallback.AsStdFunction(), @@ -334,6 +338,7 @@ TEST_F(AsynchronousImageCache, WaitForFinished) EXPECT_CALL(mockCaptureCallback, Call(_)).Times(2); + waitInThread.wait(); cache.waitForFinished(); }