public async Task TestStopProfilingRequest()
        {
            bool   success = false;
            bool   stopped = false;
            string testUri = "test_session";

            // capture stopping results
            var requestContext = new Mock <RequestContext <StopProfilingResult> >();

            requestContext.Setup(rc => rc.SendResult(It.IsAny <StopProfilingResult>()))
            .Returns <StopProfilingResult>((result) =>
            {
                success = true;
                return(Task.FromResult(0));
            });

            // capture if session was stopped
            var mockSession = new Mock <IXEventSession>();

            mockSession.Setup(p => p.Stop()).Callback(() =>
            {
                stopped = true;
            });

            var sessionListener = new TestSessionListener();
            var profilerService = new ProfilerService();

            profilerService.SessionMonitor.AddSessionListener(sessionListener);
            profilerService.ConnectionServiceInstance = TestObjects.GetTestConnectionService();
            ConnectionInfo connectionInfo = TestObjects.GetTestConnectionInfo();

            profilerService.ConnectionServiceInstance.OwnerToConnectionMap.Add(testUri, connectionInfo);
            profilerService.XEventSessionFactory = new TestXEventSessionFactory();

            var requestParams = new StopProfilingParams();

            requestParams.OwnerUri = testUri;

            profilerService.SessionMonitor.StartMonitoringSession(testUri, mockSession.Object);

            await profilerService.HandleStopProfilingRequest(requestParams, requestContext.Object);

            requestContext.VerifyAll();

            // check that session was succesfully stopped and stop was called
            Assert.True(success);
            Assert.True(stopped);

            // should not be able to remove the session, it should already be gone
            ProfilerSession ps;

            Assert.False(profilerService.SessionMonitor.StopMonitoringSession(testUri, out ps));
        }
Exemplo n.º 2
0
 /// <summary>
 /// Handle request to stop a profiling session
 /// </summary>
 internal async Task HandleStopProfilingRequest(StopProfilingParams parameters, RequestContext <StopProfilingResult> requestContext)
 {
     try
     {
         monitor.StopMonitoringSession(parameters.OwnerUri);
         await requestContext.SendResult(new StopProfilingResult
         {
             Succeeded = true
         });
     }
     catch (Exception e)
     {
         await requestContext.SendError(e);
     }
 }
Exemplo n.º 3
0
        /// <summary>
        /// Handle request to stop a profiling session
        /// </summary>
        internal async Task HandleStopProfilingRequest(StopProfilingParams parameters, RequestContext <StopProfilingResult> requestContext)
        {
            try
            {
                ProfilerSession session;
                monitor.StopMonitoringSession(parameters.OwnerUri, out session);
                session.XEventSession.Stop();

                await requestContext.SendResult(new StopProfilingResult {});
            }
            catch (Exception e)
            {
                await requestContext.SendError(e);
            }
        }
        /// <summary>
        /// Verify that a start profiling request starts a profiling session
        /// </summary>
        //[Fact]
        public async Task TestHandleStartAndStopProfilingRequests()
        {
            using (SelfCleaningTempFile queryTempFile = new SelfCleaningTempFile())
            {
                var connectionResult = await LiveConnectionHelper.InitLiveConnectionInfoAsync("master", queryTempFile.FilePath);

                ProfilerService profilerService = new ProfilerService();

                // start a new session
                var startParams = new StartProfilingParams();
                startParams.OwnerUri     = connectionResult.ConnectionInfo.OwnerUri;
                startParams.TemplateName = "Standard";

                string sessionId    = null;
                var    startContext = new Mock <RequestContext <StartProfilingResult> >();
                startContext.Setup(rc => rc.SendResult(It.IsAny <StartProfilingResult>()))
                .Returns <StartProfilingResult>((result) =>
                {
                    // capture the session id for sending the stop message
                    sessionId = result.SessionId;
                    return(Task.FromResult(0));
                });

                await profilerService.HandleStartProfilingRequest(startParams, startContext.Object);

                startContext.VerifyAll();

                // wait a bit for the session monitoring to initialize
                Thread.Sleep(TimeSpan.FromHours(1));

                // stop the session
                var stopParams = new StopProfilingParams()
                {
                    OwnerUri = sessionId
                };

                var stopContext = new Mock <RequestContext <StopProfilingResult> >();
                stopContext.Setup(rc => rc.SendResult(It.IsAny <StopProfilingResult>()))
                .Returns(Task.FromResult(0));

                await profilerService.HandleStopProfilingRequest(stopParams, stopContext.Object);

                stopContext.VerifyAll();
            }
        }
Exemplo n.º 5
0
        /// <summary>
        /// Handle request to stop a profiling session
        /// </summary>
        internal async Task HandleStopProfilingRequest(StopProfilingParams parameters, RequestContext <StopProfilingResult> requestContext)
        {
            await Task.Run(async() =>
            {
                try
                {
                    ProfilerSession session;
                    monitor.StopMonitoringSession(parameters.OwnerUri, out session);

                    if (session != null)
                    {
                        // Occasionally we might see the InvalidOperationException due to a read is
                        // in progress, add the following retry logic will solve the problem.
                        int remainingAttempts = 3;
                        while (true)
                        {
                            try
                            {
                                session.XEventSession.Stop();
                                await requestContext.SendResult(new StopProfilingResult {
                                });
                                break;
                            }
                            catch (InvalidOperationException)
                            {
                                remainingAttempts--;
                                if (remainingAttempts == 0)
                                {
                                    throw;
                                }
                                Thread.Sleep(500);
                            }
                        }
                    }
                    else
                    {
                        throw new Exception(SR.SessionNotFound);
                    }
                }
                catch (Exception e)
                {
                    await requestContext.SendError(new Exception(SR.StopSessionFailed(e.Message)));
                }
            });
        }
        /// <summary>
        /// Handle request to stop a profiling session
        /// </summary>
        internal async Task HandleStopProfilingRequest(StopProfilingParams parameters, RequestContext <StopProfilingResult> requestContext)
        {
            try
            {
                ProfilerSession session;
                monitor.StopMonitoringSession(parameters.OwnerUri, out session);

                if (session == null)
                {
                    throw new Exception(SR.SessionNotFound);
                }

                session.XEventSession.Stop();
                await requestContext.SendResult(new StopProfilingResult {});
            }
            catch (Exception e)
            {
                await requestContext.SendError(new Exception(SR.StopSessionFailed(e.Message)));
            }
        }