bool LaunchedTestsCalledBack(PNUnitService service, int iniWait) { List <string> testsThatContacted = service.GetTestsThatContacted(); if (testsThatContacted.Count == mTestGroup.Tests.Length) { mStatus.SetWarningMessage(string.Empty); return(true); } string warnMsg = string.Format( "Something weird is going on, it's been {0} ms since" + " the wait started and not all tests contacted back.", Environment.TickCount - iniWait); if (testsThatContacted.Count > 0) { warnMsg += " Tests that contacted: "; foreach (string contactedTest in testsThatContacted) { warnMsg += " " + contactedTest; } } mStatus.SetWarningMessage(warnMsg); mLog.Warn(warnMsg); return(false); }
void LaunchTestOnAgents(List <SendTestToAgentParams> testsToRun, PNUnitService service) { foreach (SendTestToAgentParams testToRun in testsToRun) { CleanPreviousRunningTestsOnAgent(testToRun); } foreach (SendTestToAgentParams testToRun in testsToRun) { LaunchTestOnAgent(testToRun, service); } }
void WaitForTestToFinish(PNUnitService service) { if (!HasToWait()) { return; } mLog.DebugFormat( "Thread going to wait for results for TestGroup {0}", mTestGroup.Name); int iniWait = Environment.TickCount; bool bAliveLastTime = true; // wait for all tests to end while (!service.WaitToFinish(10000)) { // wake up every 10 seconds and check if at least // the tests called back :-) if (HasBarriers() && !LaunchedTestsCalledBack(service, iniWait)) { if (!TestsAreAlive()) { return; } } if (Environment.TickCount - iniWait > 20000) { if (TestsAreAlive()) { bAliveLastTime = true; } else { if (!bAliveLastTime) { mLog.ErrorFormat( "Tests in {0} are not alive" + " and they were not alive in the last check" + " so this test test will be finished", mTestGroup.Name); return; } bAliveLastTime = false; } } } }
void NotifyException( PNUnitService service, TestConf test, Exception e) { TestName tn = new TestName(); tn.Name = test.Name; string fullMessage = string.Format( "{0}; EXCEPTION TYPE: {1}; STACK TRACE: {2}", e.Message, e.GetType(), e.StackTrace); PNUnitTestResult tr = new PNUnitTestResult(tn, fullMessage, string.Empty, string.Empty); tr.Failure(fullMessage, e.StackTrace); service.NotifyResult(test.Name, tr); }
void LaunchTestOnAgent(SendTestToAgentParams testToRun, PNUnitService service) { try { mTestsRun.IncrementTestsLaunched(); testToRun.Agent.IsUp(); testToRun.Agent.SetTestsTimeout(mTestTimeout); testToRun.Agent.RunTest(testToRun.TestInfo); } catch (Exception e) { mLogWriter.LogError(string.Format( "Test: [{0}] - An error occurred trying to contact {1} [{2}]", testToRun.TestGroupName + "-" + testToRun.TestConf.Name, testToRun.TestConf.Machine, e.Message)); mTestsRun.DecrementTestsLaunched(); NotifyException(service, testToRun.TestConf, e); } }
public void Run() { if (mTestGroup.Tests.Length == 0) { mLog.Fatal("No tests to run, exiting"); return; } mLog.DebugFormat( "Run TestGroup {0} with {1} tests", mTestGroup.Name, mTestGroup.Tests.Length); PNUnitService service = new PNUnitService( mTestGroup, mLogWriter, mTestsRun, mStatus); service.Publish(); List <SendTestToAgentParams> testsGroupToRun = new List <SendTestToAgentParams>(mTestGroup.Tests.Length); foreach (TestConf test in mTestGroup.Tests) { if (test.Machine.StartsWith(AGENT_KEY)) { test.Machine = mTestGroup.Agents[int.Parse(test.Machine.Substring(AGENT_KEY.Length))]; } mLogWriter.Log(string.Format("Starting {0} test {1} on {2}", mTestGroup.Name, test.Name, test.Machine)); SendTestToAgentParams testParams = new SendTestToAgentParams(); testParams.TestGroupName = mTestGroup.Name; testParams.Agent = GetAgent(test); testParams.TestConf = test; testParams.TestInfo = new PNUnitTestInfo( test.Name, test.Assembly, test.TestToRun, test.TestParams, test.StartBarrier, test.EndBarrier, test.WaitBarriers, mListenAddress); testParams.TestInfo.UserValues = mUserValues; testsGroupToRun.Add(testParams); } LaunchTestOnAgents(testsGroupToRun, service); if (mbShellMode) { CommandLoop(); } WaitForTestToFinish(service); service.Unpublish(); mLog.DebugFormat("Finish for TestGroup {0}", mTestGroup.Name); }