Esempio n. 1
0
        public static void Run()
        {
            // Enable autoflush of traces at the framework level
            Trace.AutoFlush = true;

            Log log = LogManager.CurrentLog;

            new TestLog(DriverState.TestName); //Hack: need a test log instance to record presence of not yet existent files
            StabilityTestDefinition testDefinition = new StabilityTestDefinition(DriverState.DriverParameters);
            IActionScheduler        scheduler      = (IActionScheduler)Activator.CreateInstance(testDefinition.SchedulerType);

            // HACK: Quality Vault doesn't support get arguments from command line. Passing StressRunHours through Environment variable instead.
            // Workaround TFS 822025
            double stressRunHours = 0;

            if (double.TryParse(Environment.GetEnvironmentVariable("StressRunHours"), out stressRunHours))
            {
                testDefinition.ExecutionTime = TimeSpan.FromHours(stressRunHours);
            }


            log.CurrentVariation.LogMessage("Starting Stress Run at: {0}.", DateTime.Now);
            log.CurrentVariation.LogMessage("Run should end at: {0}", DateTime.Now + testDefinition.ExecutionTime);
            log.CurrentVariation.LogMessage("Test name: {0}", DriverState.TestName);
            scheduler.Run(testDefinition);

            log.CurrentVariation.LogMessage("The test has ended itself.");
            log.CurrentVariation.LogResult(Result.Pass);
            log.CurrentVariation.Close();
        }
Esempio n. 2
0
            public void DoWork(StabilityTestDefinition metadata, int threadId)
            {
                int              iteration        = 0;
                DateTime         startTime        = DateTime.Now;
                DateTime         endTime          = startTime.Add(metadata.ExecutionTime);
                ExecutionContext executionContext = new ExecutionContext(metadata.ExecutionContext);

                executionContext.ResetState(threadId);

                //Add a stress trace listener so we can capture traces from test and Fail events
                Trace.Listeners.Add(new TraceManager(threadId));

                //make sure that exceptions are not caught by the dispatcher
                Dispatcher.CurrentDispatcher.UnhandledExceptionFilter += delegate(object sender, DispatcherUnhandledExceptionFilterEventArgs e) { e.RequestCatch = false; };
                while (DateTime.Now < endTime)
                {
                    Trace.WriteLine("[Scheduler] Starting Iteration:" + iteration);
                    Trace.WriteLine(String.Format("[Scheduler] StartTime: {0}, Current Time: {1} End Time: {2} ", startTime, DateTime.Now, endTime));

                    //Set up the iteration's randomness
                    DeterministicRandom random = new DeterministicRandom(metadata.RandomSeed, threadId, iteration);
                    DoNextActionSequence(random, executionContext, threadId);

                    Trace.WriteLine("[Scheduler] Pushing Frame onto Dispatcher");
                    DispatcherHelper.DoEvents((int)idleDuration.TotalMilliseconds, DispatcherPriority.Background);

                    Trace.WriteLine("[Scheduler] Dispatcher queue has been executed.");

                    //Visual Space for Logging readability
                    Trace.WriteLine("");
                    Trace.WriteLine("");
                    iteration++;
                }
                Trace.WriteLine(String.Format("[Scheduler] Test is ending at {0}, after running for {1}.", endTime, metadata.ExecutionTime));
            }
Esempio n. 3
0
        private void WorkInSharedAppdomain(StabilityTestDefinition metadata, int threadId)
        {
            //The Marshaled worker class should behave normally in context of it's own domain
            MarshaledWorker worker = new MarshaledWorker();

            worker.DoWork(metadata, threadId);
        }
Esempio n. 4
0
        /// <summary>
        /// Run the Stress Scheduler. This will not terminate.
        /// </summary>
        public void Run(StabilityTestDefinition metadata)
        {
            RegisterLogs(metadata.NumWorkerThreads);
            idleDuration = metadata.IdleDuration;

            List <Thread> threads = new List <Thread>();

            // Don't sends Trace to Logger.
            TraceManager.RemoveTraceToLoggerAdaptor();

            if (metadata.NumWorkerThreads != 0)
            {
                //Spin up a set of worker threads to do cool stress stuff.
                for (int i = 0; i < metadata.NumWorkerThreads; i++)
                {
                    threads.Add(InvokeThread(metadata, i));
                }

                //Let worker threads do their thing until execution time limit completes
                Thread.Sleep(metadata.ExecutionTime);
            }
            else //In case of zero worker thread, just do the job in existing thread.
            {
                RegisterLog(TraceManager.GetFileName(0, -1));
                WorkInSharedAppdomain(metadata, -1);
            }

            //Do blocking joins on workers. If they don't exit promptly, that's an epic fail.
            TimeSpan timeoutDelay = TimeSpan.FromSeconds(900);

            while (threads.Count > 0)
            {
                bool joinSuccessfully = threads[threads.Count - 1].Join(timeoutDelay);

                if (!joinSuccessfully)
                {
                    Trace.WriteLine(String.Format("Threads failed to terminate, after waiting for {0}:\n", timeoutDelay.ToString()));

                    //Debug Instruction
                    Trace.WriteLine(@"Please open the trace file under the working directory. 
                                     If the iteration in each thread just started shortly, 
                                     click 'g' to continue. Otherwise, debug the remote to 
                                     figure out what has caused the worker thread(s) to hang. ");

                    // break in the jit debugger.
                    Debugger.Break();
                }
                else
                {
                    threads.RemoveAt(threads.Count - 1);
                }
            }
        }
Esempio n. 5
0
        /// <summary>
        /// Configures a new Appdomain for executing the stress test within
        /// </summary>
        /// <param name="metadata"></param>
        /// <param name="threadId"></param>
        private void WorkInNewAppDomain(StabilityTestDefinition metadata, int threadId)
        {
            AppDomainSetup ads = new AppDomainSetup();

            ads.ApplicationBase          = System.Environment.CurrentDirectory;
            ads.DisallowBindingRedirects = false;
            ads.DisallowCodeDownload     = false;
            ads.ConfigurationFile        = AppDomain.CurrentDomain.SetupInformation.ConfigurationFile;
            string exeAssembly       = Assembly.GetEntryAssembly().FullName;
            string callingDomainName = Thread.GetDomain().FriendlyName;

            AppDomain       a      = AppDomain.CreateDomain("Worker " + threadId.ToString(), null, ads);
            MarshaledWorker worker = (MarshaledWorker)a.CreateInstanceAndUnwrap(Assembly.GetCallingAssembly().FullName, typeof(MarshaledWorker).FullName);

            worker.DoWork(metadata, threadId);
            AppDomain.Unload(a);
        }
Esempio n. 6
0
        /// <summary>
        /// Runs a thread configured with the specified metadata.
        /// </summary>
        /// <param name="metadata"></param>
        /// <param name="threadId"></param>
        /// <returns></returns>
        private Thread InvokeThread(StabilityTestDefinition metadata, int threadId)
        {
            Thread t = new Thread(delegate()
            {
                if (metadata.IsolateThreadsInAppdomains)
                {
                    WorkInNewAppDomain(metadata, threadId);
                }
                else
                {
                    WorkInSharedAppdomain(metadata, threadId);
                }
            });

            t.SetApartmentState(ApartmentState.STA);

            //HACK: It is important that worker thread names contain threadID in them.
            //It is used to filter trace messages by thread and write to separate log files.
            //See TraceManager.WriteLine().
            t.Name = String.Format("{0} Worker: {1}", DriverState.TestName, threadId);

            t.Start();
            return(t);
        }