コード例 #1
0
 public static void EnsureSilverlightPlatformSupport(this IUnitTestLaunch launch, ref IUnitTestRun run, IUnitTestProvider provider, ITaskRunnerHostController hostController)
 {
     foreach (var sequence in run.GetRootTasks().ToArray())
     {
         ConvertToSilverlightSequenceIfNecessary(sequence, ref run, launch, provider, hostController);
     }
 }
コード例 #2
0
        Task IUnitTestRunStrategy.Run(IUnitTestRun run)
        {
            var key = run.Launch.GetData(ourLaunchedInUnityKey);

            if (key != null)
            {
                return(Task.FromResult(false));
            }

            var tcs = new TaskCompletionSource <bool>();

            run.Launch.PutData(ourLaunchedInUnityKey, "smth");
            run.PutData(ourCompletionSourceKey, tcs);

            mySolution.Locks.ExecuteOrQueueEx(mySolution.GetLifetime(), "ExecuteRunUT", () =>
            {
                if (myUnityEditorProtocol.UnityModel.Value == null)
                {
                    return;
                }

                var currentConnectionLifetime = Lifetimes.Define(mySolution.GetLifetime());
                myUnityEditorProtocol.UnityModel.Change.Advise_NoAcknowledgement(currentConnectionLifetime.Lifetime, (args) =>
                {
                    if (args.HasNew && args.New == null)
                    {
                        currentConnectionLifetime.Terminate();
                    }
                });

                RunInternal(run, currentConnectionLifetime.Lifetime, myUnityEditorProtocol.UnityModel.Value, tcs);
            });

            return(tcs.Task);
        }
コード例 #3
0
        public async Task PrepareForRun(IUnitTestRun run)
        {
            // ToDo Replace this LifetimeDefinition with LifetimeDefinition from PrepareForRun (When it will be updated. It need to cancel PrepareForRun)
            var lifetimeDef = new LifetimeDefinition();

            await myInnerHostController.PrepareForRun(run).ConfigureAwait(false);

            if (!myUnityController.IsUnityEditorUnitTestRunStrategy(run.RunStrategy))
            {
                return;
            }

            lock (myStartUnitySync)
            {
                myStartUnityTask = myStartUnityTask.ContinueWith(_ =>
                {
                    var unityEditorProcessId = myUnityController.TryGetUnityProcessId();
                    return(unityEditorProcessId.HasValue
                        ? Task.CompletedTask
                        : myShellLocks.Tasks.StartNew(lifetimeDef.Lifetime, Scheduling.FreeThreaded, StartUnityIfNeed));
                }, lifetimeDef.Lifetime, TaskContinuationOptions.None, myShellLocks.Tasks.GuardedMainThreadScheduler).Unwrap();
            }

            await myStartUnityTask.ConfigureAwait(false);
        }
        public async Task PrepareForRun(IUnitTestRun run)
        {
            var lifetimeDef = Lifetime.Define();

            run.PutData(ourLifetimeDefinitionKey, lifetimeDef);

            await myInnerHostController.PrepareForRun(run).ConfigureAwait(false);

            if (!myUnityController.IsUnityEditorUnitTestRunStrategy(run.RunStrategy))
            {
                return;
            }

            lock (myStartUnitySync)
            {
                myStartUnityTask = myStartUnityTask.ContinueWith(_ =>
                {
                    var unityEditorProcessId = myUnityController.TryGetUnityProcessId();
                    return(unityEditorProcessId.HasValue
                        ? Task.CompletedTask
                        : myShellLocks.Tasks.StartNew(lifetimeDef.Lifetime, Scheduling.FreeThreaded, () => StartUnityIfNeed(lifetimeDef.Lifetime)));
                }, lifetimeDef.Lifetime, TaskContinuationOptions.None, myShellLocks.Tasks.GuardedMainThreadScheduler).Unwrap();
            }

            await myStartUnityTask.ConfigureAwait(false);
        }
