Exemplo n.º 1
0
        public static IMonitorLoader LoadMonitorLoaderAssembly()

        {
            IMonitorLoader monitorloader = null;
            const string   classname     = "Monitoring.MonitorLoader";
            const string   interfacename = "IMonitorLoader";
            Assembly       mainAssembly  = typeof(Monitoring.IMonitorLoader).GetTypeInfo().Assembly;

            Type t = mainAssembly.GetType(classname);

            //make sure the type is derived from IMonitorLoader
            Type[] interfaces = t.GetInterfaces();
            bool   derivedFromIMonitorLoader = false;

            if (interfaces != null)
            {
                foreach (Type intrface in interfaces)
                {
                    if (intrface.Name == interfacename)
                    {
                        derivedFromIMonitorLoader = true;
                    }
                }
            }
            if (derivedFromIMonitorLoader)

            {
                monitorloader = (IMonitorLoader)Activator.CreateInstance(t);

                monitorloader.AssemblyPath = mainAssembly.FullName;
            }
            else
            {
                throw new Exception("The specified assembly does not implement " + interfacename + "!!");
            }
            return(monitorloader);
        }
Exemplo n.º 2
0
        public int Run()
        {
            TraceListener listener = new TextWriterTraceListener(Console.Out);

            Trace.Listeners.Add(listener);
            Trace.UseGlobalLock = true;

            _threadsRunning = 0;
            _continue       = true;

            if (_allTests.Count == 0)
            {
                throw new ArgumentException("The specified assembly doesn't contain any tests to run. Test methods must be decorated with a Test, StressTest, MultiThreadedTest, or ThreadPoolTest attribute.");
            }

            // Run any global setup
            StressTest firstStressTest = _allTests.Find(t => t is StressTest);

            if (null != firstStressTest)
            {
                firstStressTest.RunGlobalSetup();
            }

            //Monitoring Start
            IMonitorLoader _monitorloader = null;

            if (TestMetrics.MonitorEnabled)
            {
                _monitorloader = MonitorLoader.LoadMonitorLoaderAssembly();
                if (_monitorloader != null)
                {
                    _monitorloader.Enabled     = TestMetrics.MonitorEnabled;
                    _monitorloader.HostMachine = TestMetrics.MonitorMachineName;
                    _monitorloader.TestName    = firstStressTest.Title;
                    _monitorloader.Action(MonitorLoaderUtils.MonitorAction.Start);
                }
            }

            for (int i = 0; i < _threads; i++)
            {
                Interlocked.Increment(ref _threadsRunning);
                Thread t = new Thread(new ThreadStart(this.RunStressThread));
                t.Start();
            }

            while (_threadsRunning > 0)
            {
                Thread.Sleep(1000);
            }

            //Monitoring Stop
            if (TestMetrics.MonitorEnabled)
            {
                if (_monitorloader != null)
                {
                    _monitorloader.Action(MonitorLoaderUtils.MonitorAction.Stop);
                }
            }

            // Run any global cleanup
            if (null != firstStressTest)
            {
                firstStressTest.RunGlobalCleanup();
            }

            // Write out all exceptions
            _exceptions.TraceAllExceptions();
            return(_exceptions.GetExceptionsCount());
        }