mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-04 18:26:39 +02:00
Use task delay instead of thread sleep (#7401)
* Use task delay instead of thread.sleep to free up the blocked thread * fix formatting
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
// See the LICENSE file in the project root for more information.
|
||||
|
||||
using System.Collections.Concurrent;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.Plugin.Program.Storage;
|
||||
using NUnit.Framework;
|
||||
|
||||
@@ -12,14 +13,14 @@ namespace Microsoft.Plugin.Program.UnitTests.Storage
|
||||
public class ConcurrentQueueEventHandlerTest
|
||||
{
|
||||
[TestCase]
|
||||
public void EventHandlerMustReturnEmptyPathForEmptyQueue()
|
||||
public async Task EventHandlerMustReturnEmptyPathForEmptyQueueAsync()
|
||||
{
|
||||
// Arrange
|
||||
int dequeueDelay = 0;
|
||||
ConcurrentQueue<string> eventHandlingQueue = new ConcurrentQueue<string>();
|
||||
|
||||
// Act
|
||||
string appPath = EventHandler.GetAppPathFromQueue(eventHandlingQueue, dequeueDelay);
|
||||
string appPath = await EventHandler.GetAppPathFromQueueAsync(eventHandlingQueue, dequeueDelay).ConfigureAwait(false);
|
||||
|
||||
// Assert
|
||||
Assert.IsEmpty(appPath);
|
||||
@@ -27,7 +28,7 @@ namespace Microsoft.Plugin.Program.UnitTests.Storage
|
||||
|
||||
[TestCase(1)]
|
||||
[TestCase(10)]
|
||||
public void EventHandlerMustReturnPathForConcurrentQueueWithSameFilePaths(int itemCount)
|
||||
public async Task EventHandlerMustReturnPathForConcurrentQueueWithSameFilePathsAsync(int itemCount)
|
||||
{
|
||||
// Arrange
|
||||
int dequeueDelay = 0;
|
||||
@@ -39,7 +40,7 @@ namespace Microsoft.Plugin.Program.UnitTests.Storage
|
||||
}
|
||||
|
||||
// Act
|
||||
string pathFromQueue = EventHandler.GetAppPathFromQueue(eventHandlingQueue, dequeueDelay);
|
||||
string pathFromQueue = await EventHandler.GetAppPathFromQueueAsync(eventHandlingQueue, dequeueDelay).ConfigureAwait(false);
|
||||
|
||||
// Assert
|
||||
Assert.AreEqual(appPath, pathFromQueue);
|
||||
@@ -47,7 +48,7 @@ namespace Microsoft.Plugin.Program.UnitTests.Storage
|
||||
}
|
||||
|
||||
[TestCase(5)]
|
||||
public void EventHandlerMustReturnPathAndRetainDifferentFilePathsInQueue(int itemCount)
|
||||
public async Task EventHandlerMustReturnPathAndRetainDifferentFilePathsInQueueAsync(int itemCount)
|
||||
{
|
||||
// Arrange
|
||||
int dequeueDelay = 0;
|
||||
@@ -65,7 +66,7 @@ namespace Microsoft.Plugin.Program.UnitTests.Storage
|
||||
}
|
||||
|
||||
// Act
|
||||
string pathFromQueue = EventHandler.GetAppPathFromQueue(eventHandlingQueue, dequeueDelay);
|
||||
string pathFromQueue = await EventHandler.GetAppPathFromQueueAsync(eventHandlingQueue, dequeueDelay).ConfigureAwait(false);
|
||||
|
||||
// Assert
|
||||
Assert.AreEqual(firstAppPath, pathFromQueue);
|
||||
@@ -73,7 +74,7 @@ namespace Microsoft.Plugin.Program.UnitTests.Storage
|
||||
}
|
||||
|
||||
[TestCase(5)]
|
||||
public void EventHandlerMustReturnPathAndRetainAllPathsAfterEncounteringADifferentPath(int itemCount)
|
||||
public async Task EventHandlerMustReturnPathAndRetainAllPathsAfterEncounteringADifferentPathAsync(int itemCount)
|
||||
{
|
||||
// Arrange
|
||||
int dequeueDelay = 0;
|
||||
@@ -96,7 +97,7 @@ namespace Microsoft.Plugin.Program.UnitTests.Storage
|
||||
}
|
||||
|
||||
// Act
|
||||
string pathFromQueue = EventHandler.GetAppPathFromQueue(eventHandlingQueue, dequeueDelay);
|
||||
string pathFromQueue = await EventHandler.GetAppPathFromQueueAsync(eventHandlingQueue, dequeueDelay).ConfigureAwait(false);
|
||||
|
||||
// Assert
|
||||
Assert.AreEqual(firstAppPath, pathFromQueue);
|
||||
|
||||
Reference in New Issue
Block a user