mirror of
https://github.com/ckaczor/sqltoolsservice.git
synced 2026-02-14 03:58:35 -05:00
added perf tests using test driver (#136)
* added perf tests using test driver
This commit is contained in:
@@ -4,6 +4,7 @@
|
||||
//
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Runtime.InteropServices;
|
||||
@@ -17,9 +18,41 @@ namespace Microsoft.SqlTools.ServiceLayer.TestDriver.Utility
|
||||
/// </summary>
|
||||
public class ConnectionTestUtils
|
||||
{
|
||||
public static IEnumerable<TestServerIdentity> TestServers = InitTestServerNames();
|
||||
public static Setting Setting = InitSetting();
|
||||
|
||||
private static readonly Lazy<ConnectParams> azureTestServerConnection =
|
||||
new Lazy<ConnectParams>(() => GetConnectionFromVsCodeSettings("***REMOVED***"));
|
||||
|
||||
private static IEnumerable<TestServerIdentity> InitTestServerNames()
|
||||
{
|
||||
try
|
||||
{
|
||||
string testServerNamesFilePath = Environment.GetEnvironmentVariable("TestServerNamesFile");
|
||||
string jsonFileContent = File.ReadAllText(testServerNamesFilePath);
|
||||
return Newtonsoft.Json.JsonConvert.DeserializeObject<IList<TestServerIdentity>>(jsonFileContent);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private static Setting InitSetting()
|
||||
{
|
||||
try
|
||||
{
|
||||
string settingsFileContents = GetSettingFileContent();
|
||||
Setting setting = Newtonsoft.Json.JsonConvert.DeserializeObject<Setting>(settingsFileContents);
|
||||
|
||||
return setting;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static ConnectParams AzureTestServerConnection
|
||||
{
|
||||
get { return azureTestServerConnection.Value; }
|
||||
@@ -70,6 +103,26 @@ namespace Microsoft.SqlTools.ServiceLayer.TestDriver.Utility
|
||||
private static readonly Lazy<ConnectParams> dataToolsTelemetryAzureConnection =
|
||||
new Lazy<ConnectParams>(() => GetConnectionFromVsCodeSettings("***REMOVED***"));
|
||||
|
||||
private static string GetSettingFileContent()
|
||||
{
|
||||
string settingsFilename;
|
||||
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
|
||||
{
|
||||
settingsFilename = Environment.GetEnvironmentVariable("APPDATA") + @"\Code\User\settings.json";
|
||||
}
|
||||
else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
|
||||
{
|
||||
settingsFilename = Environment.GetEnvironmentVariable("HOME") + @"/Library/Application Support/Code/User/settings.json";
|
||||
}
|
||||
else
|
||||
{
|
||||
settingsFilename = Environment.GetEnvironmentVariable("HOME") + @"/.config/Code/User/settings.json";
|
||||
}
|
||||
string settingsFileContents = File.ReadAllText(settingsFilename);
|
||||
|
||||
return settingsFileContents;
|
||||
}
|
||||
|
||||
public static ConnectParams DataToolsTelemetryAzureConnection
|
||||
{
|
||||
get { return dataToolsTelemetryAzureConnection.Value; }
|
||||
@@ -97,20 +150,7 @@ namespace Microsoft.SqlTools.ServiceLayer.TestDriver.Utility
|
||||
{
|
||||
try
|
||||
{
|
||||
string settingsFilename;
|
||||
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
|
||||
{
|
||||
settingsFilename = Environment.GetEnvironmentVariable("APPDATA") + @"\Code\User\settings.json";
|
||||
}
|
||||
else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
|
||||
{
|
||||
settingsFilename = Environment.GetEnvironmentVariable("HOME") + @"/Library/Application Support/Code/User/settings.json";
|
||||
}
|
||||
else
|
||||
{
|
||||
settingsFilename = Environment.GetEnvironmentVariable("HOME") + @"/.config/Code/User/settings.json";
|
||||
}
|
||||
string settingsFileContents = File.ReadAllText(settingsFilename);
|
||||
string settingsFileContents = GetSettingFileContent();
|
||||
|
||||
JObject root = JObject.Parse(settingsFileContents);
|
||||
JArray connections = (JArray)root["mssql.connections"];
|
||||
|
||||
@@ -0,0 +1,80 @@
|
||||
//
|
||||
// Copyright (c) Microsoft. All rights reserved.
|
||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||
//
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Globalization;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace Microsoft.SqlTools.ServiceLayer.TestDriver.Utility
|
||||
{
|
||||
/// <summary>
|
||||
/// The model for deserializing settings.json
|
||||
/// </summary>
|
||||
public class Setting
|
||||
{
|
||||
[JsonProperty("mssql.connections")]
|
||||
public List<ConnectionProfile> Connections { get; set; }
|
||||
|
||||
public ConnectionProfile GetConnentProfile(string profilerName, string serverName)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(profilerName))
|
||||
{
|
||||
var byPrfileName = Connections.FirstOrDefault(x => x.ProfileName == profilerName);
|
||||
if (byPrfileName != null)
|
||||
{
|
||||
return byPrfileName;
|
||||
}
|
||||
}
|
||||
return Connections.FirstOrDefault(x => x.ServerName == serverName);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The model to deserializing the connections inside settings.json
|
||||
/// </summary>
|
||||
public class ConnectionProfile
|
||||
{
|
||||
public const string CRED_PREFIX = "Microsoft.SqlTools";
|
||||
public const string CRED_SEPARATOR = "|";
|
||||
public const string CRED_SERVER_PREFIX = "server:";
|
||||
public const string CRED_DB_PREFIX = "db:";
|
||||
public const string CRED_USER_PREFIX = "user:";
|
||||
public const string CRED_ITEMTYPE_PREFIX = "itemtype:";
|
||||
|
||||
[JsonProperty("server")]
|
||||
public string ServerName { get; set; }
|
||||
public string Database { get; set; }
|
||||
|
||||
public string User { get; set; }
|
||||
|
||||
public string Password { get; set; }
|
||||
|
||||
public string ProfileName { get; set; }
|
||||
|
||||
|
||||
public string formatCredentialId(string itemType = "Profile")
|
||||
{
|
||||
if (!string.IsNullOrEmpty(ServerName))
|
||||
{
|
||||
List<string> cred = new List<string>();
|
||||
cred.Add(CRED_PREFIX);
|
||||
AddToList(itemType, CRED_ITEMTYPE_PREFIX, cred);
|
||||
AddToList(ServerName, CRED_SERVER_PREFIX, cred);
|
||||
AddToList(Database, CRED_DB_PREFIX, cred);
|
||||
AddToList(User, CRED_USER_PREFIX, cred);
|
||||
return string.Join(CRED_SEPARATOR, cred.ToArray());
|
||||
}
|
||||
return null;
|
||||
}
|
||||
private void AddToList(string item, string prefix, List<string> list)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(item))
|
||||
{
|
||||
list.Add(string.Format(CultureInfo.InvariantCulture, "{0}{1}", prefix, item));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
//
|
||||
// Copyright (c) Microsoft. All rights reserved.
|
||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||
//
|
||||
|
||||
namespace Microsoft.SqlTools.ServiceLayer.TestDriver.Utility
|
||||
{
|
||||
/// <summary>
|
||||
/// The model to deserialize the server names json
|
||||
/// </summary>
|
||||
public class TestServerIdentity
|
||||
{
|
||||
public string ServerName { get; set; }
|
||||
public string ProfileName { get; set; }
|
||||
|
||||
public TestServerType ServerType { get; set; }
|
||||
}
|
||||
|
||||
public enum TestServerType
|
||||
{
|
||||
None,
|
||||
Azure,
|
||||
OnPrem
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
//
|
||||
// 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.Globalization;
|
||||
|
||||
namespace Microsoft.SqlTools.ServiceLayer.TestDriver.Utility
|
||||
{
|
||||
/// <summary>
|
||||
/// Timer to calculate the test run time
|
||||
/// </summary>
|
||||
public class TestTimer
|
||||
{
|
||||
public TestTimer()
|
||||
{
|
||||
Start();
|
||||
}
|
||||
|
||||
public void Start()
|
||||
{
|
||||
StartDateTime = DateTime.UtcNow;
|
||||
}
|
||||
|
||||
public void End()
|
||||
{
|
||||
EndDateTime = DateTime.UtcNow;
|
||||
}
|
||||
|
||||
public void EndAndPrint(string testName)
|
||||
{
|
||||
End();
|
||||
var currentColor = Console.ForegroundColor;
|
||||
Console.ForegroundColor = ConsoleColor.Green;
|
||||
Console.WriteLine(string.Format(CultureInfo.InvariantCulture, "Test Name: {0} Run time in milliSeconds: {1}", testName, TotalMilliSeconds));
|
||||
Console.ForegroundColor = currentColor;
|
||||
}
|
||||
|
||||
public double TotalMilliSeconds
|
||||
{
|
||||
get
|
||||
{
|
||||
return (EndDateTime - StartDateTime).TotalMilliseconds;
|
||||
}
|
||||
}
|
||||
|
||||
public double TotalMilliSecondsUntilNow
|
||||
{
|
||||
get
|
||||
{
|
||||
return (DateTime.UtcNow - StartDateTime).TotalMilliseconds;
|
||||
}
|
||||
}
|
||||
|
||||
public DateTime StartDateTime { get; private set; }
|
||||
public DateTime EndDateTime { get; private set; }
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user