Exemplo n.º 1
0
        private void RunMultithreaded(PerformCallDelegate remoteMethodCaller, int nrOfCalls, int nrOfThreads)
        {
            ArrayList methodRunners = new ArrayList();
            ArrayList threads       = new ArrayList();

            for (int i = 0; i < nrOfThreads; i++)
            {
                TimeSpan             delay = TimeSpan.FromMilliseconds(m_random.Next(7));
                RepeatedMethodCaller rmc1  = new RepeatedMethodCaller(nrOfCalls,
                                                                      delay, remoteMethodCaller,
                                                                      m_testService1);
                methodRunners.Add(rmc1);
                Thread sv1 = new Thread(new ThreadStart(rmc1.PerformCalls));
                threads.Add(sv1);
                sv1.Start();

                delay = TimeSpan.FromMilliseconds(m_random.Next(3));
                RepeatedMethodCaller rmc2 = new RepeatedMethodCaller(nrOfCalls,
                                                                     delay, remoteMethodCaller,
                                                                     m_testService2);
                methodRunners.Add(rmc2);
                Thread sv2 = new Thread(new ThreadStart(rmc2.PerformCalls));
                threads.Add(sv2);
                sv2.Start();
            }

            foreach (Thread t in threads)
            {
                t.Join(); // wait for thread to finish
            }

            StringBuilder exceptionMsg = new StringBuilder();
            bool          foundEx      = false;

            foreach (RepeatedMethodCaller rmc in methodRunners)
            {
                Exception[] exceptions = rmc.ExceptionsEncountered;
                if (exceptions.Length > 0)
                {
                    foundEx = true;
                    foreach (Exception ex in exceptions)
                    {
                        exceptionMsg.Append(ex.ToString() + "\n");
                    }
                }
            }
            if (foundEx)
            {
                throw new TestFailedException("the following exceptions were encountered while running the test:\n" +
                                              exceptionMsg.ToString());
            }
        }
Exemplo n.º 2
0
        private void RunMultithreaded(PerformCallDelegate remoteMethodCaller, int nrOfCalls, int nrOfThreads) {
            ArrayList methodRunners = new ArrayList();
            ArrayList threads = new ArrayList();
            for (int i = 0; i < nrOfThreads; i++) {
                TimeSpan delay = TimeSpan.FromMilliseconds(m_random.Next(7));
                RepeatedMethodCaller rmc1 = new RepeatedMethodCaller(nrOfCalls,
                                                                     delay, remoteMethodCaller,
                                                                     m_testService1);
                methodRunners.Add(rmc1);
                Thread sv1 = new Thread(new ThreadStart(rmc1.PerformCalls));
                threads.Add(sv1);
                sv1.Start();
                
                delay = TimeSpan.FromMilliseconds(m_random.Next(3));
                RepeatedMethodCaller rmc2 = new RepeatedMethodCaller(nrOfCalls,
                                                                     delay, remoteMethodCaller,
                                                                     m_testService2);
                methodRunners.Add(rmc2);
                Thread sv2 = new Thread(new ThreadStart(rmc2.PerformCalls));
                threads.Add(sv2);
                sv2.Start();
            }
            
            foreach (Thread t in threads) {
                t.Join(); // wait for thread to finish
            }
            
            StringBuilder exceptionMsg = new StringBuilder();
            bool foundEx = false;
            foreach (RepeatedMethodCaller rmc in methodRunners) {
                Exception[] exceptions = rmc.ExceptionsEncountered;
                if (exceptions.Length > 0) {
                    foundEx = true;
                    foreach (Exception ex in exceptions) {
                        exceptionMsg.Append(ex.ToString() + "\n");    
                    }
                }                
            }
            if (foundEx) {
                throw new TestFailedException("the following exceptions were encountered while running the test:\n" + 
                                              exceptionMsg.ToString());
            }

        }