Ejemplo n.º 1
0
        /// <summary>
        /// Runs the async load test info.
        /// </summary>
        /// <returns>The async load test info.</returns>
        /// <param name="cache">Cache.</param>
        /// <remarks>
        /// It loads the test case info from cache if there is something in the cache.
        ///
        /// Otherwise, the test case info is queried from xunit, by executing a separate process of <seealso cref="XUnitTestRunner"/>
        /// with MonoDevelop built-in .NET remoting helper.
        ///
        /// To debug, the .NET remoting part can be commented out, and replaced with direct calls to <seealso cref="XUnitTestRunner"/>.
        /// </remarks>
        void RunAsyncLoadTestInfo(XUnitTestInfoCache cache)
        {
            while (true)
            {
                XUnitAssemblyTestSuite testSuite;
                lock (loadQueue) {
                    if (loadQueue.Count == 0)
                    {
                        if (!Monitor.Wait(loadQueue, 5000, true))
                        {
                            isRunning = false;
                            return;
                        }
                    }
                    testSuite = loadQueue.Dequeue();
                }

                XUnitTestInfo testInfo;

                try {
                    // If the information is cached in a file and it is up to date information,
                    // there is no need to parse again the assembly.

                    if (cache.Exists)
                    {
                        cache.ReadFromDisk();
                        testInfo = cache.GetTestInfo();
                        if (testInfo != null)
                        {
                            testSuite.OnTestSuiteLoaded(testInfo);
                            continue;
                        }
                    }

#if EASY_DEBUGGING
                    var runner = new XUnitRunner.XUnitRunner();
                    testInfo = runner.GetTestInfo(testSuite.AssemblyPath, testSuite.SupportAssemblies.ToArray());
                    testSuite.OnTestSuiteLoaded(testInfo);
#else
                    using (var runner = new ExternalTestRunner()) {
                        runner.Connect(XUnitVersion.XUnit2).Wait();
                        testInfo = runner.GetTestInfo(testSuite.AssemblyPath, testSuite.SupportAssemblies.ToList()).Result;
                        testSuite.OnTestSuiteLoaded(testInfo);
                    }
#endif
                } catch (Exception ex) {
                    LoggingService.LogError(ex.ToString());
                }
            }
        }
Ejemplo n.º 2
0
        static void RunAsyncLoadTest()
        {
            while (true)
            {
                LoadData ld;
                lock (loadQueue) {
                    if (loadQueue.Count == 0)
                    {
                        if (!Monitor.Wait(loadQueue, 5000, true))
                        {
                            loaderRunning = false;
                            return;
                        }
                    }
                    ld = (LoadData)loadQueue.Dequeue();
                }

                try {
                    // If the information is cached in a file and it is up to date information,
                    // there is no need to parse again the assembly.

                    if (ld.TestInfoCachePath != null && File.Exists(ld.TestInfoCachePath))
                    {
                        ld.InfoCache = TestInfoCache.Read(ld.TestInfoCachePath);
                        NunitTestInfo info = ld.InfoCache.GetInfo(ld.Path);
                        if (info != null)
                        {
                            ld.Info = info;
                            ld.Callback(ld);
                            continue;
                        }
                    }
                } catch (Exception ex) {
                    LoggingService.LogError(ex.ToString());
                }

                ExternalTestRunner runner = null;

                try {
                    if (File.Exists(ld.Path))
                    {
                        runner  = (ExternalTestRunner)Runtime.ProcessService.CreateExternalProcessObject(typeof(ExternalTestRunner), false);
                        ld.Info = runner.GetTestInfo(ld.Path, ld.SupportAssemblies);
                    }
                } catch (Exception ex) {
                    Console.WriteLine(ex);
                    ld.Error = ex;
                }
                finally {
                    try {
                        if (runner != null)
                        {
                            runner.Dispose();
                        }
                    } catch {}
                }

                try {
                    ld.Callback(ld);
                } catch {
                }
            }
        }
        static void RunAsyncLoadTest()
        {
            while (true)
            {
                LoadData ld;
                lock (loadQueue) {
                    if (loadQueue.Count == 0)
                    {
                        if (!Monitor.Wait(loadQueue, 5000, true))
                        {
                            loaderRunning = false;
                            return;
                        }
                    }
                    ld = (LoadData)loadQueue.Dequeue();
                }

                try {
                    // If the information is cached in a file and it is up to date information,
                    // there is no need to parse again the assembly.

                    if (ld.TestInfoCachePath != null && File.Exists(ld.TestInfoCachePath))
                    {
                        ld.InfoCache = TestInfoCache.Read(ld.TestInfoCachePath);
                        NunitTestInfo info = ld.InfoCache.GetInfo(ld.Path);
                        if (info != null)
                        {
                            ld.Info = info;
                            ld.Callback(ld);
                            continue;
                        }
                    }
                } catch (Exception ex) {
                    LoggingService.LogError(ex.ToString());
                }

                ExternalTestRunner runner = null;

                try {
                    if (File.Exists(ld.Path))
                    {
                        runner = new ExternalTestRunner(Path.GetDirectoryName(ld.Path));
                        runner.ProcessExecutionArchitecture = AssemblyUtilities.GetProcessExecutionArchitectureForAssembly(ld.Path);
                        runner.Connect(ld.NUnitVersion).Wait();
                        var supportAssemblies = new List <string> (ld.SupportAssemblies.Result);
                        ld.Info = runner.GetTestInfo(ld.Path, supportAssemblies).Result;
                    }
                } catch (AggregateException exception) {
                    var baseException = exception.GetBaseException();
                    Console.WriteLine(baseException);
                    ld.Error = baseException;
                } catch (Exception exception) {
                    Console.WriteLine(exception);
                    ld.Error = exception;
                }
                finally {
                    try {
                        if (runner != null)
                        {
                            runner.Dispose();
                        }
                    } catch {}
                }

                try {
                    ld.Callback(ld);
                } catch {
                }
            }
        }