mirror of
https://github.com/ckaczor/sqltoolsservice.git
synced 2026-01-22 01:25:44 -05:00
This reverts commit 822a6459ce.
This commit is contained in:
@@ -65,12 +65,17 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.Profiler
|
||||
// start profiling session
|
||||
await profilerService.HandleStartProfilingRequest(requestParams, requestContext.Object);
|
||||
|
||||
profilerService.SessionMonitor.PollSession(1);
|
||||
// simulate a short polling delay
|
||||
Thread.Sleep(200);
|
||||
profilerService.SessionMonitor.PollSession(1);
|
||||
|
||||
// wait for polling to finish, or for timeout
|
||||
System.Timers.Timer pollingTimer = new System.Timers.Timer();
|
||||
pollingTimer.Interval = 10000;
|
||||
pollingTimer.Start();
|
||||
bool timeout = false;
|
||||
pollingTimer.Elapsed += new System.Timers.ElapsedEventHandler((s_, e_) => { timeout = true; });
|
||||
pollingTimer.Elapsed += new System.Timers.ElapsedEventHandler((s_, e_) => {timeout = true;});
|
||||
while (sessionId == null && !timeout)
|
||||
{
|
||||
Thread.Sleep(250);
|
||||
@@ -120,8 +125,6 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.Profiler
|
||||
ConnectionInfo connectionInfo = TestObjects.GetTestConnectionInfo();
|
||||
profilerService.ConnectionServiceInstance.OwnerToConnectionMap.Add(testUri, connectionInfo);
|
||||
profilerService.XEventSessionFactory = new TestXEventSessionFactory();
|
||||
mockSession.SetupProperty(p => p.ConnectionDetails, connectionInfo.ConnectionDetails);
|
||||
mockSession.SetupProperty(p => p.Session, new Session(null, testUri));
|
||||
|
||||
var requestParams = new StopProfilingParams();
|
||||
requestParams.OwnerUri = testUri;
|
||||
@@ -146,12 +149,12 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.Profiler
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[Test]
|
||||
// TODO: Add more in-depth testing for pause effects on events received.
|
||||
public async Task TestPauseProfilingRequest()
|
||||
{
|
||||
bool success = false;
|
||||
string testUri = "test_session";
|
||||
|
||||
bool recievedEvents = false;
|
||||
|
||||
// capture pausing results
|
||||
var requestContext = new Mock<RequestContext<PauseProfilingResult>>();
|
||||
requestContext.Setup(rc => rc.SendResult(It.IsAny<PauseProfilingResult>()))
|
||||
@@ -161,34 +164,75 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.Profiler
|
||||
return Task.FromResult(0);
|
||||
});
|
||||
|
||||
// capture Listener event notifications
|
||||
var mockListener = new Mock<IProfilerSessionListener>();
|
||||
mockListener.Setup(p => p.EventsAvailable(It.IsAny<string>(), It.IsAny<List<ProfilerEvent>>(), It.IsAny<bool>())).Callback(() =>
|
||||
{
|
||||
recievedEvents = true;
|
||||
});
|
||||
|
||||
// setup profiler service
|
||||
var mockListener = new TestSessionListener();
|
||||
var profilerService = new ProfilerService();
|
||||
profilerService.SessionMonitor.AddSessionListener(mockListener);
|
||||
profilerService.SessionMonitor.AddSessionListener(mockListener.Object);
|
||||
profilerService.ConnectionServiceInstance = TestObjects.GetTestConnectionService();
|
||||
ConnectionInfo connectionInfo = TestObjects.GetTestConnectionInfo();
|
||||
profilerService.ConnectionServiceInstance.OwnerToConnectionMap.Add(testUri, connectionInfo);
|
||||
|
||||
var testSession = new TestXEventSession1();
|
||||
testSession.ConnectionDetails = connectionInfo.ConnectionDetails;
|
||||
testSession.Session = new Session(null, testUri);
|
||||
|
||||
var requestParams = new PauseProfilingParams();
|
||||
requestParams.OwnerUri = testUri;
|
||||
|
||||
// begin monitoring session
|
||||
profilerService.SessionMonitor.StartMonitoringSession(testUri, testSession);
|
||||
profilerService.SessionMonitor.StartMonitoringSession(testUri, new TestXEventSession1());
|
||||
|
||||
// poll the session
|
||||
profilerService.SessionMonitor.PollSession(1);
|
||||
Thread.Sleep(500);
|
||||
profilerService.SessionMonitor.PollSession(1);
|
||||
|
||||
// wait for polling to finish, or for timeout
|
||||
System.Timers.Timer pollingTimer = new System.Timers.Timer();
|
||||
pollingTimer.Interval = 10000;
|
||||
pollingTimer.Start();
|
||||
bool timeout = false;
|
||||
pollingTimer.Elapsed += new System.Timers.ElapsedEventHandler((s_, e_) => {timeout = true;});
|
||||
while (!recievedEvents && !timeout)
|
||||
{
|
||||
Thread.Sleep(250);
|
||||
}
|
||||
pollingTimer.Stop();
|
||||
|
||||
// confirm that polling works
|
||||
Assert.True(recievedEvents);
|
||||
|
||||
// pause viewer
|
||||
await profilerService.HandlePauseProfilingRequest(requestParams, requestContext.Object);
|
||||
Assert.True(success);
|
||||
|
||||
recievedEvents = false;
|
||||
success = false;
|
||||
|
||||
profilerService.SessionMonitor.PollSession(1);
|
||||
|
||||
// confirm that no events were sent to paused Listener
|
||||
Assert.False(recievedEvents);
|
||||
|
||||
// unpause viewer
|
||||
await profilerService.HandlePauseProfilingRequest(requestParams, requestContext.Object);
|
||||
Assert.True(success);
|
||||
|
||||
profilerService.SessionMonitor.PollSession(1);
|
||||
|
||||
// wait for polling to finish, or for timeout
|
||||
timeout = false;
|
||||
pollingTimer.Start();
|
||||
while (!recievedEvents && !timeout)
|
||||
{
|
||||
Thread.Sleep(250);
|
||||
}
|
||||
|
||||
// check that events got sent to Listener
|
||||
Assert.True(recievedEvents);
|
||||
|
||||
requestContext.VerifyAll();
|
||||
}
|
||||
|
||||
@@ -219,14 +263,21 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.Profiler
|
||||
profilerService.ConnectionServiceInstance = TestObjects.GetTestConnectionService();
|
||||
ConnectionInfo connectionInfo = TestObjects.GetTestConnectionInfo();
|
||||
profilerService.ConnectionServiceInstance.OwnerToConnectionMap.Add(testUri, connectionInfo);
|
||||
mockSession.SetupProperty(p => p.ConnectionDetails, connectionInfo.ConnectionDetails);
|
||||
mockSession.SetupProperty(p => p.Session, new Session(null, testUri));
|
||||
|
||||
// start monitoring test session
|
||||
profilerService.SessionMonitor.StartMonitoringSession(testUri, mockSession.Object);
|
||||
|
||||
// Call stop session to simulate when a server has stopped a session on its side.
|
||||
profilerService.SessionMonitor.StopSession(0);
|
||||
// wait for polling to finish, or for timeout
|
||||
System.Timers.Timer pollingTimer = new System.Timers.Timer();
|
||||
pollingTimer.Interval = 10000;
|
||||
pollingTimer.Start();
|
||||
bool timeout = false;
|
||||
pollingTimer.Elapsed += new System.Timers.ElapsedEventHandler((s_, e_) => {timeout = true;});
|
||||
while (sessionStopped == false && !timeout)
|
||||
{
|
||||
Thread.Sleep(250);
|
||||
}
|
||||
pollingTimer.Stop();
|
||||
|
||||
// check that a stopped session notification was sent
|
||||
Assert.True(sessionStopped);
|
||||
|
||||
@@ -123,5 +123,41 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.Profiler
|
||||
profilerSession.FilterOldEvents(profilerEvents);
|
||||
Assert.False(profilerSession.EventsLost);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Test the TryEnterPolling method
|
||||
/// </summary>
|
||||
[Test]
|
||||
public void TestTryEnterPolling()
|
||||
{
|
||||
DateTime startTime = DateTime.Now;
|
||||
|
||||
// create new profiler session
|
||||
var profilerSession = new ProfilerSession();
|
||||
|
||||
// enter the polling block
|
||||
Assert.True(profilerSession.TryEnterPolling());
|
||||
Assert.True(profilerSession.IsPolling);
|
||||
|
||||
// verify we can't enter again
|
||||
Assert.False(profilerSession.TryEnterPolling());
|
||||
|
||||
// set polling to false to exit polling block
|
||||
profilerSession.IsPolling = false;
|
||||
|
||||
bool outsideDelay = DateTime.Now.Subtract(startTime) >= profilerSession.PollingDelay;
|
||||
|
||||
// verify we can only enter again if we're outside polling delay interval
|
||||
Assert.AreEqual(profilerSession.TryEnterPolling(), outsideDelay);
|
||||
|
||||
// reset IsPolling in case the delay has elasped on slow machine or while debugging
|
||||
profilerSession.IsPolling = false;
|
||||
|
||||
// wait for the polling delay to elapse
|
||||
Thread.Sleep(profilerSession.PollingDelay);
|
||||
|
||||
// verify we can enter the polling block again
|
||||
Assert.True(profilerSession.TryEnterPolling());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,7 +11,6 @@ using System.Threading.Tasks;
|
||||
using Microsoft.SqlServer.Management.XEvent;
|
||||
using Microsoft.SqlTools.Hosting.Protocol;
|
||||
using Microsoft.SqlTools.ServiceLayer.Connection;
|
||||
using Microsoft.SqlTools.ServiceLayer.Connection.Contracts;
|
||||
using Microsoft.SqlTools.ServiceLayer.Profiler;
|
||||
using Microsoft.SqlTools.ServiceLayer.Profiler.Contracts;
|
||||
using Microsoft.SqlTools.ServiceLayer.UnitTests.Utility;
|
||||
@@ -207,10 +206,6 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.Profiler
|
||||
|
||||
public int Id { get { return 51; } }
|
||||
|
||||
public ConnectionDetails ConnectionDetails { get; set; }
|
||||
|
||||
public Session Session { get; set; }
|
||||
|
||||
public void Start(){}
|
||||
|
||||
public void Stop(){}
|
||||
@@ -296,10 +291,6 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.Profiler
|
||||
|
||||
public int Id { get { return 1; } }
|
||||
|
||||
public ConnectionDetails ConnectionDetails { get; set; }
|
||||
|
||||
public Session Session { get; set; }
|
||||
|
||||
public void Start(){}
|
||||
|
||||
public void Stop(){}
|
||||
@@ -391,10 +382,6 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.Profiler
|
||||
|
||||
public int Id { get { return 2; } }
|
||||
|
||||
public ConnectionDetails ConnectionDetails { get; set; }
|
||||
|
||||
public Session Session { get; set; }
|
||||
|
||||
public void Start(){}
|
||||
|
||||
public void Stop(){}
|
||||
|
||||
Reference in New Issue
Block a user