[ci] Fix pdf thumbnail unit tests flakiness (#13248)

* [ci] reduce pdf preview and thumbnail flakiness

* [ci] run pdf thumbnail tests

* [meta] add pdf modules to new issue template
This commit is contained in:
Jaime Bernardo 2021-09-16 18:02:50 +01:00 committed by GitHub
parent 8115a709e9
commit 323f41d14b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 17 additions and 10 deletions

View File

@ -39,6 +39,8 @@ body:
- Image Resizer
- Keyboard Manager
- MD Preview
- PDF Preview
- PDF Thumbnail
- PowerRename
- PowerToys Run
- Shortcut Guide

View File

@ -121,6 +121,7 @@ steps:
testSelector: 'testAssemblies'
testAssemblyVer2: |
**\UnitTests-SvgThumbnailProvider.dll
**\UnitTests-PdfThumbnailProvider.dll
**\Microsoft.PowerToys.Settings.UI.UnitTests.dll
**\UnitTests-MarkdownPreviewHandler.dll
**\UnitTests-PdfPreviewHandler.dll

View File

@ -66,16 +66,18 @@ namespace PdfPreviewHandlerUnitTests
private static IStream GetMockStream(byte[] sourceArray)
{
var streamMock = new Mock<IStream>();
var firstCall = true;
int bytesRead = 0;
streamMock
.Setup(x => x.Read(It.IsAny<byte[]>(), It.IsAny<int>(), It.IsAny<IntPtr>()))
.Callback<byte[], int, IntPtr>((buffer, countToRead, bytesReadPtr) =>
{
if (firstCall)
int actualCountToRead = Math.Min(sourceArray.Length - bytesRead, countToRead);
if (actualCountToRead > 0)
{
Array.Copy(sourceArray, 0, buffer, 0, sourceArray.Length);
Marshal.WriteInt32(bytesReadPtr, sourceArray.Length);
firstCall = false;
Array.Copy(sourceArray, bytesRead, buffer, 0, actualCountToRead);
Marshal.WriteInt32(bytesReadPtr, actualCountToRead);
bytesRead += actualCountToRead;
}
else
{

View File

@ -70,16 +70,18 @@ namespace PdfThumbnailProviderUnitTests
private static IStream GetMockStream(byte[] sourceArray)
{
var streamMock = new Mock<IStream>();
var firstCall = true;
int bytesRead = 0;
streamMock
.Setup(x => x.Read(It.IsAny<byte[]>(), It.IsAny<int>(), It.IsAny<IntPtr>()))
.Callback<byte[], int, IntPtr>((buffer, countToRead, bytesReadPtr) =>
{
if (firstCall)
int actualCountToRead = Math.Min(sourceArray.Length - bytesRead, countToRead);
if (actualCountToRead > 0)
{
Array.Copy(sourceArray, 0, buffer, 0, sourceArray.Length);
Marshal.WriteInt32(bytesReadPtr, sourceArray.Length);
firstCall = false;
Array.Copy(sourceArray, bytesRead, buffer, 0, actualCountToRead);
Marshal.WriteInt32(bytesReadPtr, actualCountToRead);
bytesRead += actualCountToRead;
}
else
{