From 89d702c2c310b9c5ade0a0d40637fdb2a52d30da Mon Sep 17 00:00:00 2001 From: Saeed Noursalehi Date: Thu, 23 Aug 2018 15:13:44 -0700 Subject: [PATCH 1/3] Added a multithreaded functional test that currently fails on Mac by attempting to concurrently read a previously unhydrated file from several threads --- .../MultithreadedReadWriteTests.cs | 47 +++++++++++++++++-- 1 file changed, 44 insertions(+), 3 deletions(-) diff --git a/GVFS/GVFS.FunctionalTests/Tests/EnlistmentPerFixture/MultithreadedReadWriteTests.cs b/GVFS/GVFS.FunctionalTests/Tests/EnlistmentPerFixture/MultithreadedReadWriteTests.cs index 75f9f4936..2255e9c66 100644 --- a/GVFS/GVFS.FunctionalTests/Tests/EnlistmentPerFixture/MultithreadedReadWriteTests.cs +++ b/GVFS/GVFS.FunctionalTests/Tests/EnlistmentPerFixture/MultithreadedReadWriteTests.cs @@ -1,4 +1,4 @@ -using GVFS.FunctionalTests.FileSystemRunners; +using GVFS.FunctionalTests.FileSystemRunners; using GVFS.FunctionalTests.Should; using GVFS.Tests.Should; using NUnit.Framework; @@ -14,8 +14,48 @@ namespace GVFS.FunctionalTests.Tests.EnlistmentPerFixture [Category(Categories.Mac.M1)] public class MultithreadedReadWriteTests : TestsWithEnlistmentPerFixture { - [TestCase] - public void CanReadUnhydratedFileInParallelWithoutTearing() + [TestCase, Order(1)] + public void CanReadVirtualFileInParallel() + { + // Note: This test MUST go first, or else it needs to ensure that it is reading a unique path compared to the + // other tests in this class. That applies to every directory in the path, as well as the leaf file name. + // Otherwise, this test loses most of its value because there will be no races occurring on creating the + // placeholder directories, enumerating them, and then creating a placeholder file and hydrating it. + + string fileName = Path.Combine("GVFS", "GVFS.FunctionalTests", "Tests", "LongRunningEnlistment", "GitMoveRenameTests.cs"); + string virtualPath = this.Enlistment.GetVirtualPathTo(fileName); + + Exception readException = null; + + Thread[] threads = new Thread[32]; + for (int i = 0; i < threads.Length; ++i) + { + int myIndex = i; + threads[i] = new Thread(() => + { + try + { + FileSystemRunner.DefaultRunner.ReadAllText(virtualPath).ShouldBeNonEmpty(); + } + catch (Exception e) + { + readException = e; + } + } ); + + threads[i].Start(); + } + + for (int i = 0; i < threads.Length; ++i) + { + threads[i].Join(); + } + + readException.ShouldBeNull("At least one of the reads failed"); + } + + [TestCase, Order(2)] + public void CanReadHydratedPlaceholderInParallel() { FileSystemRunner fileSystem = FileSystemRunner.DefaultRunner; string fileName = Path.Combine("GVFS", "GVFS.FunctionalTests", "Tests", "LongRunningEnlistment", "WorkingDirectoryTests.cs"); @@ -72,6 +112,7 @@ public void CanReadUnhydratedFileInParallelWithoutTearing() } [TestCaseSource(typeof(FileSystemRunner), FileSystemRunner.TestRunners)] + [Order(3)] public void CanReadWriteAFileInParallel(FileSystemRunner fileSystem) { string fileName = @"CanReadWriteAFileInParallel"; From 9790552558daad724a5ebb5ae419d443ddce9fdd Mon Sep 17 00:00:00 2001 From: Saeed Noursalehi Date: Thu, 23 Aug 2018 15:50:52 -0700 Subject: [PATCH 2/3] Fix spacing --- .../Tests/EnlistmentPerFixture/MultithreadedReadWriteTests.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/GVFS/GVFS.FunctionalTests/Tests/EnlistmentPerFixture/MultithreadedReadWriteTests.cs b/GVFS/GVFS.FunctionalTests/Tests/EnlistmentPerFixture/MultithreadedReadWriteTests.cs index 2255e9c66..5c0167b5b 100644 --- a/GVFS/GVFS.FunctionalTests/Tests/EnlistmentPerFixture/MultithreadedReadWriteTests.cs +++ b/GVFS/GVFS.FunctionalTests/Tests/EnlistmentPerFixture/MultithreadedReadWriteTests.cs @@ -41,7 +41,7 @@ public void CanReadVirtualFileInParallel() { readException = e; } - } ); + }); threads[i].Start(); } From 18611bed628d3c8333b0c719a94cd55db89c0cfc Mon Sep 17 00:00:00 2001 From: Saeed Noursalehi Date: Fri, 24 Aug 2018 11:14:24 -0700 Subject: [PATCH 3/3] Mark the new test as Windows-only --- .../Tests/EnlistmentPerFixture/MultithreadedReadWriteTests.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/GVFS/GVFS.FunctionalTests/Tests/EnlistmentPerFixture/MultithreadedReadWriteTests.cs b/GVFS/GVFS.FunctionalTests/Tests/EnlistmentPerFixture/MultithreadedReadWriteTests.cs index 5c0167b5b..9c3a21e0c 100644 --- a/GVFS/GVFS.FunctionalTests/Tests/EnlistmentPerFixture/MultithreadedReadWriteTests.cs +++ b/GVFS/GVFS.FunctionalTests/Tests/EnlistmentPerFixture/MultithreadedReadWriteTests.cs @@ -15,6 +15,7 @@ namespace GVFS.FunctionalTests.Tests.EnlistmentPerFixture public class MultithreadedReadWriteTests : TestsWithEnlistmentPerFixture { [TestCase, Order(1)] + [Category(Categories.Windows)] public void CanReadVirtualFileInParallel() { // Note: This test MUST go first, or else it needs to ensure that it is reading a unique path compared to the @@ -30,7 +31,6 @@ public void CanReadVirtualFileInParallel() Thread[] threads = new Thread[32]; for (int i = 0; i < threads.Length; ++i) { - int myIndex = i; threads[i] = new Thread(() => { try