Exemple #1
0
        /// <summary>
        /// Queues an action.
        /// </summary>
        private void QueueStackAction(SessionClient session, StackAction action)
        {
            System.ServiceModel.ClientBase <ISessionChannel> channel = session.InnerChannel as System.ServiceModel.ClientBase <ISessionChannel>;

            if (channel != null)
            {
                IStackControl control = channel.InnerChannel.GetProperty <IStackControl>();

                if (control != null)
                {
                    control.QueueAction(action);
                }
            }
        }
Exemple #2
0
        /// <summary>
        /// Queues an action.
        /// </summary>
        private void QueueStackAction(StackAction action)
        {
            System.ServiceModel.OperationContext context = System.ServiceModel.OperationContext.Current;

            if (context != null)
            {
                IStackControl control = context.Channel.GetProperty <IStackControl>();

                if (control != null)
                {
                    control.QueueAction(action);
                }
            }
        }
Exemple #3
0
        /// <summary>
        /// Sets the event sink for the current channel.
        /// </summary>
        private void InterruptListener(int duration)
        {
            System.ServiceModel.OperationContext context = System.ServiceModel.OperationContext.Current;

            if (context != null)
            {
                IStackControl control = context.EndpointDispatcher.ChannelDispatcher.Listener.GetProperty <IStackControl>();

                if (control != null)
                {
                    StackAction action = new StackAction();

                    action.ActionType = StackActionType.CloseListeningSocket;
                    action.Duration   = duration;

                    control.QueueAction(action);
                }
            }
        }
Exemple #4
0
        /// <summary>
        /// Returns the stack action to use for the current context.
        /// </summary>
        public static StackAction GetStackAction(TestCaseContext context, EndpointDescription endpointDescription)
        {
            if (!endpointDescription.EndpointUrl.StartsWith(Utils.UriSchemeOpcTcp))
            {
                return(null);
            }

            StackAction action = new StackAction();

            switch (context.StackEventType)
            {
            case 1: { action.ActionType = StackActionType.CorruptMessageChunk;   break; }

            case 2: { action.ActionType = StackActionType.ReuseSequenceNumber;   break; }

            case 3: { action.ActionType = StackActionType.CloseConnectionSocket; break; }

            case 4: { action.ActionType = StackActionType.CloseConnectionSocket; break; }

            default:
            {
                return(null);
            }
            }

            // cannot detect corrupt messages predictably if no security is used.
            if (endpointDescription.SecurityMode == MessageSecurityMode.None)
            {
                if (action.ActionType == StackActionType.CorruptMessageChunk)
                {
                    action.ActionType = StackActionType.ReuseSequenceNumber;
                }
            }

            return(action);
        }
Exemple #5
0
        /// <summary>
        /// Sets the event sink for the current channel.
        /// </summary>
        private void InterruptListener(int duration)
        {
            System.ServiceModel.OperationContext context = System.ServiceModel.OperationContext.Current;

            if (context != null)
            {
                IStackControl control = context.EndpointDispatcher.ChannelDispatcher.Listener.GetProperty<IStackControl>();

                if (control != null)
                {
                    StackAction action = new StackAction();
                    
                    action.ActionType = StackActionType.CloseListeningSocket;
                    action.Duration   = duration;

                    control.QueueAction(action);
                }
            }
        }
Exemple #6
0
        /// <summary>
        /// Queues an action.
        /// </summary>
        private void QueueStackAction(StackAction action)
        {
            System.ServiceModel.OperationContext context = System.ServiceModel.OperationContext.Current;

            if (context != null)
            {
                IStackControl control = context.Channel.GetProperty<IStackControl>();

                if (control != null)
                {
                    control.QueueAction(action);
                }
            }
        }
Exemple #7
0
        private Variant ExecuteTest_AutoReconnect(TestCaseContext testCaseContext, TestCase testCase, int iteration, Variant input)
        {
            if (TestUtils.IsSetupIteration(iteration))
            {
                SetEventSink();
                return(Variant.Null);
            }

            // get the expected input.
            Variant expectedInput;
            int     processingTime = 0;

            lock (m_random)
            {
                Utils.Trace("Iteration {0}; Server Received", iteration);

                // compare actual to expected input.
                m_random.Start(
                    (int)(testCase.Seed + iteration),
                    (int)m_sequenceToExecute.RandomDataStepSize,
                    testCaseContext);

                expectedInput = m_random.GetVariant();

                if (!Compare.CompareVariant(input, expectedInput))
                {
                    throw ServiceResultException.Create(
                              StatusCodes.BadUnexpectedError,
                              "Server did not receive expected input\r\nActual = {0}\r\nExpected = {0}",
                              input,
                              expectedInput);
                }

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

                if ((iteration + 1) % testCaseContext.StackEventFrequency == 0)
                {
                    if (testCaseContext.StackEventType == 4)
                    {
                        InterruptListener(testCaseContext.StackEventFrequency * testCaseContext.RequestInterval / 2);
                    }

                    StackAction action = TestUtils.GetStackAction(testCaseContext, SecureChannelContext.Current.EndpointDescription);

                    if (action != null)
                    {
                        QueueStackAction(action);
                    }
                }
            }

            // wait.
            Thread.Sleep(processingTime);

            // generate and return the output.
            lock (m_random)
            {
                m_random.Start((int)(
                                   testCase.ResponseSeed + iteration),
                               (int)m_sequenceToExecute.RandomDataStepSize,
                               testCaseContext);

                return(m_random.GetVariant());
            }
        }
Exemple #8
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.");
                        }
                    }
                }
            }
        }
Exemple #9
0
        /// <summary>
        /// Queues an action.
        /// </summary>
        private void QueueStackAction(SessionClient session, StackAction action)
        {
            System.ServiceModel.ClientBase<ISessionChannel> channel = session.InnerChannel as System.ServiceModel.ClientBase<ISessionChannel>;

            if (channel != null)
            {
                IStackControl control = channel.InnerChannel.GetProperty<IStackControl>();

                if (control != null)
                {
                    control.QueueAction(action);
                }
            }
        }
Exemple #10
0
        /// <summary>
        /// Returns the stack action to use for the current context.
        /// </summary>
        public static StackAction GetStackAction(TestCaseContext context, EndpointDescription endpointDescription)
        {
            if (!endpointDescription.EndpointUrl.StartsWith(Utils.UriSchemeOpcTcp))
            {
                return null;
            }

            StackAction action = new StackAction();

            switch (context.StackEventType)
            {
                case 1: { action.ActionType = StackActionType.CorruptMessageChunk;   break; }
                case 2: { action.ActionType = StackActionType.ReuseSequenceNumber;   break; }
                case 3: { action.ActionType = StackActionType.CloseConnectionSocket; break; }
                case 4: { action.ActionType = StackActionType.CloseConnectionSocket; break; }

                default:
                {
                    return null;
                }                     
            }

            // cannot detect corrupt messages predictably if no security is used.
            if (endpointDescription.SecurityMode == MessageSecurityMode.None)
            {
                if (action.ActionType == StackActionType.CorruptMessageChunk)
                {
                    action.ActionType = StackActionType.ReuseSequenceNumber;
                }
            }

            return action;
        }