提交 7698b09e 编写于 作者: S Sam Harwell

Use DisposableDirectory for resources in AbstractPersistentStorageTests

上级 e648eee0
......@@ -10,11 +10,8 @@
using System.Threading;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis.Host;
using Microsoft.CodeAnalysis.Options;
using Microsoft.CodeAnalysis.SQLite;
using Microsoft.CodeAnalysis.Storage;
using Microsoft.CodeAnalysis.Test.Utilities;
using Moq;
using Xunit;
namespace Microsoft.CodeAnalysis.UnitTests.WorkspaceServices
......@@ -35,7 +32,8 @@ public enum Size
private readonly Encoding _encoding = Encoding.UTF8;
private AbstractPersistentStorageService _storageService;
private readonly string _persistentFolder;
private readonly DisposableDirectory _persistentFolderRoot;
private readonly TempDirectory _persistentFolder;
private const int LargeSize = (int)(SQLite.v2.SQLitePersistentStorage.MaxPooledByteArrayLength * 2);
private const int MediumSize = (int)(SQLite.v2.SQLitePersistentStorage.MaxPooledByteArrayLength / 2);
......@@ -65,8 +63,8 @@ static AbstractPersistentStorageTests()
protected AbstractPersistentStorageTests()
{
_persistentFolder = Path.Combine(Path.GetTempPath(), PersistentFolderPrefix + Guid.NewGuid());
Directory.CreateDirectory(_persistentFolder);
_persistentFolderRoot = new DisposableDirectory(new TempRoot());
_persistentFolder = _persistentFolderRoot.CreateDirectory(PersistentFolderPrefix + Guid.NewGuid());
ThreadPool.GetMinThreads(out var workerThreads, out var completionPortThreads);
ThreadPool.SetMinThreads(Math.Max(workerThreads, NumThreads), completionPortThreads);
......@@ -76,11 +74,7 @@ public void Dispose()
{
// This should cause the service to release the cached connection it maintains for the primary workspace
_storageService?.GetTestAccessor().Shutdown();
if (Directory.Exists(_persistentFolder))
{
Directory.Delete(_persistentFolder, true);
}
_persistentFolderRoot.Dispose();
}
private string GetData1(Size size)
......@@ -158,7 +152,7 @@ public async Task PersistentService_Solution_WriteReadReopenSolution(Size size,
[Theory]
[CombinatorialData]
private async Task PersistentService_Solution_WriteReadSameInstance(Size size, bool withChecksum)
public async Task PersistentService_Solution_WriteReadSameInstance(Size size, bool withChecksum)
{
var solution = CreateOrOpenSolution();
var streamName1 = "PersistentService_Solution_WriteReadSameInstance1";
......@@ -172,7 +166,7 @@ private async Task PersistentService_Solution_WriteReadSameInstance(Size size, b
Assert.Equal(GetData2(size), ReadStringToEnd(await storage.ReadStreamAsync(streamName2, GetChecksum2(withChecksum))));
}
[Theory(Skip = "https://github.com/dotnet/roslyn/issues/22437")]
[Theory]
[CombinatorialData]
public async Task PersistentService_Project_WriteReadSameInstance(Size size, bool withChecksum)
{
......@@ -294,8 +288,10 @@ public async Task PersistentService_Project_SimultaneousReads(Size size, bool wi
[Theory]
[CombinatorialData]
public async Task PersistentService_Document_SimultaneousReads(Size size, bool withChecksum)
public async Task PersistentService_Document_SimultaneousReads(Size size, bool withChecksum, [CombinatorialRange(0, 100)] int iteration)
{
_ = iteration;
var solution = CreateOrOpenSolution();
var streamName1 = "PersistentService_Document_SimultaneousReads1";
......@@ -477,26 +473,23 @@ private void DoSimultaneousReads(Func<Task<string>> read, string expectedValue)
protected Solution CreateOrOpenSolution(bool nullPaths = false)
{
var solutionFile = Path.Combine(_persistentFolder, "Solution1.sln");
File.WriteAllText(solutionFile, "");
var solutionFile = _persistentFolder.CreateOrOpenFile("Solution1.sln").WriteAllText("");
var info = SolutionInfo.Create(SolutionId.CreateNewId(), VersionStamp.Create(), solutionFile);
var info = SolutionInfo.Create(SolutionId.CreateNewId(), VersionStamp.Create(), solutionFile.Path);
var workspace = new AdhocWorkspace();
workspace.AddSolution(info);
var solution = workspace.CurrentSolution;
var projectFile = Path.Combine(Path.GetDirectoryName(solutionFile), "Project1.csproj");
File.WriteAllText(projectFile, "");
var projectFile = _persistentFolder.CreateOrOpenFile("Project1.csproj").WriteAllText("");
solution = solution.AddProject(ProjectInfo.Create(ProjectId.CreateNewId(), VersionStamp.Create(), "Project1", "Project1", LanguageNames.CSharp,
filePath: nullPaths ? null : projectFile));
filePath: nullPaths ? null : projectFile.Path));
var project = solution.Projects.Single();
var documentFile = Path.Combine(Path.GetDirectoryName(projectFile), "Document1.cs");
File.WriteAllText(documentFile, "");
var documentFile = _persistentFolder.CreateOrOpenFile("Document1.cs").WriteAllText("");
solution = solution.AddDocument(DocumentInfo.Create(DocumentId.CreateNewId(project.Id), "Document1",
filePath: nullPaths ? null : documentFile));
filePath: nullPaths ? null : documentFile.Path));
// Apply this to the workspace so our Solution is the primary branch ID, which matches our usual behavior
workspace.TryApplyChanges(solution);
......@@ -509,7 +502,7 @@ protected Solution CreateOrOpenSolution(bool nullPaths = false)
{
// If we handed out one for a previous test, we need to shut that down first
_storageService?.GetTestAccessor().Shutdown();
var locationService = new MockPersistentStorageLocationService(solution.Id, _persistentFolder);
var locationService = new MockPersistentStorageLocationService(solution.Id, _persistentFolder.Path);
_storageService = GetStorageService(locationService, faultInjectorOpt);
var storage = _storageService.GetStorage(solution, checkBranchId: true);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册