1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
|
// ****************************************************************
// This is free software licensed under the NUnit license. You
// may obtain a copy of the license as well as information regarding
// copyright ownership at http://nunit.org
// ****************************************************************
using System;
namespace NUnit.Util
{
using System.Diagnostics;
using System.Security.Policy;
using System.Reflection;
using System.Collections;
using System.Configuration;
using System.IO;
using NUnit.Core;
public class TestDomain : ProxyTestRunner, TestRunner
{
static Logger log = InternalTrace.GetLogger(typeof(TestDomain));
#region Instance Variables
/// <summary>
/// The appdomain used to load tests
/// </summary>
private AppDomain domain;
/// <summary>
/// The TestAgent in the domain
/// </summary>
private DomainAgent agent;
#endregion
#region Constructors
public TestDomain() : base( 0 ) { }
public TestDomain( int runnerID ) : base( runnerID ) { }
#endregion
#region Properties
public AppDomain AppDomain
{
get { return domain; }
}
#endregion
#region Loading and Unloading Tests
public override bool Load( TestPackage package )
{
Unload();
log.Info("Loading " + package.Name);
try
{
if ( this.domain == null )
this.domain = Services.DomainManager.CreateDomain( package );
if (this.agent == null)
{
this.agent = DomainAgent.CreateInstance(domain);
this.agent.Start();
}
if ( this.TestRunner == null )
this.TestRunner = this.agent.CreateRunner( this.ID );
log.Info(
"Loading tests in AppDomain, see {0}_{1}.log",
domain.FriendlyName,
Process.GetCurrentProcess().Id);
return TestRunner.Load( package );
}
catch
{
log.Error("Load failure");
Unload();
throw;
}
}
public override void Unload()
{
if (this.TestRunner != null)
{
log.Info("Unloading");
this.TestRunner.Unload();
this.TestRunner = null;
}
if (this.agent != null)
{
log.Info("Stopping DomainAgent");
this.agent.Dispose();
this.agent = null;
}
if(domain != null)
{
log.Info("Unloading AppDomain " + domain.FriendlyName);
Services.DomainManager.Unload(domain);
domain = null;
}
}
#endregion
#region Running Tests
public override void BeginRun(EventListener listener, ITestFilter filter, bool tracing, LoggingThreshold logLevel)
{
log.Info("BeginRun in AppDomain {0}", domain.FriendlyName);
base.BeginRun(listener, filter, tracing, logLevel);
}
#endregion
#region IDisposable Members
public override void Dispose()
{
base.Dispose();
Unload();
}
#endregion
}
}
|