mirror of
https://github.com/ckaczor/sqltoolsservice.git
synced 2026-01-14 01:25:40 -05:00
Stopping sessions when handling stop requests (#627)
* Dropping profiler session on stop request * Changes to IXEventSession to simplify dropping sessions * Stop sessions instead of dropping, disable flaky tests
This commit is contained in:
committed by
GitHub
parent
b41c19bd25
commit
35b19320d4
@@ -22,7 +22,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.Profiler
|
||||
/// Unit tests for ProfilerService
|
||||
/// </summary>
|
||||
public class ProfilerServiceTests
|
||||
{
|
||||
{
|
||||
/// <summary>
|
||||
/// Test starting a profiling session and receiving event callback
|
||||
/// </summary>
|
||||
@@ -35,7 +35,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.Profiler
|
||||
string testUri = "profiler_uri";
|
||||
var requestContext = new Mock<RequestContext<StartProfilingResult>>();
|
||||
requestContext.Setup(rc => rc.SendResult(It.IsAny<StartProfilingResult>()))
|
||||
.Returns<StartProfilingResult>((result) =>
|
||||
.Returns<StartProfilingResult>((result) =>
|
||||
{
|
||||
// capture the session id for sending the stop message
|
||||
sessionId = result.SessionId;
|
||||
@@ -65,5 +65,62 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.Profiler
|
||||
Assert.Equal(sessionListener.PreviousSessionId, sessionId);
|
||||
Assert.Equal(sessionListener.PreviousEvents.Count, 1);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Test stopping a session and receiving event callback
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[Fact]
|
||||
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 = result.Succeeded;
|
||||
return Task.FromResult(0);
|
||||
});
|
||||
|
||||
// capture if session was dropped
|
||||
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;
|
||||
|
||||
ProfilerSession session = new ProfilerSession();
|
||||
session.XEventSession = mockSession.Object;
|
||||
session.SessionId = testUri;
|
||||
|
||||
profilerService.SessionMonitor.StartMonitoringSession(session);
|
||||
|
||||
await profilerService.HandleStopProfilingRequest(requestParams, requestContext.Object);
|
||||
|
||||
requestContext.VerifyAll();
|
||||
|
||||
// check that session was succesfully stopped and drop 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));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user