Beispiel #1
0
        private void ExecuteTest_AutoReconnect(
            ChannelContext  channelContext, 
            TestCaseContext testCaseContext, 
            TestCase        testCase, 
            int             iteration)
        {
            Variant input;
            Variant output;

            // initialize test case.
            if (iteration == TestCases.TestSetupIteration)
            {
                m_fault = null;
                m_blackouts = new List<BlackoutPeriod>();
                channelContext.ClientSession.OperationTimeout = 30000;
                
                RequestHeader requestHeader = new RequestHeader();

                requestHeader.Timestamp = DateTime.UtcNow;
                requestHeader.ReturnDiagnostics = (uint)DiagnosticsMasks.All;

                ResponseHeader responseHeader = channelContext.ClientSession.TestStack(
                    null,
                    testCase.TestId,
                    TestCases.TestSetupIteration,
                    input,
                    out output);

                return;
            }

            if (iteration == TestCases.TestCleanupIteration)
            {
                do
                {
                    lock (m_lock)
                    {
                        if (m_requestCount == 0)
                        {
                            return;
                        }
                    }

                    Thread.Sleep(100);
                }
                while (true);
            }
                        
            Thread.Sleep(testCaseContext.RequestInterval);

            // report fault after waiting for all active threads to exit.
            if (m_sequenceToExecute.HaltOnError)
            {
                ServiceResult fault = null;

                lock (m_lock)
                {
                    fault = m_fault;
                }

                if (fault != null)
                {
                    do
                    {
                        lock (m_lock)
                        {
                            if (m_requestCount == 0)
                            {
                                throw new ServiceResultException(fault);
                            }
                        }

                        Thread.Sleep(100);
                    }
                    while (true);
                }
            }

            // begin iteration.                            
            channelContext.EventLogger.LogStartEvent(testCase, iteration);
                
            lock (m_lock)
            {
                // set up header.
                RequestHeader requestHeader = new RequestHeader();

                requestHeader.Timestamp = DateTime.UtcNow;
                requestHeader.ReturnDiagnostics = (uint)DiagnosticsMasks.All;

                // generate input data.
                channelContext.Random.Start(
                    (int)(testCase.Seed + iteration),
                    (int)m_sequenceToExecute.RandomDataStepSize,
                    testCaseContext);

                input = channelContext.Random.GetVariant();
                
                // determine processing time in server.
                int processingTime = channelContext.Random.GetInt32Range(0, testCaseContext.MaxResponseDelay);
                
                Utils.Trace("Iteration {0}; Processing Time {1}.", iteration, processingTime);

                AsyncTestState state = new AsyncTestState(channelContext, testCaseContext, testCase, iteration);
                state.CallData = (DateTime.UtcNow.AddMilliseconds(processingTime).Ticks/TimeSpan.TicksPerMillisecond);
                                
                // set timeout to twice the processing time.
                if (processingTime < testCaseContext.MaxTransportDelay)
                {
                    processingTime = testCaseContext.MaxTransportDelay;
                }

                channelContext.ClientSession.OperationTimeout = processingTime*2;
              
                if ((iteration+1)%testCaseContext.StackEventFrequency == 0)
                {
                    StackAction action = TestUtils.GetStackAction(testCaseContext, channelContext.EndpointDescription);

                    if (action != null)
                    {
                        BlackoutPeriod period = new BlackoutPeriod();
                        period.Start = (DateTime.UtcNow.Ticks/TimeSpan.TicksPerMillisecond);
                        m_blackouts.Add(period);

                        Utils.Trace("Iteration {0}; Expecting Fault {1}", iteration, action.ActionType);
                    }
                }

                try
                {
                    channelContext.ClientSession.BeginTestStack(
                        requestHeader,
                        testCase.TestId,
                        iteration,
                        input,
                        EndAutoReconnect,
                        state);
                                        
                    m_requestCount++;
                }
                catch (Exception e)
                {
                    // check if a fault is expected.
                    bool faultExpected = FaultExpected((long)state.CallData , testCaseContext);

                    if (faultExpected)
                    {
                        Utils.Trace("Iteration {0}; Fault Expected {1}", state.Iteration, e.Message);
                        state.ChannelContext.EventLogger.LogCompleteEvent(testCase, iteration);  
                        return; 
                    }
                
                    channelContext.EventLogger.LogErrorEvent(testCase, iteration, e);

                    if (m_sequenceToExecute.HaltOnError)
                    {
                        if (m_fault == null)
                        {
                            m_fault = ServiceResult.Create(e, StatusCodes.BadUnexpectedError, "Could not send request.");
                        }
                    }
                }   
            }
        }
