Пример #1
0
        public void SpecificRequestExceptionsAreRetriedTheCorrectNumberOfTimes()
        {
            Console.WriteLine("SpecificRequestExceptionsAreRetriedTheCorrectNumberOfTimes");

            using (var gate = new ManualResetEvent(false))
            {
                var requestFactory = new TestRequestFactory();

                const int EXPECTED_RETRY_COUNT = 2;
                
                var ctx = new CIAPI.Rpc.Client(new Uri(TestConfig.RpcUrl), new RequestCache(), requestFactory, _standardThrottleScopes, EXPECTED_RETRY_COUNT)
                {
                    UserName = TestConfig.ApiUsername,
                    SessionId = TestConfig.ApiTestSessionId
                };

                requestFactory.CreateTestRequest(NewsHeadlines14, TimeSpan.FromMilliseconds(300), null, null, new WebException("(500) internal server error"));

                Exception exception = null;
                
                ctx.BeginListNewsHeadlines("UK", 14, ar =>
                    {
                        try
                        {
                            ctx.EndListNewsHeadlines(ar);
                        }
                        catch (Exception ex)
                        {
                            exception = ex;
                        }
                        finally
                        {
                            gate.Set();
                        }

                    }, null);
                gate.WaitOne(TimeSpan.FromSeconds(3));
                Assert.IsNotNull(exception);
                Assert.AreEqual(string.Format("(500) internal server error\r\nretried {0} times", EXPECTED_RETRY_COUNT),exception.Message);
                
            }
        }