コード例 #5
0
        private void StartTests(IUnitTestRun run, TaskCompletionSource <bool> tcs, Lifetime taskLifetime)
        {
            myLogger.Trace("RunUnitTestLaunch.Start.");
            var rdTask = myBackendUnityHost.BackendUnityModel.Value.RunUnitTestLaunch.Start(Unit.Instance);

            rdTask?.Result.Advise(taskLifetime, res =>
            {
                myLogger.Trace($"RunUnitTestLaunch result = {res.Result}");
                if (!res.Result)
                {
                    var defaultMessage = "Failed to start tests in Unity.";

                    var isCoverage =
                        run.HostController.HostId != WellKnownHostProvidersIds.DebugProviderId &&
                        run.HostController.HostId != WellKnownHostProvidersIds.RunProviderId;

                    if (myPackageValidator.HasNonCompatiblePackagesCombination(isCoverage, out var message))
                    {
                        defaultMessage = $"{defaultMessage} {message}";
                    }

                    if (myBackendUnityHost.BackendUnityModel.Value.UnitTestLaunch.Value.TestMode == TestMode.Play)
                    {
                        if (!myPackageValidator.CanRunPlayModeTests(out var playMessage))
                        {
                            defaultMessage = $"{defaultMessage} {playMessage}";
                        }
                    }
        private async Task PrepareForRunInternal(Lifetime lifetime, IUnitTestRun run)
        {
            var unityEditorProcessId = myUnityController.TryGetUnityProcessId();

            if (unityEditorProcessId.HasValue)
            {
                return;
            }

            var message = string.Format(StartUnityEditorQuestionMessage,
                                        myAvailableProviders[run.HostController.HostId],
                                        myUnityController.GetPresentableUnityVersion());

            if (!MessageBox.ShowYesNo(message, PluginName))
            {
                throw new Exception(string.Format(NotAvailableUnityEditorMessage, myAvailableProviders[run.HostController.HostId]));
            }

            var startUnityTask = StartUnity(lifetime);

            await myShellLocks.Tasks.YieldToIfNeeded(lifetime, Scheduling.MainGuard);

            ShowProgress(lifetime, startUnityTask);

            await startUnityTask.ConfigureAwait(false);
        }
コード例 #7
0
 public static IProject GetSilverlightProject(this RemoteTaskPacket sequence, IUnitTestRun run)
 {
     return sequence.GetAllTasksRecursive()
         .Select(task => run.GetElementByRemoteTaskId(task.Task.Id))
         .Where(element => element != null)
         .Select(element => element.Id.GetProject())
         .FirstOrDefault(project => project != null && project.PlatformID != null && project.PlatformID.Identifier == FrameworkIdentifier.Silverlight);
 }
コード例 #8
0
 public static IProject GetSilverlightProject(this RemoteTaskPacket sequence, IUnitTestRun run)
 {
     return(sequence.GetAllTasksRecursive()
            .Select(task => run.GetElementByRemoteTaskId(task.Task.Id))
            .Where(element => element != null)
            .Select(element => element.GetProject())
            .Where(project => project != null && project.PlatformID != null && project.PlatformID.Identifier == FrameworkIdentifier.Silverlight)
            .FirstOrDefault());
 }
コード例 #9
0
        private void RunWithSilverlightDebugger(IUnitTestRun run)
        {
            var targetInfo = CreateTargetInfo(run);

            this.SetField("myRunId", run.ID);
            this.SetField("myTargetInfo", targetInfo);

            new Thread(CallThreadProc) { IsBackground = true }.Start();
        }
コード例 #10
0
        private Task Run(IUnitTestRun run)
        {
            if (myUnityProcessId.Value == null)
            {
                return(Task.FromException(new Exception("Unity Editor is not available.")));
            }

            var tcs             = new TaskCompletionSource <bool>();
            var taskLifetimeDef = Lifetime.Define(myLifetime);

            taskLifetimeDef.SynchronizeWith(tcs);

            myUnityProcessId.When(run.Lifetime, (int?)null, _ =>
            {
                tcs.TrySetException(new Exception("Unity Editor has been closed."));
            });

            var hostId = run.HostController.HostId;

            switch (hostId)
            {
            case WellKnownHostProvidersIds.DebugProviderId:
                mySolution.Locks.ExecuteOrQueueEx(myLifetime, "AttachDebuggerToUnityEditor", () =>
                {
                    if (!run.Lifetime.IsAlive)
                    {
                        tcs.TrySetCanceled();
                        return;
                    }

                    var task = myUnityHost.GetValue(model => model.AttachDebuggerToUnityEditor.Start(Unit.Instance));
                    task.Result.AdviseNotNull(myLifetime, result =>
                    {
                        if (!run.Lifetime.IsAlive)
                        {
                            tcs.TrySetCanceled();
                        }
                        else if (!result.Result)
                        {
                            tcs.SetException(new Exception("Unable to attach debugger."));
                        }
                        else
                        {
                            RefreshAndRunTask(run, tcs, taskLifetimeDef.Lifetime);
                        }
                    });
                });
                break;

            default:
                RefreshAndRunTask(run, tcs, taskLifetimeDef.Lifetime);
                break;
            }

            return(tcs.Task);
        }
コード例 #11
0
        private void RefreshAndRunTask(IUnitTestRun run, TaskCompletionSource <bool> tcs)
        {
            myLogger.Verbose("Before calling Refresh.");
            Refresh(mySolution.Locks, run.Lifetime).GetAwaiter().OnCompleted(() =>
            {
                mySolution.Locks.ExecuteOrQueueEx(run.Lifetime, "Check compilation", () =>
                {
                    if (myEditorProtocol.UnityModel.Value == null)
                    {
                        myLogger.Verbose("Unity Editor connection unavailable.");
                        tcs.SetException(new Exception("Unity Editor connection unavailable."));
                        return;
                    }

                    var task = myEditorProtocol.UnityModel.Value.GetCompilationResult.Start(Unit.Instance);
                    task.Result.AdviseNotNull(run.Lifetime, result =>
                    {
                        if (!result.Result)
                        {
                            tcs.SetException(new Exception("There are errors during compilation in Unity."));

                            mySolution.Locks.ExecuteOrQueueEx(run.Lifetime, "RunViaUnityEditorStrategy compilation failed",
                                                              () =>
                            {
                                var notification = new NotificationModel("Compilation failed",
                                                                         "Script compilation in Unity failed, so tests were not started.", true,
                                                                         RdNotificationEntryType.INFO);
                                myNotificationsModel.Notification(notification);
                            });
                            myUnityHost.PerformModelAction(model => model.ActivateUnityLogView());
                        }
                        else
                        {
                            var launch = SetupLaunch(run);
                            mySolution.Locks.ExecuteOrQueueEx(run.Lifetime, "ExecuteRunUT", () =>
                            {
                                if (myEditorProtocol.UnityModel.Value == null)
                                {
                                    tcs.SetException(new Exception("Unity Editor connection unavailable."));
                                    return;
                                }

                                myEditorProtocol.UnityModel.ViewNotNull(run.Lifetime, (lt, model) =>
                                {
                                    // recreate UnitTestLaunch in case of AppDomain.Reload, which is the case with PlayMode tests
                                    model.UnitTestLaunch.SetValue(launch);
                                    SubscribeResults(run, lt, tcs, launch);
                                });

                                myEditorProtocol.UnityModel.Value.RunUnitTestLaunch();
                            });
                        }
                    });
                });
            });
        }
コード例 #12
0
 public static void AddDynamicElement(this IUnitTestRun run, IUnitTestElement element)
 {
     using (ReadLockCookie.Create())
     {
         var elementManager = run.Launch.ComponentContainer.GetComponent <IUnitTestElementManager>();
         elementManager.AddElements(new HashSet <IUnitTestElement> {
             element
         });
     }
 }
コード例 #13
0
        private void RunInternal(IUnitTestRun firstRun, Lifetime connectionLifetime, EditorPluginModel unityModel, TaskCompletionSource <bool> tcs)
        {
            mySolution.Locks.AssertMainThread();

            var elementToIdMap   = new Dictionary <string, IUnitTestElement>();
            var unitTestElements = CollectElementsToRunInUnityEditor(firstRun);
            var allNames         = InitElementsMap(unitTestElements, elementToIdMap);
            var emptyList        = new List <string>();

            var launch = new UnitTestLaunch(allNames, emptyList, emptyList);

            launch.TestResult.Advise(connectionLifetime, result =>
            {
                var unitTestElement = GetElementById(result.TestId, elementToIdMap);
                if (unitTestElement == null)
                {
                    return;
                }

                switch (result.Status)
                {
                case Status.Pending:
                    myUnitTestResultManager.MarkPending(unitTestElement,
                                                        firstRun.Launch.Session);
                    break;

                case Status.Running:
                    myUnitTestResultManager.TestStarting(unitTestElement,
                                                         firstRun.Launch.Session);
                    break;

                case Status.Passed:
                case Status.Failed:
                    var taskResult = result.Status == Status.Failed ? TaskResult.Error : TaskResult.Success;
                    var message    = result.Status == Status.Failed ? "Failed" : "Passed";

                    myUnitTestResultManager.TestOutput(unitTestElement, firstRun.Launch.Session, result.Output, TaskOutputType.STDOUT);
                    myUnitTestResultManager.TestDuration(unitTestElement, firstRun.Launch.Session, TimeSpan.FromMilliseconds(result.Duration));
                    myUnitTestResultManager.TestFinishing(unitTestElement,
                                                          firstRun.Launch.Session, message, taskResult);
                    break;

                default:
                    throw new ArgumentOutOfRangeException(
                        $"Unknown test result from the protocol: {result.Status}");
                }
            });

            launch.RunResult.Advise(connectionLifetime, result =>
            {
                tcs.SetResult(true);
            });

            unityModel.UnitTestLaunch.Value = launch;
        }
コード例 #14
0
 public override void Run(string remotingAddress, IUnitTestRun run)
 {
     if (run.IsSilverlightRun())
     {
         RunWithSilverlightDebugger(remotingAddress, run);
     }
     else
     {
         base.Run(remotingAddress, run);
     }
 }
コード例 #15
0
 public override void Run(IUnitTestRun run)
 {
     if (run.IsSilverlightRun())
     {
         RunWithSilverlightDebugger(run);
     }
     else
     {
         base.Run(run);
     }
 }
コード例 #16
0
 public override void Run(IUnitTestRun run)
 {
     if (run.IsSilverlightRun())
     {
         RunWithSilverlightDebugger(run);
     }
     else
     {
         base.Run(run);
     }
 }
コード例 #17
0
 public override void Run(string remotingAddress, IUnitTestRun run)
 {
     if (run.IsSilverlightRun())
     {
         RunWithSilverlightDebugger(remotingAddress, run);
     }
     else
     {
         base.Run(remotingAddress, run);
     }
 }
コード例 #18
0
 public void Cancel(IUnitTestRun run)
 {
     mySolution.Locks.ExecuteOrQueueEx(run.Lifetime, "CancellingUnitTests", () =>
     {
         var launchProperty = myEditorProtocol.UnityModel.Value?.UnitTestLaunch;
         if (launchProperty != null && launchProperty.HasValue())
         {
             launchProperty.Value?.Abort.Start(Unit.Instance);
         }
         run.GetData(ourCompletionSourceKey).NotNull().SetCanceled();
     });
 }
コード例 #19
0
        private void RunWithSilverlightDebugger(string remotingAddress, IUnitTestRun run)
        {
            var targetInfo = CreateTargetInfo(remotingAddress, run);

            this.SetField("myRunId", run.ID);
            this.SetField("myTargetInfo", targetInfo);

            new Thread(CallThreadProc)
            {
                IsBackground = true
            }.Start();
        }
コード例 #20
0
        public void Run(
            Lifetime lifetime,
            ITaskRunnerHostController runController,
            IUnitTestRun run,
            IUnitTestLaunch launch,
            Action continuation)
        {
            launch.EnsureSilverlightPlatformSupport(ref run, this.provider, runController);

            this.strategy = new OutOfProcessUnitTestRunStrategy(SilverlightUnitTestProvider.GetTaskRunnerInfo(launch));
            this.strategy.Run(lifetime, runController, run, launch, continuation);
        }
コード例 #21
0
        public void Run(Lifetime lifetime, ITaskRunnerHostController runController, IUnitTestRun run, IUnitTestLaunch launch,
			Action continuation)
        {
            foreach (var project in run.Elements.OfType<Element>().GroupBy(x => x.ProjectFolder))
            {
                var projectFolder = project.Key;
                foreach (var set in project.GroupBy(x => x.IsE2E))
                {
                    KarmaTestRunner.Run(launch, projectFolder, set, set.Key);
                }
            }
            launch.Finished();
        }
コード例 #22
0
 public void Run(Lifetime lifetime, ITaskRunnerHostController runController, IUnitTestRun run, IUnitTestLaunch launch,
                 Action continuation)
 {
     foreach (var project in run.Elements.OfType <Element>().GroupBy(x => x.ProjectFolder))
     {
         var projectFolder = project.Key;
         foreach (var set in project.GroupBy(x => x.IsE2E))
         {
             KarmaTestRunner.Run(launch, projectFolder, set, set.Key);
         }
     }
     launch.Finished();
 }
        public Task PrepareForRun(IUnitTestRun run, ITaskRunnerHostController next)
        {
            var lifetimeDef = myLifetime.CreateNested();

            run.PutData(ourLifetimeDefinitionKey, lifetimeDef);

            lock (myStartUnitySync)
            {
                WrapStartUnityTask(() => PrepareForRunInternal(lifetimeDef.Lifetime, run));
                WrapStartUnityTask(() => next.PrepareForRun(run));

                return(myStartUnityTask);
            }
        }
コード例 #24
0
        Task IUnitTestRunStrategy.Run(IUnitTestRun run)
        {
            lock (myCurrentLaunchesTaskAccess)
            {
                var cancellationTs = new CancellationTokenSource();
                run.Lifetime.OnTermination(cancellationTs.Cancel);
                run.PutData(ourCancellationTokenSourceKey, cancellationTs);

                var newLaunchTask = myCurrentLaunchesTask.ContinueWith(_ => Run(run), cancellationTs.Token).Unwrap();
                myCurrentLaunchesTask = Task.WhenAll(myCurrentLaunchesTask, newLaunchTask);

                return(newLaunchTask);
            }
        }
コード例 #25
0
        private IEnumerable <IUnitTestElement> CollectElementsToRunInUnityEditor(IUnitTestRun firstRun)
        {
            var result = new JetHashSet <IUnitTestElement>();

            foreach (var unitTestRun in firstRun.Launch.Runs)
            {
                if (unitTestRun.RunStrategy.Equals(this))
                {
                    result.AddRange(unitTestRun.Elements);
                }
            }

            return(result.ToList());
        }
コード例 #26
0
        Task IUnitTestRunStrategy.Run(IUnitTestRun run)
        {
            var key = run.Launch.GetData(ourLaunchedInUnityKey);

            if (key != null)
            {
                return(Task.FromResult(false));
            }

            var hostId = run.HostController.HostId;

            if (hostId == WellKnownHostProvidersIds.DebugProviderId)
            {
                run.Launch.Output.Error("Starting Unity tests from 'Debug' is currently unsupported. Please attach to editor and use 'Run'.");
                return(Task.FromResult(false));
            }

            if (hostId != WellKnownHostProvidersIds.RunProviderId)
            {
                run.Launch.Output.Error($"Starting Unity tests from '{hostId}' is currently unsupported. Please use `Run`.");
                return(Task.FromResult(false));
            }

            var tcs = new TaskCompletionSource <bool>();

            run.Launch.PutData(ourLaunchedInUnityKey, "smth");
            run.PutData(ourCompletionSourceKey, tcs);

            mySolution.Locks.ExecuteOrQueueEx(mySolution.GetLifetime(), "ExecuteRunUT", () =>
            {
                if (myUnityEditorProtocol.UnityModel.Value == null)
                {
                    return;
                }

                var currentConnectionLifetime = Lifetimes.Define(mySolution.GetLifetime());
                myUnityEditorProtocol.UnityModel.Change.Advise_NoAcknowledgement(currentConnectionLifetime.Lifetime, (args) =>
                {
                    if (args.HasNew && args.New == null)
                    {
                        currentConnectionLifetime.Terminate();
                    }
                });

                RunInternal(run, currentConnectionLifetime.Lifetime, myUnityEditorProtocol.UnityModel.Value, tcs);
            });

            return(tcs.Task);
        }
コード例 #27
0
        Task IUnitTestRunStrategy.Run(IUnitTestRun run)
        {
            var key = run.Launch.GetData(ourLaunchedInUnityKey);

            if (key != null)
            {
                return(Task.FromResult(false));
            }

            var tcs = new TaskCompletionSource <bool>();

            run.Launch.PutData(ourLaunchedInUnityKey, "smth");
            run.PutData(ourCompletionSourceKey, tcs);

            var hostId = run.HostController.HostId;

            switch (hostId)
            {
            case WellKnownHostProvidersIds.DebugProviderId:
                mySolution.Locks.ExecuteOrQueueEx(run.Lifetime, "AttachDebuggerToUnityEditor", () =>
                {
                    var task = myUnityHost.GetValue(model =>
                                                    model.AttachDebuggerToUnityEditor.Start(Unit.Instance));
                    task.Result.AdviseNotNull(run.Lifetime, result =>
                    {
                        if (!result.Result)
                        {
                            tcs.SetException(new Exception("Unable to attach debugger."));
                        }
                        else
                        {
                            RefreshAndRunTask(run, tcs);
                        }
                    });
                });
                break;

            case WellKnownHostProvidersIds.RunProviderId:
                RefreshAndRunTask(run, tcs);
                break;

            default:
                run.Launch.Output.Error(
                    $"Starting Unity tests from '{hostId}' is currently unsupported. Please use `Run`.");
                return(Task.FromResult(false));
            }

            return(tcs.Task);
        }
コード例 #28
0
        public static void AddTaskSequence(this IUnitTestRun run, RemoteTaskPacket sequence, SilverlightUnitTestElement silverlightElement, IUnitTestRun originalRun)
        {
            var runTasks = run.GetField<Dictionary<RemoteTask, IUnitTestElement>>("myTasks");
            var runTaskIdsToElements = run.GetField<Dictionary<string, IUnitTestElement>>("myTaskIdsToElements");
            var runElementsToTasks = run.GetField<Dictionary<IUnitTestElement, RemoteTask>>("myElementsToTasks");

            if (runTasks == null)
            {
                runTasks = new Dictionary<RemoteTask, IUnitTestElement>();
                run.SetField("myTasks", runTasks);
            }

            if (runTaskIdsToElements == null)
            {
                runTaskIdsToElements = new Dictionary<string, IUnitTestElement>();
                run.SetField("myTaskIdsToElements", runTaskIdsToElements);
            }

            if (runElementsToTasks == null)
            {
                runElementsToTasks = new Dictionary<IUnitTestElement, RemoteTask>();
                run.SetField("myElementsToTasks", runElementsToTasks);
            }

            foreach (var unitTestTask in sequence.GetAllTasksRecursive())
            {
                var element = originalRun.GetElementByRemoteTaskId(unitTestTask.Task.Id);

                runTasks[unitTestTask.Task] = element;

                if (element != null)
                {
                    runTaskIdsToElements[unitTestTask.Task.Id] = element;
                    runElementsToTasks[element] = unitTestTask.Task;
                }
            }

            run.GetRootTasks().Add(sequence);
            runTasks[sequence.Task] = silverlightElement;
            runTaskIdsToElements[sequence.Task.Id] = silverlightElement;
            runElementsToTasks[silverlightElement] = sequence.Task;
        }
コード例 #29
0
        public static void AddTaskSequence(this IUnitTestRun run, RemoteTaskPacket sequence, SilverlightUnitTestElement silverlightElement, IUnitTestRun originalRun)
        {
            var runTasks             = run.GetField <Dictionary <RemoteTask, IUnitTestElement> >("myTasks");
            var runTaskIdsToElements = run.GetField <Dictionary <string, IUnitTestElement> >("myTaskIdsToElements");
            var runElementsToTasks   = run.GetField <Dictionary <IUnitTestElement, RemoteTask> >("myElementsToTasks");

            if (runTasks == null)
            {
                runTasks = new Dictionary <RemoteTask, IUnitTestElement>();
                run.SetField("myTasks", runTasks);
            }

            if (runTaskIdsToElements == null)
            {
                runTaskIdsToElements = new Dictionary <string, IUnitTestElement>();
                run.SetField("myTaskIdsToElements", runTaskIdsToElements);
            }

            if (runElementsToTasks == null)
            {
                runElementsToTasks = new Dictionary <IUnitTestElement, RemoteTask>();
                run.SetField("myElementsToTasks", runElementsToTasks);
            }

            foreach (var unitTestTask in sequence.GetAllTasksRecursive())
            {
                var element = originalRun.GetElementByRemoteTaskId(unitTestTask.Task.Id);

                runTasks[unitTestTask.Task] = element;

                if (element != null)
                {
                    runTaskIdsToElements[unitTestTask.Task.Id] = element;
                    runElementsToTasks[element] = unitTestTask.Task;
                }
            }

            run.GetRootTasks().Add(sequence);
            runTasks[sequence.Task] = silverlightElement;
            runTaskIdsToElements[sequence.Task.Id] = silverlightElement;
            runElementsToTasks[silverlightElement] = sequence.Task;
        }
コード例 #30
0
        private VsDebugTargetInfo2 CreateTargetInfo(string remotingAddress, IUnitTestRun run)
        {
            var runnerPath = GetTaskRunnerPathForRun(run);
            var runnerArgs = GetTaskRunnerCommandLineArgs(remotingAddress, run.ID);
            var silverlightDebugEngineGuid = new Guid("032F4B8C-7045-4B24-ACCF-D08C9DA108FE");

            var debugTargetInfo = new VsDebugTargetInfo2
            {
                dlo                   = 1U,
                bstrExe               = runnerPath.FullPath,
                bstrCurDir            = runnerPath.Directory.FullPath,
                bstrArg               = runnerArgs,
                guidLaunchDebugEngine = silverlightDebugEngineGuid,
                LaunchFlags           = 97U
            };

            debugTargetInfo.cbSize = (uint)Marshal.SizeOf(debugTargetInfo);

            return(debugTargetInfo);
        }
コード例 #31
0
 private bool ShouldDisableAllConcurrency(IUnitTestRun run)
 {
     // Code coverage (and therefore continuous testing) and dotMemoryUnit cannot handle
     // tests running concurrently (code coverage and memory usage need to be tied back
     // to a specific test), so we need to disable concurrency in these environments. For
     // xunit, this means disabling parallelisation and async reporting of test messages.
     // This is likely to be set automatically in the test runner process by the ReSharper
     // test hosts - TaskExecutorConfiguration.DisallowTestConcurrency or some such.
     // See https://youtrack.jetbrains.com/issue/DCVR-7804
     switch (run.Launch.HostProvider.ID)
     {
     // TODO: It would be nice to use the actual constants, but they're not referenced
     // case ContinuousTestingHostProvider.ContinuousTestingHostProviderId:
     case "ContinuousTestingHostProviderId":
     case "Cover":
     case "dotMemoryUnit":
         return(true);
     }
     return(false);
 }
コード例 #32
0
        private VsDebugTargetInfo2 CreateTargetInfo(IUnitTestRun run)
        {
            var runnerPath = GetTaskRunnerPathForRun(run);
            var runnerArgs = GetTaskRunnerCommandLineArgs(run.ID, port);
            var silverlightDebugEngineGuid = new Guid("032F4B8C-7045-4B24-ACCF-D08C9DA108FE");

            var debugTargetInfo = new VsDebugTargetInfo2
            {
                dlo = 1U,
                bstrExe = runnerPath.FullPath,
                bstrCurDir = runnerPath.Directory.FullPath,
                bstrArg = runnerArgs,
                guidLaunchDebugEngine = silverlightDebugEngineGuid,
                LaunchFlags = 97U
            };

            debugTargetInfo.cbSize = (uint)Marshal.SizeOf(debugTargetInfo);

            return debugTargetInfo;
        }
コード例 #33
0
        private static void ConvertToSilverlightSequenceIfNecessary(RemoteTaskPacket sequence, IUnitTestRun run, IUnitTestLaunch launch, UnitTestProviders providers, ITaskRunnerHostController hostController)
        {
            if (!sequence.IsSilverlightSequence())
            {
                var silverlightProject = sequence.GetSilverlightProject(run);
                if (silverlightProject != null)
                {
                    var silverlightRun = launch.GetOrCreateSilverlightRun(silverlightProject.PlatformID, providers, hostController);

                    var provider = providers.GetProvider(SilverlightUnitTestProvider.RunnerId);
                    var silverlightElement = new SilverlightUnitTestElement(provider, silverlightRun.Key.RunStrategy);

                    var remoteTask = new SilverlightUnitTestTask(silverlightProject.PlatformID.Version, silverlightProject.GetXapPath(), silverlightProject.GetDllPath());

                    var silverlightSequence = new RemoteTaskPacket(remoteTask) { TaskPackets = { sequence } };

                    run.GetRootTasks().Remove(sequence);
                    silverlightRun.Value.AddTaskSequence(silverlightSequence, silverlightElement, run);
                }
            }
        }
コード例 #34
0
        private UnitTestLaunch SetupLaunch(IUnitTestRun firstRun)
        {
            var rdUnityModel = mySolution.GetProtocolSolution().GetRdUnityModel();

            var unitTestElements = CollectElementsToRunInUnityEditor(firstRun);
            var tests            = InitElementsMap(unitTestElements);
            var emptyList        = new List <string>();

            var mode = TestMode.Edit;

            if (rdUnityModel.UnitTestPreference.HasValue())
            {
                mode = rdUnityModel.UnitTestPreference.Value == UnitTestLaunchPreference.PlayMode
                    ? TestMode.Play
                    : TestMode.Edit;
            }

            var launch = new UnitTestLaunch(tests, emptyList, emptyList, mode);

            return(launch);
        }
コード例 #35
0
        private static void ConvertToSilverlightSequenceIfNecessary(RemoteTaskPacket sequence, ref IUnitTestRun run, IUnitTestLaunch launch, IUnitTestProvider provider, ITaskRunnerHostController hostController)
        {
            if (!sequence.IsSilverlightSequence())
            {
                var silverlightProject = sequence.GetSilverlightProject(run);
                if (silverlightProject != null)
                {
                    var silverlightRun = launch.GetOrCreateSilverlightRun(silverlightProject.PlatformID, provider, hostController);

                    var silverlightElement = new SilverlightUnitTestElement(new UnitTestElementId(provider, run.Elements.First().Id.PersistentProjectId, Guid.NewGuid().ToString()), silverlightRun.Key.RunStrategy);

                    var remoteTask = new SilverlightUnitTestTask(silverlightProject.PlatformID.Version, silverlightProject.GetXapPath(), silverlightProject.GetDllPath());

                    var silverlightSequence = new RemoteTaskPacket(remoteTask) { TaskPackets = { sequence } };

                    run.GetRootTasks().Remove(sequence);
                    silverlightRun.Value.AddTaskSequence(silverlightSequence, silverlightElement, run);
                    run = silverlightRun.Value;
                }
            }
        }
コード例 #36
0
        Task IUnitTestRunStrategy.Run(IUnitTestRun run)
        {
            lock (myCurrentLaunchesTaskAccess)
            {
                var key = run.Launch.GetData(ourLaunchedInUnityKey);
                if (key != null)
                {
                    return(Task.FromResult(false));
                }

                run.Launch.PutData(ourLaunchedInUnityKey, "smth");

                var cancellationTs = new CancellationTokenSource();
                run.Lifetime.OnTermination(cancellationTs.Cancel);
                run.PutData(ourCancellationTokenSourceKey, cancellationTs);

                var newLaunchTask = myCurrentLaunchesTask.ContinueWith(_ => Run(run), cancellationTs.Token).Unwrap();
                myCurrentLaunchesTask = Task.WhenAll(myCurrentLaunchesTask, newLaunchTask);

                return(newLaunchTask);
            }
        }
コード例 #37
0
 public IList<UnitTestTask> GetTaskSequence(ICollection<IUnitTestElement> explicitElements, IUnitTestRun run)
 {
     return GetTaskSequence(explicitElements);
 }
コード例 #38
0
 public void Abort(ITaskRunnerHostController runController, IUnitTestRun run)
 {
     this.strategy.Abort(runController, run);
 }
コード例 #39
0
 public void Cancel(ITaskRunnerHostController runController, IUnitTestRun run)
 {
     this.strategy.Cancel(runController, run);
 }
コード例 #40
0
 public void Cancel(ITaskRunnerHostController runController, IUnitTestRun run)
 {
 }
コード例 #41
0
 public IList <UnitTestTask> GetTaskSequence([NotNull] ICollection <IUnitTestElement> explicitElements, [NotNull] IUnitTestRun run)
 {
     return(GetTaskSequence(explicitElements, init: true));
 }
コード例 #42
0
 public abstract IList<UnitTestTask> GetTaskSequence(ICollection<IUnitTestElement> explicitElements, IUnitTestRun run);
コード例 #43
0
 public void Abort(ITaskRunnerHostController runController, IUnitTestRun run)
 {
 }
コード例 #44
0
        public IList<UnitTestTask> GetTaskSequence(ICollection<IUnitTestElement> explicitElements, IUnitTestRun run)
        {
            if (this is ContextSpecificationElement)
            {
                var contextSpecification = this as ContextSpecificationElement;
                var context = contextSpecification.Context;

                return new List<UnitTestTask>
               {
                 this._taskFactory.CreateRunAssemblyTask(context),
                 this._taskFactory.CreateContextTask(context),
                 this._taskFactory.CreateContextSpecificationTask(context, contextSpecification)
               };
            }

            if (this is BehaviorSpecificationElement)
            {
                var behaviorSpecification = this as BehaviorSpecificationElement;
                var behavior = behaviorSpecification.Behavior;
                var context = behavior.Context;

                return new List<UnitTestTask>
               {
                 this._taskFactory.CreateRunAssemblyTask(context),
                 this._taskFactory.CreateContextTask(context),
                 this._taskFactory.CreateBehaviorSpecificationTask(context, behaviorSpecification)
               };
            }

            if (this is ContextElement || this is BehaviorElement)
            {
                return EmptyArray<UnitTestTask>.Instance;
            }

            throw new ArgumentException(String.Format("Element is not a Machine.Specifications element: '{0}'", this));
        }
コード例 #45
0
        private void RefreshAndRunTask(IUnitTestRun run, TaskCompletionSource <bool> tcs, Lifetime taskLifetime)
        {
            var cancellationTs    = run.GetData(ourCancellationTokenSourceKey);
            var cancellationToken = cancellationTs.NotNull().Token;

            myLogger.Trace("Before calling Refresh.");
            Refresh(run.Lifetime, tcs, cancellationToken).ContinueWith(__ =>
            {
                if (tcs.Task.IsCanceled || tcs.Task.IsFaulted) // Refresh failed or was stopped
                {
                    return;
                }

                myLogger.Trace("Refresh. OnCompleted.");
                // KS: Can't use run.Lifetime for ExecuteOrQueueEx here and in all similar places: run.Lifetime is terminated when
                // Unit Test Session is closed from UI without cancelling the run. This will leave task completion source in running state forever.
                mySolution.Locks.ExecuteOrQueueEx(myLifetime, "Check compilation", () =>
                {
                    if (!run.Lifetime.IsAlive || cancellationTs.IsCancellationRequested)
                    {
                        tcs.TrySetCanceled();
                        return;
                    }

                    if (myBackendUnityHost.BackendUnityModel.Value == null)
                    {
                        tcs.SetException(new Exception("Unity Editor connection unavailable."));
                        return;
                    }

                    var filters = GetFilters(run);

                    UnitTestLaunchClientControllerInfo unityClientControllerInfo = null;
                    var clientControllerInfo = run.HostController.GetClientControllerInfo(run);
                    if (clientControllerInfo != null)
                    {
                        unityClientControllerInfo = new UnitTestLaunchClientControllerInfo(
                            clientControllerInfo.AssemblyLocation,
                            clientControllerInfo.ExtraDependencies?.ToList(),
                            clientControllerInfo.TypeName);
                    }

                    var frontendBackendModel = mySolution.GetProtocolSolution().GetFrontendBackendModel();
                    myUsageStatistics.TrackActivity("UnityUnitTestPreference", frontendBackendModel.UnitTestPreference.Value.ToString());
                    var mode = TestMode.Edit;
                    if (frontendBackendModel.UnitTestPreference.Value == UnitTestLaunchPreference.PlayMode)
                    {
                        mode = TestMode.Play;
                    }
                    var launch = new UnitTestLaunch(run.Launch.Session.Id, filters, mode, unityClientControllerInfo);

                    myBackendUnityHost.BackendUnityModel.ViewNotNull(taskLifetime, (lt, model) =>
                    {
                        // recreate UnitTestLaunch in case of AppDomain.Reload, which is the case with PlayMode tests
                        myLogger.Trace("UnitTestLaunch.SetValue.");
                        if (frontendBackendModel.UnitTestPreference.Value == UnitTestLaunchPreference.Both)
                        {
                            model.UnitTestLaunch.SetValue(launch);
                            SubscribeResults(run, lt, launch);
                            launch.RunResult.Advise(lt, result =>
                            {
                                if (launch.TestMode == TestMode.Play)
                                {
                                    tcs.SetResult(result.Passed);
                                }
                                else
                                {
                                    launch = new UnitTestLaunch(launch.SessionId, launch.TestFilters, TestMode.Play,
                                                                launch.ClientControllerInfo);
                                    model.UnitTestLaunch.SetValue(launch);
                                    SubscribeResults(run, lt, launch);
                                    StartTests(run, tcs, lt);
                                }
                            });
                        }
                        else
                        {
                            model.UnitTestLaunch.SetValue(launch);
                            SubscribeResults(run, lt, launch);
                            launch.RunResult.Advise(lt, result => { tcs.SetResult(result.Passed); });
                        }
                    });

                    StartTests(run, tcs, taskLifetime);

                    // set results for explicit tests
                    foreach (var element in run.Elements.OfType <NUnitElementBase>().Where(a =>
                                                                                           a.RunState == RunState.Explicit && !run.Launch.Criterion.Explicit.Contains(a)))
                    {
                        myUnitTestResultManager.TestFinishing(element, run.Launch.Session,
                                                              "Test should be run explicitly", UnitTestStatus.Ignored);
                    }
                });
            }, cancellationToken);
        }
コード例 #46
0
        private void RefreshAndRunTask(IUnitTestRun run, TaskCompletionSource <bool> tcs, Lifetime taskLifetime)
        {
            var cancellationTs = run.GetData(ourCancellationTokenSourceKey);

            myLogger.Verbose("Before calling Refresh.");
            Refresh(run.Lifetime, cancellationTs.NotNull().Token).GetAwaiter().OnCompleted(() =>
            {
                // KS: Can't use run.Lifetime for ExecuteOrQueueEx here and in all similar places: run.Lifetime is terminated when
                // Unit Test Session is closed from UI without cancelling the run. This will leave task completion source in running state forever.
                mySolution.Locks.ExecuteOrQueueEx(myLifetime, "Check compilation", () =>
                {
                    if (!run.Lifetime.IsAlive || cancellationTs.IsCancellationRequested)
                    {
                        tcs.SetCanceled();
                        return;
                    }

                    if (myEditorProtocol.UnityModel.Value == null)
                    {
                        myLogger.Verbose("Unity Editor connection unavailable.");
                        tcs.SetException(new Exception("Unity Editor connection unavailable."));
                        return;
                    }

                    var task = myEditorProtocol.UnityModel.Value.GetCompilationResult.Start(Unit.Instance);
                    task.Result.AdviseNotNull(myLifetime, result =>
                    {
                        if (!run.Lifetime.IsAlive || cancellationTs.IsCancellationRequested)
                        {
                            tcs.SetCanceled();
                        }
                        else if (!result.Result)
                        {
                            tcs.SetException(new Exception("There are errors during compilation in Unity."));

                            mySolution.Locks.ExecuteOrQueueEx(run.Lifetime, "RunViaUnityEditorStrategy compilation failed",
                                                              () =>
                            {
                                var notification = new NotificationModel("Compilation failed",
                                                                         "Script compilation in Unity failed, so tests were not started.", true,
                                                                         RdNotificationEntryType.INFO);
                                myNotificationsModel.Notification(notification);
                            });
                            myUnityHost.PerformModelAction(model => model.ActivateUnityLogView());
                        }
                        else
                        {
                            var launch = SetupLaunch(run);
                            mySolution.Locks.ExecuteOrQueueEx(myLifetime, "ExecuteRunUT", () =>
                            {
                                if (!run.Lifetime.IsAlive || cancellationTs.IsCancellationRequested)
                                {
                                    tcs.SetCanceled();
                                    return;
                                }

                                if (myEditorProtocol.UnityModel.Value == null)
                                {
                                    tcs.SetException(new Exception("Unity Editor connection unavailable."));
                                    return;
                                }

                                myEditorProtocol.UnityModel.ViewNotNull(taskLifetime, (lt, model) =>
                                {
                                    // recreate UnitTestLaunch in case of AppDomain.Reload, which is the case with PlayMode tests
                                    model.UnitTestLaunch.SetValue(launch);
                                    SubscribeResults(run, lt, tcs, launch);
                                });

                                myUnityProcessId.When(taskLifetime, (int?)null, _ => tcs.TrySetException(new Exception("Unity Editor has been closed.")));

                                var rdTask = myEditorProtocol.UnityModel.Value.RunUnitTestLaunch.Start(Unit.Instance);
                                rdTask?.Result.Advise(taskLifetime, res =>
                                {
                                    myLogger.Trace($"RunUnitTestLaunch result = {res.Result}");
                                    if (!res.Result)
                                    {
                                        var defaultMessage = "Failed to start tests in Unity.";

                                        var isCoverage =
                                            run.HostController.HostId != WellKnownHostProvidersIds.DebugProviderId &&
                                            run.HostController.HostId != WellKnownHostProvidersIds.RunProviderId;

                                        if (myPackageValidator.HasNonCompatiblePackagesCombination(isCoverage, out var message))
                                        {
                                            defaultMessage = $"{defaultMessage} {message}";
                                        }

                                        if (myEditorProtocol.UnityModel.Value.UnitTestLaunch.Value.TestMode == TestMode.Play)
                                        {
                                            if (!myPackageValidator.CanRunPlayModeTests(out var playMessage))
                                            {
                                                defaultMessage = $"{defaultMessage} {playMessage}";
                                            }
                                        }

                                        tcs.TrySetException(new Exception(defaultMessage));
                                    }
                                });
                            });
                        }
                    });
コード例 #47
0
 public abstract IList <UnitTestTask> GetTaskSequence(ICollection <IUnitTestElement> explicitElements, IUnitTestRun run);
コード例 #48
0
 public static IEnumerable <RemoteTaskPacket> GetAllTasks(this IUnitTestRun run)
 {
     return(run.GetTasks().SelectMany(t => t.GetAllTasksRecursive()));
 }