-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1a15a1e
commit fe0fe29
Showing
9 changed files
with
246 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
test/HotPotato.Benchmark.Test/HotPotato.Benchmark.Test.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net5.0</TargetFramework> | ||
|
||
<IsPackable>false</IsPackable> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.9.4" /> | ||
<PackageReference Include="Moq" Version="4.16.1" /> | ||
<PackageReference Include="NBench" Version="2.0.1" /> | ||
<PackageReference Include="NSwag.Core" Version="13.13.2" /> | ||
<PackageReference Include="NSwag.Core.Yaml" Version="13.13.2" /> | ||
<PackageReference Include="Pro.NBench.xUnit" Version="2.0.0" /> | ||
<PackageReference Include="xunit" Version="2.4.1" /> | ||
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3"> | ||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> | ||
<PrivateAssets>all</PrivateAssets> | ||
</PackageReference> | ||
<PackageReference Include="coverlet.collector" Version="3.0.2"> | ||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> | ||
<PrivateAssets>all</PrivateAssets> | ||
</PackageReference> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\HotPotato.OpenApi.Test\HotPotato.OpenApi.Test.csproj" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<None Update="PerfSpec.yaml"> | ||
<CopyToOutputDirectory>Always</CopyToOutputDirectory> | ||
</None> | ||
</ItemGroup> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
using HotPotato.OpenApi.Matchers; | ||
using NBench; | ||
using Pro.NBench.xUnit.XunitExtensions; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Diagnostics; | ||
using Xunit; | ||
using Xunit.Abstractions; | ||
|
||
namespace HotPotato.Benchmark.Test | ||
{ | ||
//xUnit thinks that the PerfSetup should be a theory, so the warning needs to be disabled | ||
#pragma warning disable xUnit1013 | ||
public class MatcherBenchmarkTest | ||
{ | ||
private Counter _counter; | ||
|
||
//consider scalable lengths for path strings | ||
private const string AValidPath = "/foo/bar"; | ||
private readonly List<string> ValidPaths = new List<string> | ||
{ | ||
"/a/b/c", | ||
"/a/b", | ||
"/foo/bar", | ||
"/d/c" | ||
}; | ||
|
||
public MatcherBenchmarkTest(ITestOutputHelper output) | ||
{ | ||
Trace.Listeners.Clear(); | ||
Trace.Listeners.Add(new XunitTraceListener(output)); | ||
} | ||
|
||
[PerfSetup] | ||
public void Setup(BenchmarkContext context) | ||
{ | ||
_counter = context.GetCounter("Iterations"); | ||
} | ||
|
||
/// <summary> | ||
/// Ensure that we can match paths at least 500,000 times per second (5ms). | ||
/// </summary> | ||
[NBenchFact] | ||
[PerfBenchmark( | ||
Description = "Ensure matching doesn't take too long", | ||
NumberOfIterations = 3, | ||
RunTimeMilliseconds = 1000, | ||
RunMode = RunMode.Throughput, | ||
TestMode = TestMode.Test)] | ||
[CounterThroughputAssertion("Iterations", MustBe.GreaterThan, 500000)] | ||
public void PathMatcher_Match_Benchmark() | ||
{ | ||
PathMatcher.Match(AValidPath, ValidPaths); | ||
_counter.Increment(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
openapi: '3.0.1' | ||
info: | ||
version: 1.0.0 | ||
title: Truncated Raw Potato Spec for Performance Testing | ||
paths: | ||
/order: | ||
post: | ||
summary: Add a new order | ||
requestBody: | ||
description: Creating a new order with all properties | ||
required: true | ||
content: | ||
application/json: | ||
schema: | ||
$ref: '#/components/schemas/Order' | ||
responses: | ||
'201': | ||
description: Order created successfully | ||
content: | ||
application/json: | ||
schema: | ||
$ref: '#/components/schemas/Order' | ||
|
||
components: | ||
schemas: | ||
Order: | ||
required: | ||
- id | ||
- price | ||
- items | ||
properties: | ||
id: | ||
type: integer | ||
price: | ||
type: number | ||
nullable: true | ||
items: | ||
type: | ||
schema: | ||
$ref: '#/components/schemas/ItemsList' | ||
Item: | ||
required: | ||
- itemId | ||
- name | ||
- price | ||
properties: | ||
itemId: | ||
type: integer | ||
name: | ||
type: string | ||
price: | ||
type: number | ||
nullable: true | ||
ItemsList: | ||
type: array | ||
items: | ||
type: | ||
schema: | ||
$ref: '#/components/schemas/Item' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
using HotPotato.Core.Http; | ||
using HotPotato.OpenApi.Results; | ||
using HotPotato.OpenApi.Validators; | ||
using HotPotato.OpenApi.SpecificationProvider; | ||
using Moq; | ||
using NBench; | ||
using Newtonsoft.Json; | ||
using NSwag; | ||
using Pro.NBench.xUnit.XunitExtensions; | ||
using System; | ||
using System.IO; | ||
using System.Collections.Generic; | ||
using System.Net; | ||
using System.Net.Http; | ||
using System.Diagnostics; | ||
using System.Threading.Tasks; | ||
using Xunit; | ||
using Xunit.Abstractions; | ||
|
||
namespace HotPotato.Benchmark.Test | ||
{ | ||
//xUnit thinks that the PerfSetup should be a theory, so the warning needs to be disabled | ||
#pragma warning disable xUnit1013 | ||
public class ValidatorBenchmarkTest | ||
{ | ||
private Counter _counter; | ||
private IValidationStrategy validationStrategy; | ||
|
||
public ValidatorBenchmarkTest(ITestOutputHelper output) | ||
{ | ||
ResultCollector resultCollector = new ResultCollector(); | ||
|
||
string specPath = Path.Combine(Environment.CurrentDirectory, "PerfSpec.yaml"); | ||
//stub this out on SpecificationProvider | ||
OpenApiDocument spec = OpenApiYamlDocument.FromFileAsync(specPath).Result; | ||
Mock<ISpecificationProvider> mockSpecPro = new Mock<ISpecificationProvider>(); | ||
mockSpecPro.Setup(x => x.GetSpecDocument()).Returns(spec); | ||
|
||
validationStrategy = new ValidationBuilder(resultCollector, mockSpecPro.Object) | ||
.WithPath("/order") | ||
.WithMethod(HttpMethod.Post) | ||
.WithStatusCode(HttpStatusCode.Created) | ||
.WithBody("{\"id\":5,\"price\":10.0,\"items\":[]}", new HttpContentType("application/json")) | ||
.Build(); | ||
|
||
Trace.Listeners.Clear(); | ||
Trace.Listeners.Add(new XunitTraceListener(output)); | ||
} | ||
|
||
[PerfSetup] | ||
public void Setup(BenchmarkContext context) | ||
{ | ||
_counter = context.GetCounter("Iterations"); | ||
} | ||
|
||
/// <summary> | ||
/// Ensure that we can validate at least 10,000 times per second. | ||
/// </summary> | ||
[NBenchFact] | ||
[PerfBenchmark( | ||
Description = "Ensure validation doesn't take too long", | ||
NumberOfIterations = 3, | ||
RunTimeMilliseconds = 1000, | ||
RunMode = RunMode.Throughput, | ||
TestMode = TestMode.Test)] | ||
[CounterThroughputAssertion("Iterations", MustBe.GreaterThan, 10000)] | ||
public void ValidationStrategy_Validate_Benchmark() | ||
{ | ||
validationStrategy.Validate(); | ||
_counter.Increment(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters