示例#1
0
        void AsyncCreateTests(object ob)
        {
            TestStatus newStatus = TestStatus.Ready;

            try
            {
                LoadData loadData = (LoadData)ob;

                if (loadData.Error != null)
                {
                    newStatus = TestStatus.LoadError;
                    return;
                }

                Tests.Clear();

                if (loadData.Info == null)
                {
                    oldList = new UnitTest [0];
                    return;
                }

                FillTests(loadData.Info);

                // If the async loader has loaded a cache, reuse it.
                if (loadData.InfoCache != null)
                {
                    testInfoCache = loadData.InfoCache;
                }

                testInfoCache.SetInfo(AssemblyPath, loadData.Info);
            }
            catch (Exception ex)
            {
                LoggingService.LogError(ex.ToString());
                newStatus = TestStatus.LoadError;
            }
            finally
            {
                lock (locker)
                {
                    Status = newStatus;
                    Monitor.PulseAll(locker);
                }
                OnTestChanged();
            }
        }
        void AsyncCreateTests(object ob)
        {
            TestStatus newStatus = TestStatus.Ready;

            try {
                LoadData loadData = (LoadData) ob;

                if (loadData.Error != null) {
                    newStatus = TestStatus.LoadError;
                    return;
                }

                Tests.Clear ();

                if (loadData.Info == null) {
                    oldList = new UnitTest [0];
                    return;
                }

                FillTests (loadData.Info);

                // If the async loader has loaded a cache, reuse it.
                if (loadData.InfoCache != null)
                    testInfoCache = loadData.InfoCache;

                testInfoCache.SetInfo (AssemblyPath, loadData.Info);
            }
            catch (Exception ex) {
                Console.WriteLine (ex);
                newStatus = TestStatus.LoadError;
            }
            finally {
                lock (locker) {
                    Status = newStatus;
                }
                OnTestChanged ();
            }
        }
示例#3
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 {
                }
            }
        }