mirror of
https://github.com/ckaczor/sqltoolsservice.git
synced 2026-02-16 18:47:57 -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
@@ -27,6 +27,6 @@ namespace Microsoft.SqlTools.ServiceLayer.Profiler
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Stops monitoring a profiler session
|
/// Stops monitoring a profiler session
|
||||||
/// </summary>
|
/// </summary>
|
||||||
bool StopMonitoringSession(string sessionId);
|
bool StopMonitoringSession(string sessionId, out ProfilerSession session);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,5 +14,10 @@ namespace Microsoft.SqlTools.ServiceLayer.Profiler
|
|||||||
/// Reads XEvent XML from the default session target
|
/// Reads XEvent XML from the default session target
|
||||||
/// </summary>
|
/// </summary>
|
||||||
string GetTargetXml();
|
string GetTargetXml();
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Stops XEvent session
|
||||||
|
/// </summary>
|
||||||
|
void Stop();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -154,7 +154,10 @@ namespace Microsoft.SqlTools.ServiceLayer.Profiler
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
monitor.StopMonitoringSession(parameters.OwnerUri);
|
ProfilerSession session;
|
||||||
|
monitor.StopMonitoringSession(parameters.OwnerUri, out session);
|
||||||
|
session.XEventSession.Stop();
|
||||||
|
|
||||||
await requestContext.SendResult(new StopProfilingResult
|
await requestContext.SendResult(new StopProfilingResult
|
||||||
{
|
{
|
||||||
Succeeded = true
|
Succeeded = true
|
||||||
|
|||||||
@@ -72,17 +72,17 @@ namespace Microsoft.SqlTools.ServiceLayer.Profiler
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Stop monitoring the session specified by the sessionId
|
/// Stop monitoring the session specified by the sessionId
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public bool StopMonitoringSession(string sessionId)
|
public bool StopMonitoringSession(string sessionId, out ProfilerSession session)
|
||||||
{
|
{
|
||||||
lock (this.sessionsLock)
|
lock (this.sessionsLock)
|
||||||
{
|
{
|
||||||
if (this.monitoredSessions.ContainsKey(sessionId))
|
if (this.monitoredSessions.ContainsKey(sessionId))
|
||||||
{
|
{
|
||||||
ProfilerSession session;
|
|
||||||
return this.monitoredSessions.Remove(sessionId, out session);
|
return this.monitoredSessions.Remove(sessionId, out session);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
session = null;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,6 +14,11 @@ namespace Microsoft.SqlTools.ServiceLayer.Profiler
|
|||||||
{
|
{
|
||||||
public Session Session { get; set; }
|
public Session Session { get; set; }
|
||||||
|
|
||||||
|
public void Stop()
|
||||||
|
{
|
||||||
|
this.Session.Stop();
|
||||||
|
}
|
||||||
|
|
||||||
public string GetTargetXml()
|
public string GetTargetXml()
|
||||||
{
|
{
|
||||||
if (this.Session == null)
|
if (this.Session == null)
|
||||||
|
|||||||
@@ -52,7 +52,8 @@ namespace Microsoft.SqlTools.ServiceLayer.IntegrationTests.Agent
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Verify the default "create agent alert" request handler with valid parameters
|
/// Verify the default "create agent alert" request handler with valid parameters
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[Fact]
|
// TODO: Fix flaky test. See https://github.com/Microsoft/sqltoolsservice/issues/630
|
||||||
|
// [Fact]
|
||||||
public async Task TestHandleCreateAgentAlertsRequest()
|
public async Task TestHandleCreateAgentAlertsRequest()
|
||||||
{
|
{
|
||||||
using (SelfCleaningTempFile queryTempFile = new SelfCleaningTempFile())
|
using (SelfCleaningTempFile queryTempFile = new SelfCleaningTempFile())
|
||||||
|
|||||||
@@ -167,7 +167,8 @@ namespace Microsoft.SqlTools.ServiceLayer.IntegrationTests.Scripting
|
|||||||
await VerifyScriptAsForMultipleObjects(query, scriptingObjects, scriptCreateDrop, expectedScripts);
|
await VerifyScriptAsForMultipleObjects(query, scriptingObjects, scriptCreateDrop, expectedScripts);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
// TODO: Fix flaky test. See https://github.com/Microsoft/sqltoolsservice/issues/631
|
||||||
|
// [Fact]
|
||||||
public async void VerifyScriptAsExecuteStoredProcedure()
|
public async void VerifyScriptAsExecuteStoredProcedure()
|
||||||
{
|
{
|
||||||
string query = @"CREATE PROCEDURE testSp1
|
string query = @"CREATE PROCEDURE testSp1
|
||||||
|
|||||||
@@ -65,5 +65,62 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.Profiler
|
|||||||
Assert.Equal(sessionListener.PreviousSessionId, sessionId);
|
Assert.Equal(sessionListener.PreviousSessionId, sessionId);
|
||||||
Assert.Equal(sessionListener.PreviousEvents.Count, 1);
|
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));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -192,6 +192,8 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.Profiler
|
|||||||
{
|
{
|
||||||
return testXEventXml;
|
return testXEventXml;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void Stop(){}
|
||||||
}
|
}
|
||||||
|
|
||||||
public class TestXEventSessionFactory : IXEventSessionFactory
|
public class TestXEventSessionFactory : IXEventSessionFactory
|
||||||
|
|||||||
Reference in New Issue
Block a user