mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-06 11:16:51 +02:00
Revert "Improving performance of Adding and Removing Packaged Apps" (#4898)
* Revert "Adding newline to end of file for IProgramRepository" This reverts commitd55cac80bf. * Revert "Fixing comments" This reverts commita1ecdc9bfa. * Revert "Restoring checks for invalid uwp apps based on PR feedback. This was accidentally removed when moving the initialize outside the constructor." This reverts commit0e8c1cb0fd. * Revert "Removing unecessary implementation of IRepository interface as this is implemented by the base class." This reverts commit1c724280f5. * Revert "Fixing potential race condition in ListRepository. Now internally implemented as a concurrent dictionary." This reverts commit9ff8246a9d. * Revert "Updating packagerepository comment based on pr feedback" This reverts commit2c45956030. * Revert "Changing test structure. Need to add unit tests." This reverts commit1c267a55d5. * Revert "Fixing message format for exception" This reverts commitf60bdc3dd4. * Revert "Merging in Theme changes and moving win32Tests to Microsoft.Plugin.Program.UnitTests" This reverts commit030dfc2370.
This commit is contained in:
committed by
GitHub
parent
b13e719ab3
commit
12d9d59d85
@@ -1,148 +0,0 @@
|
||||
using Microsoft.Plugin.Program.Storage;
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Windows.Media.Capture;
|
||||
using Wox.Infrastructure.Storage;
|
||||
|
||||
namespace Microsoft.Plugin.Program.UnitTests.Storage
|
||||
{
|
||||
[TestFixture]
|
||||
class ListRepositoryTests
|
||||
{
|
||||
|
||||
[Test]
|
||||
public void Contains_ShouldReturnTrue_WhenListIsInitializedWithItem()
|
||||
{
|
||||
//Arrange
|
||||
var itemName = "originalItem1";
|
||||
IRepository<string> repository = new ListRepository<string>() { itemName };
|
||||
|
||||
//Act
|
||||
var result = repository.Contains(itemName);
|
||||
|
||||
//Assert
|
||||
Assert.IsTrue(result);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Contains_ShouldReturnTrue_WhenListIsUpdatedWithAdd()
|
||||
{
|
||||
//Arrange
|
||||
IRepository<string> repository = new ListRepository<string>();
|
||||
|
||||
//Act
|
||||
var itemName = "newItem";
|
||||
repository.Add(itemName);
|
||||
var result = repository.Contains(itemName);
|
||||
|
||||
//Assert
|
||||
Assert.IsTrue(result);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Contains_ShouldReturnFalse_WhenListIsUpdatedWithRemove()
|
||||
{
|
||||
//Arrange
|
||||
var itemName = "originalItem1";
|
||||
IRepository<string> repository = new ListRepository<string>() { itemName };
|
||||
|
||||
//Act
|
||||
repository.Remove(itemName);
|
||||
var result = repository.Contains(itemName);
|
||||
|
||||
//Assert
|
||||
Assert.IsFalse(result);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task Add_ShouldNotThrow_WhenBeingIterated()
|
||||
{
|
||||
//Arrange
|
||||
ListRepository<string> repository = new ListRepository<string>();
|
||||
var numItems = 1000;
|
||||
for(var i=0; i<numItems;++i)
|
||||
{
|
||||
repository.Add($"OriginalItem_{i}");
|
||||
}
|
||||
|
||||
//Act - Begin iterating on one thread
|
||||
var iterationTask = Task.Run(() =>
|
||||
{
|
||||
var remainingIterations = 10000;
|
||||
while (remainingIterations > 0)
|
||||
{
|
||||
foreach (var item in repository)
|
||||
{
|
||||
//keep iterating
|
||||
|
||||
}
|
||||
--remainingIterations;
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
//Act - Insert on another thread
|
||||
var addTask = Task.Run(() =>
|
||||
{
|
||||
for (var i = 0; i < numItems; ++i)
|
||||
{
|
||||
repository.Add($"NewItem_{i}");
|
||||
}
|
||||
});
|
||||
|
||||
//Assert that this does not throw. Collections that aren't syncronized will throw an invalidoperatioexception if the list is modified while enumerating
|
||||
Assert.DoesNotThrowAsync(async () =>
|
||||
{
|
||||
await Task.WhenAll(new Task[] { iterationTask, addTask });
|
||||
});
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task Remove_ShouldNotThrow_WhenBeingIterated()
|
||||
{
|
||||
//Arrange
|
||||
ListRepository<string> repository = new ListRepository<string>();
|
||||
var numItems = 1000;
|
||||
for (var i = 0; i < numItems; ++i)
|
||||
{
|
||||
repository.Add($"OriginalItem_{i}");
|
||||
}
|
||||
|
||||
//Act - Begin iterating on one thread
|
||||
var iterationTask = Task.Run(() =>
|
||||
{
|
||||
var remainingIterations = 10000;
|
||||
while (remainingIterations > 0)
|
||||
{
|
||||
foreach (var item in repository)
|
||||
{
|
||||
//keep iterating
|
||||
|
||||
}
|
||||
--remainingIterations;
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
//Act - Remove on another thread
|
||||
var addTask = Task.Run(() =>
|
||||
{
|
||||
for (var i = 0; i < numItems; ++i)
|
||||
{
|
||||
repository.Remove($"OriginalItem_{i}");
|
||||
}
|
||||
});
|
||||
|
||||
//Assert that this does not throw. Collections that aren't syncronized will throw an invalidoperatioexception if the list is modified while enumerating
|
||||
Assert.DoesNotThrowAsync(async () =>
|
||||
{
|
||||
await Task.WhenAll(new Task[] { iterationTask, addTask });
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,10 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace Microsoft.Plugin.Program.UnitTests.Storage
|
||||
{
|
||||
class PackageRepositoryTest
|
||||
{
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user