Files
sqltoolsservice/test/Microsoft.SqlTools.ServiceLayer.UnitTests/Profiler/ProfilerSessionTests.cs
Alex Ma 822a6459ce Update to XElite (#1287)
* added Xevent.xelite to packages

* WIP on XELite conversion

* added wip changes

* added streaminfo class for preserving streams

* added list for profilerService

* added cancelXelStreamRequest.cs

* added test configuration for profilerservice

* added request handler using startprofilingrequest

* fix start profiling result

* added small connection string

* WIP branch for XElite (not functional)

* added hardcoded string with working stream

* added check for buildconnectionstring

* added back HandleXEvent

* added profilerservice eventsavailable test

* WIP change for profilersessionmonitor

* added more changes to profilersessionmonitor

* changed HandleXEvent

* added more additions to profielrSessionMonitor

* added startmonitoringstream

* added startmonitoringsession

* added startmonitoringstream to IProfilerSessionMonitor

* switch to monitoringStream

* added assignment of connectioninfo

* added conninfo

* added conninfo to iProfilerSessionMonitor.cs

* added isStreaming flag

* added token list

* added XEventSession name.

* removed polling lock

* test adding filters

* removed old profile filter as its incompatible

* added wip cancel feature in removesession

* moved cancellationtoken outside

* added backIsStreaming

* moved isstreaming around

* added  multiple events in list

* added timeout to handleXEvent

* removed timeout

* remove eventList count check

* remove old events filter

* returned eventlist

* remove old events filter

* renamed xelite handle function

* restored sqlclient version

* removed original handlestartprofilingrequest

* added monitoring stream to handlecreatexeventsessionrequest

* removed unnecessary sections from monitor

* Revert "removed unnecessary sections from monitor"

This reverts commit 91cadeebeeedfe99cec2e9c42944ba6716d95a61.

* added xevent actions to profileEvent

* removed polling lock for processStreams

* added filter for oldevents

* removed unused methods

* removed comment

* removed unnecessary class

* removed unnecessary requests

* removed outdated methods

* added work in progress cancellation task

* added profilersessionmonitor changes

* added small changes

* renamed startMonitoringStream

* more changes related to feedback

* made changes to code

* removed more polling code

* fixed tests

* added connectioninfo to testxeventsessions

* changed functions

* added back else

* small formatting fix

* more changes made

* added changes to XEventSession

* update to strings

* added changes to accomodate tests

* more changes

* added profilerservicetest for stopprofiling

* added TestStoppedSessionNotification test

* added session missing details handler

* simplified error message

* restored strings and added changes

* added auto-getter setter for IsStreaming

* added more changes

* removed unnecessary lines from test

* added more debugging messages

* made last changes

* added error message for handlestopprofilingrequest

* added more debug messages

* added back an s

* added verbose
2021-12-07 14:11:42 -08:00

128 lines
4.9 KiB
C#

//
// 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 NUnit.Framework;
namespace Microsoft.SqlTools.ServiceLayer.UnitTests.Profiler
{
/// <summary>
/// Tests for ProfilerSession class
/// </summary>
public class ProfilerSessionTests
{
/// <summary>
/// Test the FilterOldEvents method
/// </summary>
[Test]
public void TestFilterOldEvents()
{
// create a profiler session and get some test events
var profilerSession = new ProfilerSession();
var allEvents = ProfilerTestObjects.TestProfilerEvents;
var profilerEvents = ProfilerTestObjects.TestProfilerEvents;
// filter all the results from the first poll
// these events happened before the profiler began
profilerSession.FilterOldEvents(profilerEvents);
Assert.AreEqual(0, profilerEvents.Count);
// add a new event
var newEvent = new ProfilerEvent("new event", "1/1/2017");
newEvent.Values.Add("event_sequence", "4");
allEvents.Add(newEvent);
// poll all events
profilerEvents.AddRange(allEvents);
// filtering should leave only the new event
profilerSession.FilterOldEvents(profilerEvents);
Assert.AreEqual(1, profilerEvents.Count);
Assert.True(profilerEvents[0].Equals(newEvent));
//poll again with no new events
profilerEvents.AddRange(allEvents);
// filter should now filter all the events since they've been seen before
profilerSession.FilterOldEvents(profilerEvents);
Assert.AreEqual(0, profilerEvents.Count);
}
/// <summary>
/// Test the FilterProfilerEvents method
/// </summary>
[Test]
public void TestFilterProfilerEvents()
{
// create a profiler session and get some test events
var profilerSession = new ProfilerSession();
var profilerEvents = ProfilerTestObjects.TestProfilerEvents;
int expectedEventCount = profilerEvents.Count;
// add a new "Profiler Polling" event
var newEvent = new ProfilerEvent("sql_batch_completed", "1/1/2017");
newEvent.Values.Add("batch_text", "SELECT target_data FROM sys.dm_xe_session_targets");
newEvent.Values.Add("event_sequence", "4");
profilerEvents.Add(newEvent);
// verify that the polling event is removed
Assert.AreEqual(profilerEvents.Count, expectedEventCount + 1);
var newProfilerEvents = profilerSession.FilterProfilerEvents(profilerEvents);
Assert.AreEqual(newProfilerEvents.Count, expectedEventCount);
}
/// <summary>
/// Test notifications for lost events
/// </summary>
[Test]
public void TestEventsLost()
{
// create a profiler session and get some test events
var profilerSession = new ProfilerSession();
var profilerEvents = ProfilerTestObjects.TestProfilerEvents;
// filter all the results from the first poll
// these events happened before the profiler began
profilerSession.FilterOldEvents(profilerEvents);
Assert.AreEqual(0, profilerEvents.Count);
// No events should be lost
Assert.False(profilerSession.EventsLost);
// test all events are overwritten, but no events are lost
profilerEvents.Clear();
ProfilerEvent newEvent = new ProfilerEvent("event4", "6/18/2018");
newEvent.Values.Add("event_sequence", "4");
profilerEvents.Add(newEvent);
profilerSession.FilterOldEvents(profilerEvents);
// should not show event loss
Assert.False(profilerSession.EventsLost);
// test all events are overwritten, and events are lost
profilerEvents.Clear();
newEvent = new ProfilerEvent("event7", "6/18/2018");
newEvent.Values.Add("event_sequence", "7");
profilerEvents.Add(newEvent);
profilerSession.FilterOldEvents(profilerEvents);
// should show event loss
Assert.True(profilerSession.EventsLost);
//poll again with previously seen events
profilerEvents.Add(newEvent);
// old events were seen, no event loss occured
profilerSession.FilterOldEvents(profilerEvents);
Assert.False(profilerSession.EventsLost);
}
}
}