UnitTest: Fix or disable some flacky tests

If we get better tools we can come back and look again into it.

Change-Id: I8ded8f9831b0c46c09e15d283a6298ad09aaaeb6
Reviewed-by: Thomas Hartmann <thomas.hartmann@qt.io>
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
This commit is contained in:
Marco Bubke
2023-09-04 16:30:31 +02:00
parent 4978cbc5f6
commit 37c0737844
2 changed files with 25 additions and 9 deletions

View File

@@ -15,11 +15,11 @@ class AsynchronousExplicitImageCache : public testing::Test
protected:
Notification notification;
Notification waitInThread;
NiceMock<MockImageCacheStorage> mockStorage;
NiceMock<MockFunction<void(QmlDesigner::ImageCache::AbortReason)>> mockAbortCallback;
NiceMock<MockFunction<void(QmlDesigner::ImageCache::AbortReason)>> mockAbortCallback2;
NiceMock<MockFunction<void(const QImage &image)>> mockCaptureCallback;
NiceMock<MockFunction<void(const QImage &image)>> mockCaptureCallback2;
NiceMock<MockImageCacheStorage> mockStorage;
QmlDesigner::AsynchronousExplicitImageCache cache{mockStorage};
QImage image1{10, 10, QImage::Format_ARGB32};
QImage midSizeImage1{5, 5, QImage::Format_ARGB32};
@@ -111,7 +111,8 @@ TEST_F(AsynchronousExplicitImageCache, request_mid_size_image_fetches_mid_size_i
notification.wait();
}
TEST_F(AsynchronousExplicitImageCache, request_mid_size_image_calls_capture_callback_with_image_from_storage)
TEST_F(AsynchronousExplicitImageCache,
request_mid_size_image_calls_capture_callback_with_image_from_storage)
{
ON_CALL(mockStorage, fetchMidSizeImage(Eq("/path/to/Component.qml"), _))
.WillByDefault(Return(QmlDesigner::ImageCacheStorageInterface::ImageEntry{midSizeImage1}));
@@ -140,7 +141,8 @@ TEST_F(AsynchronousExplicitImageCache, request_mid_size_image_calls_abort_callba
notification.wait();
}
TEST_F(AsynchronousExplicitImageCache, request_mid_size_image_calls_abort_callback_without_mid_size_image)
TEST_F(AsynchronousExplicitImageCache,
request_mid_size_image_calls_abort_callback_without_mid_size_image)
{
ON_CALL(mockStorage, fetchMidSizeImage(Eq("/path/to/Component.qml"), _))
.WillByDefault(Return(QmlDesigner::ImageCacheStorageInterface::ImageEntry{QImage{}}));
@@ -168,7 +170,8 @@ TEST_F(AsynchronousExplicitImageCache, request_small_image_fetches_small_image_f
notification.wait();
}
TEST_F(AsynchronousExplicitImageCache, request_small_image_calls_capture_callback_with_image_from_storage)
TEST_F(AsynchronousExplicitImageCache,
request_small_image_calls_capture_callback_with_image_from_storage)
{
ON_CALL(mockStorage, fetchSmallImage(Eq("/path/to/Component.qml"), _))
.WillByDefault(Return(QmlDesigner::ImageCacheStorageInterface::ImageEntry{smallImage1}));
@@ -211,7 +214,7 @@ TEST_F(AsynchronousExplicitImageCache, request_small_image_calls_abort_callback_
notification.wait();
}
TEST_F(AsynchronousExplicitImageCache, clean_removes_entries)
TEST_F(AsynchronousExplicitImageCache, DISABLED_clean_removes_entries)
{
ON_CALL(mockStorage, fetchSmallImage(_, _)).WillByDefault([&](Utils::SmallStringView, auto) {
return QmlDesigner::ImageCacheStorageInterface::ImageEntry{smallImage1};
@@ -219,8 +222,10 @@ TEST_F(AsynchronousExplicitImageCache, clean_removes_entries)
ON_CALL(mockCaptureCallback2, Call(_)).WillByDefault([&](auto) { waitInThread.wait(); });
cache.requestSmallImage("/path/to/Component1.qml",
mockCaptureCallback2.AsStdFunction(),
mockAbortCallback.AsStdFunction());
mockAbortCallback2.AsStdFunction());
EXPECT_CALL(mockAbortCallback, Call(Eq(QmlDesigner::ImageCache::AbortReason::Abort)))
.WillOnce([&](auto) { notification.notify(); });
EXPECT_CALL(mockCaptureCallback, Call(_)).Times(0);
cache.requestSmallImage("/path/to/Component3.qml",
@@ -228,26 +233,32 @@ TEST_F(AsynchronousExplicitImageCache, clean_removes_entries)
mockAbortCallback.AsStdFunction());
cache.clean();
waitInThread.notify();
notification.wait();
}
TEST_F(AsynchronousExplicitImageCache, clean_calls_abort)
{
QmlDesigner::AsynchronousExplicitImageCache cache{mockStorage};
ON_CALL(mockStorage, fetchSmallImage(Eq("/path/to/Component1.qml"), _))
.WillByDefault([&](Utils::SmallStringView, auto) {
notification.notify();
waitInThread.wait();
return QmlDesigner::ImageCacheStorageInterface::ImageEntry{smallImage1};
});
cache.requestSmallImage("/path/to/Component1.qml",
mockCaptureCallback.AsStdFunction(),
mockAbortCallback2.AsStdFunction());
notification.wait();
cache.requestSmallImage("/path/to/Component2.qml",
mockCaptureCallback.AsStdFunction(),
mockAbortCallback.AsStdFunction());
EXPECT_CALL(mockAbortCallback, Call(Eq(QmlDesigner::ImageCache::AbortReason::Abort)));
EXPECT_CALL(mockAbortCallback, Call(Eq(QmlDesigner::ImageCache::AbortReason::Abort)))
.WillOnce([&](auto) { notification.notify(); });
cache.clean();
waitInThread.notify();
notification.wait();
}
TEST_F(AsynchronousExplicitImageCache, after_clean_new_jobs_works)
@@ -268,9 +279,10 @@ TEST_F(AsynchronousExplicitImageCache, after_clean_new_jobs_works)
TEST_F(AsynchronousExplicitImageCache, request_image_with_extra_id_fetches_image_from_storage)
{
ON_CALL(mockAbortCallback, Call(_)).WillByDefault([&](auto) { notification.notify(); });
EXPECT_CALL(mockStorage, fetchImage(Eq("/path/to/Component.qml+extraId1"), _))
.WillRepeatedly([&](Utils::SmallStringView, auto) {
notification.notify();
return QmlDesigner::ImageCacheStorageInterface::ImageEntry{};
});

View File

@@ -124,8 +124,12 @@ TEST_F(AsynchronousImageFactory, request_image_request_image_from_collector_if_f
TEST_F(AsynchronousImageFactory, clean_removes_entries)
{
EXPECT_CALL(collectorMock, start(Eq("/path/to/Component1.qml"), _, _, _, _))
.WillRepeatedly([&](auto, auto, auto, auto, auto) { waitInThread.wait(); });
.WillRepeatedly([&](auto, auto, auto, auto, auto) {
notification.notify();
waitInThread.wait();
});
factory.generate("/path/to/Component1.qml");
notification.wait();
EXPECT_CALL(collectorMock, start(Eq("/path/to/Component3.qml"), _, _, _, _)).Times(0);