Exemplo n.º 1
0
        private void HandleOnTestCompletion(object sender, TestExecutionResultEventArgs e)
        {
            var environment = sender as IActiveEnvironment;

            var map = m_Tests[e.Id];
            var index = map.Environments.FindIndex(t => t.Item1.Environment == environment.Environment);
            map.Environments[index] = new Tuple<IActiveEnvironment, EnvironmentTestExecutionState>(
                environment,
                EnvironmentTestExecutionState.Complete);

            if (map.Environments.All(t => t.Item2 == EnvironmentTestExecutionState.Complete))
            {
                CompleteTest(e.Id, e.Result);
            }
        }
Exemplo n.º 2
0
        private void HandleTestCompleted(object sender, TestExecutionResultEventArgs eventArgs)
        {
            lock (m_Lock)
            {
                using (var ownedContext = m_TestContextFactory())
                {
                    var currentContext = ownedContext.Value;

                    var shouldTerminateEnvironment = m_Configuration.HasValueFor(
                        MasterServiceConfigurationKeys.ShouldTerminateEnvironmentOnFailedTest)
                        ? m_Configuration.Value<bool>(MasterServiceConfigurationKeys.ShouldTerminateEnvironmentOnFailedTest)
                        : MasterServiceConstants.DefaultShouldTerminateEnvironmentOnFailedTest;

                    if (shouldTerminateEnvironment || (eventArgs.Result == TestExecutionResult.Passed))
                    {
                        foreach (var environment in m_ExecutingTests.EnvironmentsForTest(eventArgs.Id))
                        {
                            try
                            {
                                environment.Shutdown();
                                currentContext.MarkMachineAsInactive(environment.Environment);
                            }
                            catch (Exception e)
                            {
                                m_Diagnostics.Log(
                                    LevelToLog.Error,
                                    MasterServiceConstants.LogPrefix,
                                    string.Format(
                                        CultureInfo.InvariantCulture,
                                        "Failed to shut down the machine {0}. Error was: {1}",
                                        environment.Environment,
                                        e));
                            }
                        }
                    }

                    var report = m_ExecutingTests.ReportFor(eventArgs.Id);
                    var notifications = m_ExecutingTests.NotificationsFor(eventArgs.Id);
                    foreach (var notification in notifications)
                    {
                        notification.OnTestCompleted(eventArgs.Result, report);
                    }

                    m_ExecutingTests.Remove(eventArgs.Id);
                    currentContext.StopTest(eventArgs.Id);
                    try
                    {
                        var testFile = TestHelpers.StoragePathForTestFiles(eventArgs.Id, m_Configuration, m_FileSystem);
                        if (m_FileSystem.File.Exists(testFile))
                        {
                            m_FileSystem.File.Delete(testFile);
                        }
                    }
                    catch (IOException e)
                    {
                        m_Diagnostics.Log(
                            LevelToLog.Error,
                            MasterServiceConstants.LogPrefix,
                            string.Format(
                                CultureInfo.InvariantCulture,
                                Resources.Log_Messages_FailedToDeleteTestFiles_WithFileAndError,
                                eventArgs.Id,
                                e));
                    }

                    m_Diagnostics.Log(
                        LevelToLog.Info,
                        MasterServiceConstants.LogPrefix,
                        string.Format(
                            CultureInfo.InvariantCulture,
                            Resources.Log_Messages_CompletedTest_WithId,
                            eventArgs.Id));
                }
            }
        }
 private void HandleOnTestCompletion(object sender, TestExecutionResultEventArgs eventArgs)
 {
     var local = OnTestCompletion;
     if (local != null)
     {
         // The remote environments don't actually know the test ID, but we do ...
         local(this, new TestExecutionResultEventArgs(RunningTest, eventArgs.Result));
     }
 }