From c50860a471d37ad326918c2b56334de74ff38511 Mon Sep 17 00:00:00 2001 From: Jonathan Peppers Date: Fri, 23 Aug 2019 14:35:37 -0500 Subject: [PATCH 1/3] [tests] add checks if long paths supported Context: http://build.azdo.io/2971289 Our `MaxPathTests` seem to be failing on a specific build machine: `DDMBLDW137`. I suspect this machine has long paths enabled. I added a check that attempts to write a long path, and if it succeeds we can `Assert.Ignore` these tests appropriately. A filename can only be 255 characters, so I added a constant for this value so the various tests can use it. --- .../MaxPathTests.cs | 4 +-- .../Tasks/RemoveDirTests.cs | 6 ++--- .../Utilities/BaseTest.cs | 26 +++++++++++++++++++ .../Utilities/FilesTests.cs | 6 ++--- 4 files changed, 34 insertions(+), 8 deletions(-) diff --git a/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/MaxPathTests.cs b/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/MaxPathTests.cs index 88c768aaeec..6a6c4596ac2 100644 --- a/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/MaxPathTests.cs +++ b/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/MaxPathTests.cs @@ -15,8 +15,8 @@ public class MaxPathTests : BaseTest [SetUp] public void Setup () { - if (!IsWindows) { - Assert.Ignore ("MAX_PATH only applies on Windows"); + if (LongPathsSupported) { + Assert.Ignore ("This environment supports long paths"); } } diff --git a/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/Tasks/RemoveDirTests.cs b/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/Tasks/RemoveDirTests.cs index 121bc8282b1..973ea919696 100644 --- a/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/Tasks/RemoveDirTests.cs +++ b/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/Tasks/RemoveDirTests.cs @@ -76,10 +76,10 @@ public void ReadonlyFile () [Test] public void LongPath () { - if (!IsWindows) { - Assert.Ignore ("MAX_PATH only applies on Windows"); + if (LongPathsSupported) { + Assert.Ignore ("This environment supports long paths"); } - var file = NewFile (fileName: "foo".PadRight (250, 'N')); + var file = NewFile (fileName: "foo".PadRight (MaxFileName, 'N')); var task = CreateTask (); Assert.IsTrue (task.Execute (), "task.Execute() should have succeeded."); Assert.AreEqual (1, task.RemovedDirectories.Length, "Changes should have been made."); diff --git a/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/Utilities/BaseTest.cs b/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/Utilities/BaseTest.cs index 67279358d4c..539630c287e 100644 --- a/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/Utilities/BaseTest.cs +++ b/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/Utilities/BaseTest.cs @@ -164,6 +164,32 @@ public static string AndroidNdkPath { } } + /// + /// Windows can only create a file of 255 characters: This type of path is composed of components separated by backslashes, each up to the value returned in the lpMaximumComponentLength parameter of the GetVolumeInformation function (this value is commonly 255 characters). + /// See: https://docs.microsoft.com/en-us/windows/win32/fileio/naming-a-file#maximum-path-length-limitation + /// + public const int MaxFileName = 255; + + static Lazy longPaths = new Lazy (() => { + if (!TestEnvironment.IsWindows) { + return true; + } + var path = Path.Combine (Path.GetTempPath (), "foo".PadRight (MaxFileName, 'N')); + try { + File.WriteAllText (path, ""); + return true; + } catch { + return false; + } finally { + // If the file exists, we should be able to delete it + if (File.Exists (path)) { + File.Delete (path); + } + } + }); + + public static bool LongPathsSupported => longPaths.Value; + protected static void WaitFor(int milliseconds) { var pause = new ManualResetEvent(false); diff --git a/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/Utilities/FilesTests.cs b/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/Utilities/FilesTests.cs index 914da582f7c..2b0b94843f6 100644 --- a/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/Utilities/FilesTests.cs +++ b/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/Utilities/FilesTests.cs @@ -85,7 +85,7 @@ public void CopyIfChanged_NoExist () public void CopyIfChanged_LongPath () { var src = NewFile (contents: "foo"); - var dest = NewFile (contents: "bar", fileName: "bar".PadRight (250, 'N')); + var dest = NewFile (contents: "bar", fileName: "bar".PadRight (MaxFileName, 'N')); dest = Files.ToLongPath (dest); Assert.IsTrue (Files.CopyIfChanged (src, dest), "Changes should have occurred"); FileAssert.AreEqual (src, dest); @@ -142,7 +142,7 @@ public void CopyIfStringChanged_NoExist () [Test] public void CopyIfStringChanged_LongPath () { - var dest = NewFile (fileName: "bar".PadRight (250, 'N')); + var dest = NewFile (fileName: "bar".PadRight (MaxFileName, 'N')); dest = Files.ToLongPath (dest); Assert.IsTrue (Files.CopyIfStringChanged ("foo", dest), "Changes should have occurred"); FileAssert.Exists (dest); @@ -192,7 +192,7 @@ public void CopyIfStreamChanged_NoChanges () public void CopyIfStreamChanged_LongPath () { using (var src = NewStream ("foo")) { - var dest = NewFile (fileName: "bar".PadRight (250, 'N')); + var dest = NewFile (fileName: "bar".PadRight (MaxFileName, 'N')); dest = Files.ToLongPath (dest); Assert.IsTrue (Files.CopyIfStreamChanged (src, dest), "Changes should have occurred"); FileAssert.Exists (dest); From a8e453cf1283a9918b9fb178d0df9e65080e9616 Mon Sep 17 00:00:00 2001 From: Jonathan Peppers Date: Mon, 26 Aug 2019 22:00:13 -0500 Subject: [PATCH 2/3] REVERT THIS! Temporarily require `$(Agent.Name)` = `DDMBLDW137` --- build-tools/automation/azure-pipelines.yaml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/build-tools/automation/azure-pipelines.yaml b/build-tools/automation/azure-pipelines.yaml index 147643c8608..98d9ccdba41 100644 --- a/build-tools/automation/azure-pipelines.yaml +++ b/build-tools/automation/azure-pipelines.yaml @@ -226,7 +226,9 @@ stages: jobs: - job: win_build_test displayName: Build and Test - pool: $(XA.Build.Win.Pool) + pool: + name: $(XA.Build.Win.Pool) + demands: Agent.Name -equals DDMBLDW137 timeoutInMinutes: 360 cancelTimeoutInMinutes: 5 workspace: From 4080e0377b0b7e48f41e62052535734add3f81e8 Mon Sep 17 00:00:00 2001 From: Jonathan Peppers Date: Wed, 28 Aug 2019 14:33:52 -0500 Subject: [PATCH 3/3] Revert "REVERT THIS!" This reverts commit 878aec04a49815d0abcccaa6f566026b39aa15d7. --- build-tools/automation/azure-pipelines.yaml | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/build-tools/automation/azure-pipelines.yaml b/build-tools/automation/azure-pipelines.yaml index 98d9ccdba41..147643c8608 100644 --- a/build-tools/automation/azure-pipelines.yaml +++ b/build-tools/automation/azure-pipelines.yaml @@ -226,9 +226,7 @@ stages: jobs: - job: win_build_test displayName: Build and Test - pool: - name: $(XA.Build.Win.Pool) - demands: Agent.Name -equals DDMBLDW137 + pool: $(XA.Build.Win.Pool) timeoutInMinutes: 360 cancelTimeoutInMinutes: 5 workspace: