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)); }
/// <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(); } }