Skip to content

Commit

Permalink
Profiling tool for running test scripts. (#3243)
Browse files Browse the repository at this point in the history
* Profiling tool for running test scripts.

* Merge with master and fix bug in ask.
  • Loading branch information
chrimc62 committed Jan 10, 2020
1 parent 6e4e3b7 commit 7265bc4
Show file tree
Hide file tree
Showing 4 changed files with 127 additions and 2 deletions.
11 changes: 11 additions & 0 deletions Microsoft.Bot.Builder.sln
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.Bot.Builder.Adapt
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.Bot.Builder.TestProtocol", "tests\Microsoft.Bot.Builder.TestProtocol\Microsoft.Bot.Builder.TestProtocol.csproj", "{24CCB459-B4F6-484F-8BA4-946A4AB816FA}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Microsoft.Bot.Builder.Dialogs.Adaptive.Profiling", "tests\Microsoft.Bot.Builder.Dialogs.Adaptive.Profiling\Microsoft.Bot.Builder.Dialogs.Adaptive.Profiling.csproj", "{D9242899-AB3F-46BB-BAB4-386CB8EC535C}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -670,6 +672,14 @@ Global
{24CCB459-B4F6-484F-8BA4-946A4AB816FA}.Release|Any CPU.Build.0 = Release|Any CPU
{24CCB459-B4F6-484F-8BA4-946A4AB816FA}.Release-Windows|Any CPU.ActiveCfg = Release|Any CPU
{24CCB459-B4F6-484F-8BA4-946A4AB816FA}.Release-Windows|Any CPU.Build.0 = Release|Any CPU
{D9242899-AB3F-46BB-BAB4-386CB8EC535C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{D9242899-AB3F-46BB-BAB4-386CB8EC535C}.Debug|Any CPU.Build.0 = Debug|Any CPU
{D9242899-AB3F-46BB-BAB4-386CB8EC535C}.Debug-Windows|Any CPU.ActiveCfg = Debug|Any CPU
{D9242899-AB3F-46BB-BAB4-386CB8EC535C}.Debug-Windows|Any CPU.Build.0 = Debug|Any CPU
{D9242899-AB3F-46BB-BAB4-386CB8EC535C}.Release|Any CPU.ActiveCfg = Release|Any CPU
{D9242899-AB3F-46BB-BAB4-386CB8EC535C}.Release|Any CPU.Build.0 = Release|Any CPU
{D9242899-AB3F-46BB-BAB4-386CB8EC535C}.Release-Windows|Any CPU.ActiveCfg = Release|Any CPU
{D9242899-AB3F-46BB-BAB4-386CB8EC535C}.Release-Windows|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down Expand Up @@ -743,6 +753,7 @@ Global
{C8E31CD2-89D4-4659-9557-43EC9C99D984} = {6230B915-B238-4E57-AAC4-06B4498F540F}
{1D05EFE4-7F25-4D5A-BCEE-1109B9EF25A8} = {E8CD434A-306F-41D9-B67D-BFFF3287354D}
{24CCB459-B4F6-484F-8BA4-946A4AB816FA} = {AD743B78-D61F-4FBF-B620-FA83CE599A50}
{D9242899-AB3F-46BB-BAB4-386CB8EC535C} = {AD743B78-D61F-4FBF-B620-FA83CE599A50}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {7173C9F3-A7F9-496E-9078-9156E35D6E16}
Expand Down
4 changes: 2 additions & 2 deletions libraries/Microsoft.Bot.Builder.Dialogs.Adaptive/Input/Ask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ public override async Task<DialogTurnResult> BeginDialogAsync(DialogContext dc,

dc.GetState().TryGetValue(TurnPath.DIALOGEVENT, out DialogEvent trigger);

var expected = ExpectedProperties.GetValue(dc.GetState());
if (ExpectedProperties != null
var expected = ExpectedProperties?.GetValue(dc.GetState());
if (expected != null
&& dc.GetState().TryGetValue(DialogPath.ExpectedProperties, out List<string> lastExpectedProperties)
&& !expected.Any(prop => !lastExpectedProperties.Contains(prop))
&& !lastExpectedProperties.Any(prop => !expected.Contains(prop))
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.0</TargetFramework>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
<DebugType>portable</DebugType>
<DebugSymbols>true</DebugSymbols>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\..\libraries\Microsoft.Bot.Builder.Dialogs.Adaptive\Microsoft.Bot.Builder.Dialogs.Adaptive.csproj" />
</ItemGroup>

</Project>
97 changes: 97 additions & 0 deletions tests/Microsoft.Bot.Builder.Dialogs.Adaptive.Profiling/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
// Licensed under the MIT License.
// Copyright (c) Microsoft Corporation. All rights reserved.

using System;
using System.IO;
using System.Threading.Tasks;
using Microsoft.Bot.Builder.AI.QnA;
using Microsoft.Bot.Builder.Dialogs.Adaptive.Testing;
using Microsoft.Bot.Builder.Dialogs.Declarative;
using Microsoft.Bot.Builder.Dialogs.Declarative.Resources;
using Microsoft.Bot.Builder.Dialogs.Declarative.Types;
using Microsoft.Bot.Builder.MockLuis;
using Microsoft.Extensions.Configuration;

namespace Microsoft.Bot.Builder.Dialogs.Adaptive.Profiling
{
public class Program
{
public static void Help()
{
Console.Error.WriteLine("[-secret <id=profile>] [-luis <luisDir>] testscripts...");
Console.Error.WriteLine("-secret This is your secret id for luis keys.");
Console.Error.WriteLine("-luis This is the directory where luis settings arg.");
System.Environment.Exit(-1);
}

public static void Main(string[] args)
{
var secret = "profile";
string luis = null;
if (args.Length == 0)
{
Help();
}

for (var i = 0; i < args.Length; ++i)
{
var arg = args[i];
if (arg.StartsWith("-"))
{
if (arg == "-secret")
{
if (++i < args.Length)
{
secret = args[i];
}
else
{
throw new System.ArgumentException("Missing --secret value");
}
}
else if (arg == "-luis")
{
if (++i < args.Length)
{
luis = args[i];
}
else
{
throw new System.ArgumentException("Missing --luis value");
}
}
else
{
Console.Error.WriteLine($"Unknown arg {arg}");
Help();
}
}
else
{
var cd = Directory.GetCurrentDirectory();
var dir = Path.GetDirectoryName(arg);
var name = Path.GetFileName(arg);
var config = new ConfigurationBuilder()
.AddInMemoryCollection()
.UseLuisSettings(luis ?? dir, secret)
.Build();
var explorer = new ResourceExplorer().AddFolder(dir);
DeclarativeTypeLoader.Reset();
TypeFactory.Configuration = config;
DeclarativeTypeLoader.AddComponent(new DialogComponentRegistration());
DeclarativeTypeLoader.AddComponent(new AdaptiveComponentRegistration());
DeclarativeTypeLoader.AddComponent(new LanguageGenerationComponentRegistration());
DeclarativeTypeLoader.AddComponent(new QnAMakerComponentRegistration());
DeclarativeTypeLoader.AddComponent(new MockLuisComponentRegistration());
var script = explorer.LoadType<TestScript>(name);
var timer = new System.Diagnostics.Stopwatch();
Console.Write($"Executing {arg}");
timer.Start();
script.ExecuteAsync(testName: name, configuration: config, resourceExplorer: explorer).Wait();
timer.Stop();
Console.WriteLine($" took {timer.ElapsedMilliseconds} ms");
}
}
}
}
}

0 comments on commit 7265bc4

Please sign in to comment.