From 4ac3acca2228c12a0e93deac3c29dc47d276a2de Mon Sep 17 00:00:00 2001 From: Pranav K Date: Wed, 18 Feb 2015 11:23:57 -0800 Subject: [PATCH] Wait for precompiled file to change. --- .../PrecompilationTest.cs | 22 +++++++++++-------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/test/Microsoft.AspNet.Mvc.FunctionalTests/PrecompilationTest.cs b/test/Microsoft.AspNet.Mvc.FunctionalTests/PrecompilationTest.cs index c0d75f60d8..4d77b7f2bd 100644 --- a/test/Microsoft.AspNet.Mvc.FunctionalTests/PrecompilationTest.cs +++ b/test/Microsoft.AspNet.Mvc.FunctionalTests/PrecompilationTest.cs @@ -18,7 +18,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests { public class PrecompilationTest { - private static readonly TimeSpan _cacheDelayInterval = TimeSpan.FromSeconds(2); + private static readonly TimeSpan _cacheDelayInterval = TimeSpan.FromSeconds(1); private readonly IServiceProvider _services = TestHelper.CreateServices(nameof(PrecompilationWebSite)); private readonly Action _app = new Startup().Configure; @@ -113,7 +113,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests // Act - 7 // Add a new _GlobalImport file - File.WriteAllText(Path.Combine(viewsDirectory, "..", "_GlobalImport.cshtml"), string.Empty); + var newGlobalImport = await TouchFile(Path.GetDirectoryName(viewsDirectory), "_GlobalImport.cshtml"); responseContent = await client.GetStringAsync("http://localhost/Home/Index"); // Assert - 7 @@ -125,7 +125,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests // Act - 8 // Remove new _GlobalImport file - File.Delete(Path.Combine(viewsDirectory, "..", "_GlobalImport.cshtml")); + File.Delete(newGlobalImport); responseContent = await client.GetStringAsync("http://localhost/Home/Index"); // Assert - 8 @@ -188,8 +188,8 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests var applicationEnvironment = _services.GetRequiredService(); - var viewsDirectory = Path.Combine(applicationEnvironment.ApplicationBasePath, - "Views", + var viewsDirectory = Path.Combine(applicationEnvironment.ApplicationBasePath, + "Views", "GlobalImportDelete"); var globalPath = Path.Combine(viewsDirectory, "_GlobalImport.cshtml"); var globalContent = File.ReadAllText(globalPath); @@ -216,11 +216,15 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests } } - private static Task TouchFile(string viewsDir, string file) + private static async Task TouchFile(string viewsDir, string file) { - File.AppendAllText(Path.Combine(viewsDir, file), " "); - // Delay to ensure we don't hit the cached file system. - return Task.Delay(_cacheDelayInterval); + var path = Path.Combine(viewsDir, file); + File.AppendAllText(path, " "); + + // Delay to allow the file system watcher to catch up. + await Task.Delay(_cacheDelayInterval); + + return path; } private sealed class ParsedResponse