Permalink
Browse files

Experiment with single test reuse

  • Loading branch information...
davidebbo committed Nov 28, 2012
1 parent 80ecca6 commit 09ff6dbd8226a0cb5ecc34c3838fafb377a7ca29
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="utf-8" ?>
+<configuration>
+ <appSettings>
+ <!-- Uncomment out this line to reuse the same site for all functional tests, which runs much faster -->
+ <!--<add key="SiteReusedForAllTests" value="TestRunnerSite"/>-->
+ </appSettings>
+</configuration>
@@ -99,6 +99,7 @@
<ItemGroup>
<EmbeddedResource Include=".ssh\config" />
<EmbeddedResource Include=".ssh\id_rsa" />
+ <None Include="App.config" />
<None Include="packages.config">
<SubType>Designer</SubType>
</None>
@@ -82,7 +82,11 @@ public string GitUrl
private void Delete()
{
- _siteManager.DeleteSite(_appName);
+ // Don't delete the site if we're supposed to reuse it
+ if (!KuduUtils.ReuseSameSiteForAllTests)
+ {
+ _siteManager.DeleteSite(_appName);
+ }
}
public void Save(string path, string content)
@@ -96,6 +100,13 @@ public void Save(string path, string content)
public static void Run(string applicationName, Action<ApplicationManager> action)
{
var appManager = CreateApplication(applicationName);
+
+ if (KuduUtils.ReuseSameSiteForAllTests)
+ {
+ // In site reuse mode, clean out the existing site so we start clean
+ appManager.RepositoryManager.Delete().Wait();
+ }
+
var dumpPath = Path.Combine(PathHelper.TestResultsPath, applicationName, applicationName + ".zip");
try
{
@@ -118,7 +129,11 @@ public static void Run(string applicationName, Action<ApplicationManager> action
}
finally
{
- appManager.Delete();
+ // Delete the site at the end, unless we're in site reuse mode
+ if (!KuduUtils.ReuseSameSiteForAllTests)
+ {
+ appManager.Delete();
+ }
}
}
@@ -129,16 +144,30 @@ public static ApplicationManager CreateApplication(string applicationName)
var siteManager = GetSiteManager(pathResolver, settingsResolver);
- try
+ Site site;
+
+ if (KuduUtils.ReuseSameSiteForAllTests)
{
- siteManager.DeleteSite(applicationName);
+ // In site reuse mode, try to get the existing site, and create it if needed
+ site = siteManager.GetSite(applicationName);
+ if (site == null)
+ {
+ site = siteManager.CreateSite(applicationName);
+ }
}
- catch (Exception)
+ else
{
+ try
+ {
+ siteManager.DeleteSite(applicationName);
+ }
+ catch (Exception)
+ {
- }
+ }
- Site site = siteManager.CreateSite(applicationName);
+ site = siteManager.CreateSite(applicationName);
+ }
string gitUrl = null;
var repositoryManager = new RemoteRepositoryManager(site.ServiceUrl + "live/scm");
@@ -1,4 +1,5 @@
using System;
+using System.Configuration;
using System.Diagnostics;
using System.IO;
using System.Net;
@@ -64,8 +65,15 @@ public static XDocument GetServerProfile(string serviceUrl, string logsTempPath,
public static string GetRandomWebsiteName(string name)
{
- int maxLen = Math.Min(name.Length, 25);
- return name.Substring(0, maxLen) + Guid.NewGuid().ToString("N").Substring(0, 4);
+ if (KuduUtils.ReuseSameSiteForAllTests)
+ {
+ return KuduUtils.SiteReusedForAllTests;
+ }
+ else
+ {
+ int maxLen = Math.Min(name.Length, 25);
+ return name.Substring(0, maxLen) + Guid.NewGuid().ToString("N").Substring(0, 4);
+ }
}
/// <summary>
@@ -80,5 +88,21 @@ public static string GetCachedRepositoryPath(string repositoryName)
}
return null;
}
+
+ public static string SiteReusedForAllTests
+ {
+ get
+ {
+ return ConfigurationManager.AppSettings["SiteReusedForAllTests"];
+ }
+ }
+
+ public static bool ReuseSameSiteForAllTests
+ {
+ get
+ {
+ return !String.IsNullOrEmpty(SiteReusedForAllTests);
+ }
+ }
}
}

0 comments on commit 09ff6db

Please sign in to comment.