Skip to content

Commit

Permalink
Merge branch 'master' into release/3.6
Browse files Browse the repository at this point in the history
  • Loading branch information
rprouse committed Jan 14, 2017
2 parents cf55c5b + dc655ce commit b16914f
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 12 deletions.
35 changes: 27 additions & 8 deletions src/NUnitEngine/nunit-agent/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@ public class NUnitTestAgent

static Guid AgentId;
static string AgencyUrl;
static Process AgencyProcess;
static ITestAgency Agency;
static RemoteTestAgent Agent;

/// <summary>
/// Channel used for communications with the agency
Expand All @@ -65,7 +67,7 @@ public static int Main(string[] args)
for (int i = 2; i < args.Length; i++)
{
string arg = args[i];

// NOTE: we can test these strings exactly since
// they originate from the engine itself.
if (arg == "--debug-agent")
Expand All @@ -77,6 +79,11 @@ public static int Main(string[] args)
{
traceLevel = (InternalTraceLevel)Enum.Parse(typeof(InternalTraceLevel), arg.Substring(8));
}
else if (arg.StartsWith("--pid="))
{
int agencyProcessId = int.Parse(arg.Substring(6));
AgencyProcess = Process.GetProcessById(agencyProcessId);
}
}

// Initialize trace so we can see what's happening
Expand Down Expand Up @@ -141,16 +148,12 @@ public static int Main(string[] args)
if (Channel != null)
{
log.Info("Starting RemoteTestAgent");
RemoteTestAgent agent = new RemoteTestAgent(AgentId, Agency, engine.Services);
Agent = new RemoteTestAgent(AgentId, Agency, engine.Services);

try
{
if (agent.Start())
{
log.Debug("Waiting for stopSignal");
agent.WaitForStop();
log.Debug("Stop signal received");
}
if (Agent.Start())
WaitForStop();
else
log.Error("Failed to start RemoteTestAgent");
}
Expand All @@ -174,5 +177,21 @@ public static int Main(string[] args)

return 0;
}

private static void WaitForStop()
{
log.Debug("Waiting for stopSignal");

while (!Agent.WaitForStop(500))
{
if (AgencyProcess.HasExited)
{
log.Error("Parent process has been terminated.");
Environment.Exit(-1);
}
}

log.Debug("Stop signal received");
}
}
}
4 changes: 2 additions & 2 deletions src/NUnitEngine/nunit.engine/Agents/RemoteTestAgent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,9 @@ public override void Stop()
stopSignal.Set();
}

public void WaitForStop()
public bool WaitForStop(int timeout)
{
stopSignal.WaitOne();
return stopSignal.WaitOne(timeout);
}

#endregion
Expand Down
4 changes: 2 additions & 2 deletions src/NUnitEngine/nunit.engine/Services/TestAgency.cs
Original file line number Diff line number Diff line change
Expand Up @@ -167,10 +167,10 @@ private Guid LaunchAgentProcess(TestPackage package)
bool debugAgent = package.GetSetting(EnginePackageSettings.DebugAgent, false);
string traceLevel = package.GetSetting(EnginePackageSettings.InternalTraceLevel, "Off");
bool loadUserProfile = package.GetSetting(EnginePackageSettings.LoadUserProfile, false);

// Set options that need to be in effect before the package
// is loaded by using the command line.
string agentArgs = string.Empty;
string agentArgs = "--pid=" + Process.GetCurrentProcess().Id.ToString();
if (debugAgent)
agentArgs += " --debug-agent";
if (traceLevel != "Off")
Expand Down

0 comments on commit b16914f

Please sign in to comment.