Beispiel #2
0
        private void ExecuteTest_AutoReconnect(
            ChannelContext channelContext,
            TestCaseContext testCaseContext,
            TestCase testCase,
            int iteration)
        {
            Variant input;
            Variant output;

            // initialize test case.
            if (iteration == TestCases.TestSetupIteration)
            {
                m_fault     = null;
                m_blackouts = new List <BlackoutPeriod>();
                channelContext.ClientSession.OperationTimeout = 30000;

                RequestHeader requestHeader = new RequestHeader();

                requestHeader.Timestamp         = DateTime.UtcNow;
                requestHeader.ReturnDiagnostics = (uint)DiagnosticsMasks.All;

                ResponseHeader responseHeader = channelContext.ClientSession.TestStack(
                    null,
                    testCase.TestId,
                    TestCases.TestSetupIteration,
                    input,
                    out output);

                return;
            }

            if (iteration == TestCases.TestCleanupIteration)
            {
                do
                {
                    lock (m_lock)
                    {
                        if (m_requestCount == 0)
                        {
                            return;
                        }
                    }

                    Thread.Sleep(100);
                }while (true);
            }

            Thread.Sleep(testCaseContext.RequestInterval);

            // report fault after waiting for all active threads to exit.
            if (m_sequenceToExecute.HaltOnError)
            {
                ServiceResult fault = null;

                lock (m_lock)
                {
                    fault = m_fault;
                }

                if (fault != null)
                {
                    do
                    {
                        lock (m_lock)
                        {
                            if (m_requestCount == 0)
                            {
                                throw new ServiceResultException(fault);
                            }
                        }

                        Thread.Sleep(100);
                    }while (true);
                }
            }

            // begin iteration.
            channelContext.EventLogger.LogStartEvent(testCase, iteration);

            lock (m_lock)
            {
                // set up header.
                RequestHeader requestHeader = new RequestHeader();

                requestHeader.Timestamp         = DateTime.UtcNow;
                requestHeader.ReturnDiagnostics = (uint)DiagnosticsMasks.All;

                // generate input data.
                channelContext.Random.Start(
                    (int)(testCase.Seed + iteration),
                    (int)m_sequenceToExecute.RandomDataStepSize,
                    testCaseContext);

                input = channelContext.Random.GetVariant();

                // determine processing time in server.
                int processingTime = channelContext.Random.GetInt32Range(0, testCaseContext.MaxResponseDelay);

                Utils.Trace("Iteration {0}; Processing Time {1}.", iteration, processingTime);

                AsyncTestState state = new AsyncTestState(channelContext, testCaseContext, testCase, iteration);
                state.CallData = (DateTime.UtcNow.AddMilliseconds(processingTime).Ticks / TimeSpan.TicksPerMillisecond);

                // set timeout to twice the processing time.
                if (processingTime < testCaseContext.MaxTransportDelay)
                {
                    processingTime = testCaseContext.MaxTransportDelay;
                }

                channelContext.ClientSession.OperationTimeout = processingTime * 2;

                if ((iteration + 1) % testCaseContext.StackEventFrequency == 0)
                {
                    StackAction action = TestUtils.GetStackAction(testCaseContext, channelContext.EndpointDescription);

                    if (action != null)
                    {
                        BlackoutPeriod period = new BlackoutPeriod();
                        period.Start = (DateTime.UtcNow.Ticks / TimeSpan.TicksPerMillisecond);
                        m_blackouts.Add(period);

                        Utils.Trace("Iteration {0}; Expecting Fault {1}", iteration, action.ActionType);
                    }
                }

                try
                {
                    channelContext.ClientSession.BeginTestStack(
                        requestHeader,
                        testCase.TestId,
                        iteration,
                        input,
                        EndAutoReconnect,
                        state);

                    m_requestCount++;
                }
                catch (Exception e)
                {
                    // check if a fault is expected.
                    bool faultExpected = FaultExpected((long)state.CallData, testCaseContext);

                    if (faultExpected)
                    {
                        Utils.Trace("Iteration {0}; Fault Expected {1}", state.Iteration, e.Message);
                        state.ChannelContext.EventLogger.LogCompleteEvent(testCase, iteration);
                        return;
                    }

                    channelContext.EventLogger.LogErrorEvent(testCase, iteration, e);

                    if (m_sequenceToExecute.HaltOnError)
                    {
                        if (m_fault == null)
                        {
                            m_fault = ServiceResult.Create(e, StatusCodes.BadUnexpectedError, "Could not send request.");
                        }
                    }
                }
            }
        }