Skip to content

Commit

Permalink
Created unit test and fix for unloading problem
Browse files Browse the repository at this point in the history
  • Loading branch information
tuespetre committed May 31, 2014
1 parent a3bf514 commit 8361600
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 6 deletions.
4 changes: 2 additions & 2 deletions Pechkin/Factory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,6 @@ private static void SetupAppDomain()
/// <param name="e">Typically EventArgs.Empty, not used in the method.</param>
private static void TearDownAppDomain(object sender, EventArgs e)
{
SynchronizedDispatcher.Terminate();

if (Factory.operatingDomain != null)
{
Func<object> del = () =>
Expand All @@ -127,6 +125,8 @@ private static void TearDownAppDomain(object sender, EventArgs e)

Factory.operatingDomain = null;
}

SynchronizedDispatcher.Terminate();
}
}
}
31 changes: 27 additions & 4 deletions PechkinTests/PechkinTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,29 @@ public static string GetResourceString(string name)
return new StreamReader(s).ReadToEnd();
}

[Fact]
public void UnloadsWkhtmltoxWhenAppDomainUnloads()
{
//arrange
var domain = AppDomain.CreateDomain("testing_unload", null, new AppDomainSetup
{
ApplicationBase = Path.GetDirectoryName(typeof(Factory).Assembly.Location)
});

//act
domain.DoCallBack(() =>
{
Factory.Create().Convert("<p>some html</p>");
});
AppDomain.Unload(domain);

//assert
Assert.False(Process.GetCurrentProcess()
.Modules
.Cast<ProcessModule>()
.Any(m => m.ModuleName == "wkhtmltox.dll"));
}

[Fact]
public void BubblesExceptionsFromSyncedThread()
{
Expand Down Expand Up @@ -82,7 +105,7 @@ public void ObjectIsHappilyGarbageCollected()
ret = c.Convert(html);

Assert.NotNull(ret);

GC.Collect();
}

Expand All @@ -106,9 +129,9 @@ public void OneObjectPerformsTwoConversionSequentially()
public void ResultIsPdf()
{
string html = GetResourceString("PechkinTests.Resources.page.html");

IPechkin c = Factory.Create();

byte[] ret = c.Convert(html);

Assert.NotNull(ret);
Expand All @@ -134,7 +157,7 @@ public void ReturnsResultFromFile()
string fn = string.Format("{0}.html", Path.GetTempFileName());
FileStream fs = new FileStream(fn, FileMode.Create);
StreamWriter sw = new StreamWriter(fs);

sw.Write(html);

sw.Close();
Expand Down

0 comments on commit 8361600

Please sign in to comment.