public void Configuration(IAppBuilder app)
        {
            app.Run(context =>
            {
                Stopwatch stopWatch = new Stopwatch();
                Trace.WriteLine("Received client call. Starting stop watch now.");
                stopWatch.Start();

                context.Request.CallCancelled.Register(() =>
                {
                    stopWatch.Stop();
                    Trace.WriteLine(string.Format("Cancellation token triggered. Elapsed time : {0}. Test should succeed", stopWatch.Elapsed));
                    NotificationServer.NotifyClient();
                });

                int retryCount = 0;
                while (retryCount < 3)
                {
                    Thread.CurrentThread.Join(5 * 1000);
                    if (context.Request.CallCancelled.IsCancellationRequested)
                    {
                        break;
                    }
                    retryCount++;
                }

                return(context.Response.WriteAsync("FAILURE"));
            });
        }
Example #2
0
        public bool WriteCore(TraceEventType eventType, int eventId, object state, Exception exception, Func <object, Exception, string> formatter)
        {
            if (expectedMessages.Contains(state.ToString()) &&
                state.ToString().Contains(eventType.ToString()))
            {
                expectedMessages.Remove(state.ToString());
            }

            if (expectedMessages.Count == 0)
            {
                NotificationServer.NotifyClient();
            }

            return(true);
        }
        internal void Configuration(IAppBuilder app)
        {
            appDisposingTokenOnHostProperties = app.Properties.Get <CancellationToken>("host.OnAppDisposing");
            appDisposingTokenOnHostProperties.Register(() =>
            {
                NotificationServer.NotifyClient();
            });

            app.Run(context =>
            {
                var perRequestHostDisposingToken = context.Get <CancellationToken>("host.OnAppDisposing");
                if (perRequestHostDisposingToken.GetHashCode() != this.appDisposingTokenOnHostProperties.GetHashCode())
                {
                    return(context.Response.WriteAsync("FAILURE"));
                }

                return(context.Response.WriteAsync("SUCCESS"));
            });
        }