Esempio n. 1
0
        public void PollingRequestHandlerDoesNotPollAfterClose()
        {
            var httpClient = new CustomHttpClient();
            var requestHandler = new PollingRequestHandler(httpClient);
            var active = true;

            Action verifyActive = () =>
            {
                Assert.True(active);
            };

            requestHandler.ResolveUrl = () =>
            {
                Assert.True(active);

                return "";
            };

            requestHandler.PrepareRequest += request =>
            {
                verifyActive();
            };

            requestHandler.OnPolling += verifyActive;

            requestHandler.OnAfterPoll += exception =>
            {
                verifyActive();
                return TaskAsyncHelper.Empty;
            };

            requestHandler.OnError += exception =>
            {
                verifyActive();
            };

            requestHandler.OnMessage += message =>
            {
                verifyActive();
            };

            requestHandler.OnAbort += request =>
            {
                active = false;
            };

            requestHandler.Start();

            // Let the request handler run for three seconds
            Thread.Sleep(TimeSpan.FromSeconds(.1));

            requestHandler.Stop();

            // Let all requests finish to see if we get any unintended results
            Thread.Sleep(TimeSpan.FromSeconds(1));
        }
Esempio n. 2
0
        public void PollingRequestHandlerDoesNotPollAfterClose()
        {
            var httpClient     = new CustomHttpClient();
            var requestHandler = new PollingRequestHandler(httpClient);
            var active         = true;

            Action verifyActive = () =>
            {
                Assert.True(active);
            };

            requestHandler.ResolveUrl = () =>
            {
                Assert.True(active);

                return("");
            };

            requestHandler.PrepareRequest += request =>
            {
                verifyActive();
            };

            requestHandler.OnPolling += verifyActive;

            requestHandler.OnAfterPoll += exception =>
            {
                verifyActive();
                return(TaskAsyncHelper.Empty);
            };

            requestHandler.OnError += exception =>
            {
                verifyActive();
            };

            requestHandler.OnMessage += message =>
            {
                verifyActive();
            };

            requestHandler.OnAbort += request =>
            {
                active = false;
            };

            requestHandler.Start();

            // Let the request handler run for three seconds
            Thread.Sleep(TimeSpan.FromSeconds(.1));

            requestHandler.Stop();

            // Let all requests finish to see if we get any unintended results
            Thread.Sleep(TimeSpan.FromSeconds(1));
        }
Esempio n. 3
0
        public void PollingRequestHandlerDoesNotPollAfterCloseMidRequest()
        {
            var httpClient = new CustomHttpClient();
            var requestHandler = new PollingRequestHandler(httpClient);
            var active = true;
            var killRequest = false;
            Action verifyActive = () =>
            {
                Assert.True(active);
            };

            requestHandler.ResolveUrl = () =>
            {
                Assert.True(active);

                return "";
            };

            requestHandler.PrepareRequest += request =>
            {
                if (killRequest)
                {
                    // Execute the stop on a different thread so it does not share the lock
                    // This is to simulate a real world situation in which the user requests the connection to stop
                    ThreadPool.QueueUserWorkItem(state =>
                    {
                        requestHandler.Stop();
                    });
                }

                verifyActive();
            };

            requestHandler.OnPolling += verifyActive;

            requestHandler.OnMessage += message =>
            {
                verifyActive();
            };

            requestHandler.OnAfterPoll += exception =>
            {
                verifyActive();
                return TaskAsyncHelper.Empty;
            };

            requestHandler.OnError += exception =>
            {
                verifyActive();
            };

            requestHandler.OnAbort += request =>
            {
                active = false;
            };

            requestHandler.Start();

            // Let the request handler run for three seconds
            Thread.Sleep(TimeSpan.FromSeconds(.1));

            killRequest = true;

            // Let all requests finish to see if we get any unintended results
            Thread.Sleep(TimeSpan.FromSeconds(1));
        }
Esempio n. 4
0
        public void PollingRequestHandlerDoesNotPollAfterCloseMidRequest()
        {
            var    httpClient     = new CustomHttpClient();
            var    requestHandler = new PollingRequestHandler(httpClient);
            var    active         = true;
            var    killRequest    = false;
            Action verifyActive   = () =>
            {
                Assert.True(active);
            };

            requestHandler.ResolveUrl = () =>
            {
                Assert.True(active);

                return("");
            };

            requestHandler.PrepareRequest += request =>
            {
                if (killRequest)
                {
                    // Execute the stop on a different thread so it does not share the lock
                    // This is to simulate a real world situation in which the user requests the connection to stop
                    ThreadPool.QueueUserWorkItem(state =>
                    {
                        requestHandler.Stop();
                    });
                }

                verifyActive();
            };

            requestHandler.OnPolling += verifyActive;

            requestHandler.OnMessage += message =>
            {
                verifyActive();
            };

            requestHandler.OnAfterPoll += exception =>
            {
                verifyActive();
                return(TaskAsyncHelper.Empty);
            };

            requestHandler.OnError += exception =>
            {
                verifyActive();
            };

            requestHandler.OnAbort += request =>
            {
                active = false;
            };

            requestHandler.Start();

            // Let the request handler run for three seconds
            Thread.Sleep(TimeSpan.FromSeconds(.1));

            killRequest = true;

            // Let all requests finish to see if we get any unintended results
            Thread.Sleep(TimeSpan.FromSeconds(1));
        }