Add retry policy to ProfileOptimization test (dotnet/corefx#31810)
authorMarco Rossignoli <marco.rossignoli@gmail.com>
Thu, 13 Sep 2018 20:48:20 +0000 (22:48 +0200)
committerDan Moseley <danmose@microsoft.com>
Thu, 13 Sep 2018 20:48:20 +0000 (13:48 -0700)
* add retry policy

* add write test on profile file path location

* address PR feedback

* cleanup code

Commit migrated from https://github.com/dotnet/corefx/commit/065bed2fb74ebed6798990e65b88e67c0b47429b

src/libraries/System.Runtime.Extensions/tests/System/Runtime/ProfileOptimization.netcoreapp.cs

index 367a9df..91e4f51 100644 (file)
@@ -5,22 +5,36 @@
 using System.Diagnostics;
 using System.IO;
 using Xunit;
+using Xunit.Abstractions;
 
 namespace System.Runtime.Tests
 {
     public class ProfileOptimizationTest : RemoteExecutorTestBase
     {
+        private readonly ITestOutputHelper _output;
+
+        public ProfileOptimizationTest(ITestOutputHelper output) => _output = output;
+
         [Fact]
         public void ProfileOptimization_CheckFileExists()
         {
             string tmpProfileFilePath = GetTestFileName();
+            string tmpTestFileName = Path.Combine(Path.GetDirectoryName(tmpProfileFilePath), Path.GetRandomFileName());
+
+            _output.WriteLine($"We'll test write permission on path '{tmpTestFileName}'");
 
-            RemoteInvoke(profileFilePath =>
+            RemoteInvoke((profileFilePath, testFileName) =>
             {
+                // after test fail tracked by https://github.com/dotnet/corefx/issues/31792
+                // we suspect that the reason is something related to write permission to the location
+                // to prove that we added a simple write to file in same location of profile file directory path
+                // ProfileOptimization/Multi-Core JIT could fail silently
+                File.WriteAllText(testFileName, "42");
+
                 ProfileOptimization.SetProfileRoot(Path.GetDirectoryName(profileFilePath));
                 ProfileOptimization.StartProfile(Path.GetFileName(profileFilePath));
-                return 42;
-            }, tmpProfileFilePath).Dispose();
+
+            }, tmpProfileFilePath, tmpTestFileName).Dispose();
 
             FileInfo fileInfo = new FileInfo(tmpProfileFilePath);
             Assert.True(fileInfo.Exists);