mirror of
https://github.com/ckaczor/sqltoolsservice.git
synced 2026-01-18 01:25:41 -05:00
XEvent Profiler initial event handlers (#456)
* Bump SMO to 140.2.5 to pick-up private XEvent binaries * Pick up SMO binaries from the build lab * Add ProfilerService class placeholder * Update SMO nuget package to include DB Scoped XEvents * Stage changes * Stage changes * Update SMO to use RTM dependencies and remove separate SqlScript package * Stage changes * Iterate on profiler service * Fix post-merge break in localization * More refactoring * Continue iterating on profiler * Add test profiler listener * Address a couple of the code review feedback * Fix AppVeyor build break * Use self-cleaning test file
This commit is contained in:
@@ -0,0 +1,87 @@
|
||||
//
|
||||
// Copyright (c) Microsoft. All rights reserved.
|
||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||
//
|
||||
|
||||
using System;
|
||||
using System.Threading;
|
||||
using Microsoft.SqlTools.ServiceLayer.Profiler;
|
||||
using Microsoft.SqlTools.ServiceLayer.Profiler.Contracts;
|
||||
using Xunit;
|
||||
|
||||
namespace Microsoft.SqlTools.ServiceLayer.UnitTests.Profiler
|
||||
{
|
||||
/// <summary>
|
||||
/// Tests for ProfilerSession class
|
||||
/// </summary>
|
||||
public class ProfilerSessionTests
|
||||
{
|
||||
/// <summary>
|
||||
/// Test the FilterOldEvents method
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public void TestFilterOldEvents()
|
||||
{
|
||||
// create a profiler session and get some test events
|
||||
var profilerSession = new ProfilerSession();
|
||||
var profilerEvents = ProfilerTestObjects.TestProfilerEvents;
|
||||
|
||||
// filter old events shouldn't filter any new events
|
||||
var newProfilerEvents = profilerSession.FilterOldEvents(profilerEvents);
|
||||
Assert.Equal(profilerEvents.Count, newProfilerEvents.Count);
|
||||
|
||||
// filter should now filter all the events since they've been seen before
|
||||
newProfilerEvents = profilerSession.FilterOldEvents(profilerEvents);
|
||||
Assert.Equal(newProfilerEvents.Count, 0);
|
||||
|
||||
// add a new event
|
||||
var newEvent = new ProfilerEvent("new event", "1/1/2017");
|
||||
profilerEvents.Add(newEvent);
|
||||
|
||||
// verify we only have the new event when reprocessing the event list
|
||||
newProfilerEvents = profilerSession.FilterOldEvents(profilerEvents);
|
||||
Assert.Equal(newProfilerEvents.Count, 1);
|
||||
Assert.True(newProfilerEvents[0].Equals(newEvent));
|
||||
|
||||
// process whole list again and verify nothing new is available
|
||||
newProfilerEvents = profilerSession.FilterOldEvents(profilerEvents);
|
||||
Assert.Equal(newProfilerEvents.Count, 0);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Test the TryEnterPolling method
|
||||
/// </summary>
|
||||
[Fact]
|
||||
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.Equal(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());
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user