Skip to content

Commit 1fc2fa8

Browse files
committed
Update tests to common packaging. Address style issues
1 parent 7b61969 commit 1fc2fa8

File tree

92 files changed

+688
-654
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

92 files changed

+688
-654
lines changed

Directory.Packages.props

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@
9595

9696
<!-- Other packages -->
9797
<ItemGroup>
98+
<PackageVersion Include="BenchmarkDotNet" Version="0.13.1" />
9899
<PackageVersion Include="Mono.Posix.NETStandard" Version="1.0.0" />
99100
<PackageVersion Include="Newtonsoft.Json" Version="13.0.3" />
100101
</ItemGroup>

global.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"sdk": {
3-
"version": "8.0.101",
3+
"version": "9.0.100",
44
"rollForward": "latestFeature"
55
},
66
"msbuild-sdks": {

perf/WebJobs.Script.Benchmarks/AuthUtilityBenchmarks.cs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,21 @@
11
// Copyright (c) .NET Foundation. All rights reserved.
22
// Licensed under the MIT License. See License.txt in the project root for license information.
33

4-
using BenchmarkDotNet.Attributes;
5-
using Microsoft.Azure.WebJobs.Extensions.Http;
6-
using Microsoft.Azure.WebJobs.Script.WebHost.Security.Authentication;
7-
using Microsoft.Azure.WebJobs.Script.WebHost.Security.Authorization;
84
using System;
95
using System.Collections.Generic;
106
using System.Linq;
117
using System.Security.Claims;
8+
using BenchmarkDotNet.Attributes;
9+
using Microsoft.Azure.WebJobs.Extensions.Http;
10+
using Microsoft.Azure.WebJobs.Script.WebHost.Security.Authentication;
11+
using Microsoft.Azure.WebJobs.Script.WebHost.Security.Authorization;
1212

1313
namespace Microsoft.Azure.WebJobs.Script.Benchmarks
1414
{
1515
public class AuthUtilityBenchmarks
1616
{
17-
private ClaimsPrincipal Principal;
17+
private ClaimsPrincipal _principal;
18+
1819
private static List<Claim> TotallyRandomClaims { get; } = new List<Claim>()
1920
{
2021
new Claim(SecurityConstants.AuthLevelKeyNameClaimType, "test1"),
@@ -28,29 +29,29 @@ public class AuthUtilityBenchmarks
2829
};
2930

3031
[Params(null, "code")]
31-
public string KeyName;
32+
public string KeyName { get; set; }
3233

3334
[Params(0, 4, 8)]
34-
public int ClaimsCount;
35+
public int ClaimsCount { get; set; }
3536

3637
[GlobalSetup]
3738
public void Setup()
3839
{
3940
var identity = new ClaimsIdentity(TotallyRandomClaims.Take(ClaimsCount));
40-
Principal = new ClaimsPrincipal(identity);
41+
_principal = new ClaimsPrincipal(identity);
4142
}
4243

4344
[Benchmark(Baseline = true)]
4445
public bool PrincipalHasAuthLevelClaim() =>
45-
AuthUtility.PrincipalHasAuthLevelClaim(Principal, AuthorizationLevel.Function);
46+
AuthUtility.PrincipalHasAuthLevelClaim(_principal, AuthorizationLevel.Function);
4647

4748
[Benchmark]
4849
public bool PrincipalHasAuthLevelClaimNoArray() =>
49-
PrincipalHasAuthLevelClaimNoArray(Principal, AuthorizationLevel.Function);
50+
PrincipalHasAuthLevelClaimNoArray(_principal, AuthorizationLevel.Function);
5051

5152
[Benchmark]
5253
public bool PrincipalHasAuthLevelClaimHasClaim() =>
53-
PrincipalHasAuthLevelClaimHasClaim(Principal, AuthorizationLevel.Function);
54+
PrincipalHasAuthLevelClaimHasClaim(_principal, AuthorizationLevel.Function);
5455

5556
public static bool PrincipalHasAuthLevelClaimNoArray(ClaimsPrincipal principal, AuthorizationLevel requiredLevel, string keyName = null)
5657
{
@@ -107,8 +108,7 @@ public static bool PrincipalHasAuthLevelClaimHasClaim(ClaimsPrincipal principal,
107108

108109
return principal.HasClaim(c => c.Type == SecurityConstants.AuthLevelClaimType
109110
&& (c.Value == nameof(AuthorizationLevel.Admin)
110-
|| (c.Value == levelString && (keyName == null || string.Equals(principal.FindFirstValue(SecurityConstants.AuthLevelKeyNameClaimType), keyName, StringComparison.OrdinalIgnoreCase)))
111-
));
111+
|| (c.Value == levelString && (keyName == null || string.Equals(principal.FindFirstValue(SecurityConstants.AuthLevelKeyNameClaimType), keyName, StringComparison.OrdinalIgnoreCase)))));
112112
}
113113
}
114114
}
Lines changed: 34 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
// Copyright (c) .NET Foundation. All rights reserved.
22
// Licensed under the MIT License. See License.txt in the project root for license information.
33

4+
using System;
5+
using System.IO;
6+
using System.Runtime.CompilerServices;
7+
using System.Threading.Tasks;
48
using BenchmarkDotNet.Attributes;
59
using Microsoft.Azure.WebJobs.Script.Description;
610
using Microsoft.Azure.WebJobs.Script.Extensibility;
@@ -9,66 +13,63 @@
913
using Microsoft.CodeAnalysis.Scripting;
1014
using Microsoft.CodeAnalysis.Scripting.Hosting;
1115
using Microsoft.Extensions.Logging.Abstractions;
12-
using System;
13-
using System.IO;
14-
using System.Runtime.CompilerServices;
15-
using System.Threading.Tasks;
1616

1717
namespace Microsoft.Azure.WebJobs.Script.Benchmarks
1818
{
1919
public class CSharpCompilationBenchmarks
2020
{
21-
// Set of samples to benchmark
22-
// TODOO: BlobTrigger, needs assembly refs working
23-
[Params("DocumentDB", "HttpTrigger", "HttpTrigger-Cancellation", "HttpTrigger-CustomRoute", "NotificationHub")]
24-
public string BenchmarkTrigger;
21+
// Dyanmic Compilation
22+
private readonly InteractiveAssemblyLoader _assemblyLoader = new InteractiveAssemblyLoader();
2523

2624
// Script source
27-
private string ScriptPath;
28-
private static string GetCSharpSamplePath([CallerFilePath] string thisFilePath = null) =>
29-
Path.Combine(thisFilePath, "..", "..", "..", "sample", "CSharp");
30-
private string ScriptSource;
31-
private FunctionMetadata FunctionMetadata;
25+
private string _scriptPath;
26+
private string _scriptSource;
27+
private FunctionMetadata _functionMetadata;
28+
private IFunctionMetadataResolver _resolver;
29+
private CSharpCompilationService _compilationService;
3230

33-
// Dyanmic Compilation
34-
private readonly InteractiveAssemblyLoader AssemblyLoader = new InteractiveAssemblyLoader();
35-
private IFunctionMetadataResolver Resolver;
36-
private CSharpCompilationService CompilationService;
31+
private IDotNetCompilation _scriptCompilation;
32+
private DotNetCompilationResult _scriptAssembly;
3733

38-
private IDotNetCompilation ScriptCompilation;
39-
private DotNetCompilationResult ScriptAssembly;
34+
// Set of samples to benchmark
35+
// TODO: BlobTrigger, needs assembly refs working
36+
[Params("DocumentDB", "HttpTrigger", "HttpTrigger-Cancellation", "HttpTrigger-CustomRoute", "NotificationHub")]
37+
public string BenchmarkTrigger { get; set; }
4038

4139
[GlobalSetup]
4240
public async Task SetupAsync()
4341
{
44-
ScriptPath = Path.Combine(GetCSharpSamplePath(), BenchmarkTrigger, "run.csx");
45-
ScriptSource = File.ReadAllText(ScriptPath);
46-
FunctionMetadata = new FunctionMetadata()
42+
_scriptPath = Path.Combine(GetCSharpSamplePath(), BenchmarkTrigger, "run.csx");
43+
_scriptSource = File.ReadAllText(_scriptPath);
44+
_functionMetadata = new FunctionMetadata()
4745
{
48-
FunctionDirectory = Path.GetDirectoryName(ScriptPath),
49-
ScriptFile = ScriptPath,
46+
FunctionDirectory = Path.GetDirectoryName(_scriptPath),
47+
ScriptFile = _scriptPath,
5048
Name = BenchmarkTrigger,
5149
Language = DotNetScriptTypes.CSharp
5250
};
5351

54-
Resolver = new ScriptFunctionMetadataResolver(ScriptPath, Array.Empty<IScriptBindingProvider>(), NullLogger.Instance);
55-
CompilationService = new CSharpCompilationService(Resolver, OptimizationLevel.Release);
52+
_resolver = new ScriptFunctionMetadataResolver(_scriptPath, Array.Empty<IScriptBindingProvider>(), NullLogger.Instance);
53+
_compilationService = new CSharpCompilationService(_resolver, OptimizationLevel.Release);
5654

57-
ScriptCompilation = await CompilationService.GetFunctionCompilationAsync(FunctionMetadata);
58-
ScriptAssembly = await ScriptCompilation.EmitAsync(default);
55+
_scriptCompilation = await _compilationService.GetFunctionCompilationAsync(_functionMetadata);
56+
_scriptAssembly = await _scriptCompilation.EmitAsync(default);
5957
}
6058

6159
[Benchmark(Description = nameof(CSharpScript) + "." + nameof(CSharpScript.Create))]
62-
public Script<object> ScriptCreation() =>
63-
CSharpScript.Create(ScriptSource, options: Resolver.CreateScriptOptions(), assemblyLoader: AssemblyLoader);
60+
public Script<object> ScriptCreation() =>
61+
CSharpScript.Create(_scriptSource, options: _resolver.CreateScriptOptions(), assemblyLoader: _assemblyLoader);
6462

6563
[Benchmark(Description = nameof(CSharpCompilationService) + "." + nameof(CSharpCompilationService.GetFunctionCompilationAsync))]
66-
public Task<IDotNetCompilation> GetFunctionCompilationAsync() => CompilationService.GetFunctionCompilationAsync(FunctionMetadata);
64+
public Task<IDotNetCompilation> GetFunctionCompilationAsync() => _compilationService.GetFunctionCompilationAsync(_functionMetadata);
6765

6866
[Benchmark(Description = nameof(CSharpCompilationBenchmarks) + "." + nameof(CSharpCompilationBenchmarks.EmitAsync))]
69-
public Task<DotNetCompilationResult> EmitAsync() => ScriptCompilation.EmitAsync(default);
67+
public Task<DotNetCompilationResult> EmitAsync() => _scriptCompilation.EmitAsync(default);
7068

7169
[Benchmark(Description = nameof(DotNetCompilationResult) + "." + nameof(DotNetCompilationResult.Load))]
72-
public void Load() => ScriptAssembly.Load(FunctionMetadata,Resolver, NullLogger.Instance);
70+
public void Load() => _scriptAssembly.Load(_functionMetadata, _resolver, NullLogger.Instance);
71+
72+
private static string GetCSharpSamplePath([CallerFilePath] string thisFilePath = null) =>
73+
Path.Combine(thisFilePath, "..", "..", "..", "sample", "CSharp");
7374
}
7475
}

perf/WebJobs.Script.Benchmarks/GrpcMessageConversionBenchmarks.cs

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,33 +4,31 @@
44
using System.Threading.Tasks;
55
using BenchmarkDotNet.Attributes;
66
using Google.Protobuf.Collections;
7-
using Newtonsoft.Json;
8-
using Newtonsoft.Json.Linq;
9-
using Microsoft.Extensions.Logging;
10-
using Microsoft.Extensions.Logging.Abstractions;
117
using Microsoft.Azure.WebJobs.Script.Grpc;
12-
using Microsoft.Azure.WebJobs.Script.Grpc.Messages;
138
using Microsoft.Azure.WebJobs.Script.Workers.Rpc;
9+
using Microsoft.Extensions.Logging.Abstractions;
10+
using Newtonsoft.Json.Linq;
1411

1512
namespace Microsoft.Azure.WebJobs.Script.Benchmarks
1613
{
1714
public class GrpcMessageConversionBenchmarks
1815
{
19-
private static byte[] _byteArray = new byte[2000];
20-
private static string _str = new string('-', 2000);
21-
private static double _dbl = 2000;
22-
private static byte[][] _byteJaggedArray = new byte[1000][];
23-
private static string[] _strArray = new string[]{ new string('-', 1000), new string('-', 1000) };
24-
private static double[] _dblArray = new double[1000];
25-
private static long[] _longArray = new long[1000];
26-
private static JObject _jObj = JObject.Parse(@"{'name': 'lilian'}");
27-
internal GrpcCapabilities grpcCapabilities = new GrpcCapabilities(NullLogger.Instance);
16+
private static readonly byte[] _byteArray = new byte[2000];
17+
private static readonly string _str = new('-', 2000);
18+
private static readonly double _dbl = 2000;
19+
private static readonly byte[][] _byteJaggedArray = new byte[1000][];
20+
private static readonly string[] _strArray = [new('-', 1000), new('-', 1000)];
21+
private static readonly double[] _dblArray = new double[1000];
22+
private static readonly long[] _longArray = new long[1000];
23+
private static readonly JObject _jObj = JObject.Parse(@"{'name': 'lilian'}");
24+
25+
private readonly GrpcCapabilities _grpcCapabilities = new(NullLogger.Instance);
2826

2927
// Not easy to benchmark
3028
// public static HttpRequest _httpRequest;
3129

3230
[Benchmark]
33-
public Task ToRpc_Null() => InvokeToRpc(((object)null));
31+
public Task ToRpc_Null() => InvokeToRpc((object)null);
3432

3533
[Benchmark]
3634
public Task ToRpc_ByteArray() => InvokeToRpc(_byteArray);
@@ -56,7 +54,7 @@ public class GrpcMessageConversionBenchmarks
5654
[Benchmark]
5755
public Task ToRpc_JObject() => InvokeToRpc(_jObj);
5856

59-
public async Task InvokeToRpc(object obj) => await obj.ToRpc(NullLogger.Instance, grpcCapabilities);
57+
public async Task InvokeToRpc(object obj) => await obj.ToRpc(NullLogger.Instance, _grpcCapabilities);
6058

6159
[GlobalSetup]
6260
public void Setup()
@@ -65,7 +63,8 @@ public void Setup()
6563
{
6664
{ RpcWorkerConstants.TypedDataCollection, "1" }
6765
};
68-
grpcCapabilities.UpdateCapabilities(addedCapabilities, GrpcCapabilitiesUpdateStrategy.Merge);
66+
67+
_grpcCapabilities.UpdateCapabilities(addedCapabilities, GrpcCapabilitiesUpdateStrategy.Merge);
6968
}
7069
}
7170
}

perf/WebJobs.Script.Benchmarks/Microsoft.Azure.WebJobs.Script.Benchmarks.csproj

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,10 @@
99
</PropertyGroup>
1010

1111
<ItemGroup>
12-
<PackageReference Include="BenchmarkDotNet" Version="0.13.1" />
12+
<PackageReference Include="BenchmarkDotNet" />
13+
</ItemGroup>
14+
15+
<ItemGroup>
1316
<ProjectReference Include="../../src/WebJobs.Script/WebJobs.Script.csproj" />
1417
<ProjectReference Include="../../src/WebJobs.Script.WebHost/WebJobs.Script.WebHost.csproj" />
1518
</ItemGroup>
Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
// Copyright (c) .NET Foundation. All rights reserved.
22
// Licensed under the MIT License. See License.txt in the project root for license information.
33

4-
using BenchmarkDotNet.Running;
54
using System.IO;
5+
using BenchmarkDotNet.Running;
66

77
namespace Microsoft.Azure.WebJobs.Script.Benchmarks
88
{
@@ -12,7 +12,6 @@ public static void Main(string[] args) =>
1212
BenchmarkSwitcher
1313
.FromAssembly(typeof(Program).Assembly)
1414
.Run(args, RecommendedConfig.Create(
15-
artifactsPath: new DirectoryInfo(Path.Combine(Path.GetDirectoryName(typeof(Program).Assembly.Location), "BenchmarkDotNet.Artifacts"))
16-
));
15+
artifactsPath: new DirectoryInfo(Path.Combine(Path.GetDirectoryName(typeof(Program).Assembly.Location), "BenchmarkDotNet.Artifacts"))));
1716
}
1817
}

perf/WebJobs.Script.Benchmarks/RecommendedConfig.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// Copyright (c) .NET Foundation. All rights reserved.
22
// Licensed under the MIT License. See License.txt in the project root for license information.
33

4+
using System.IO;
45
using BenchmarkDotNet.Columns;
56
using BenchmarkDotNet.Configs;
67
using BenchmarkDotNet.Diagnosers;
@@ -10,21 +11,20 @@
1011
using BenchmarkDotNet.Loggers;
1112
using BenchmarkDotNet.Reports;
1213
using Perfolizer.Horology;
13-
using System.IO;
1414

1515
namespace Microsoft.Azure.WebJobs.Script.Benchmarks
1616
{
1717
/// <summary>
1818
/// Default config largely matching the dotnet/performance repo:
19-
/// https://github.com/dotnet/performance/blob/a453235176943a222f126762b4b5436f6687d62e/src/harness/BenchmarkDotNet.Extensions/RecommendedConfig.cs
19+
/// https://github.com/dotnet/performance/blob/a453235176943a222f126762b4b5436f6687d62e/src/harness/BenchmarkDotNet.Extensions/RecommendedConfig.cs.
2020
/// </summary>
2121
internal static class RecommendedConfig
2222
{
2323
public static IConfig Create(DirectoryInfo artifactsPath)
2424
{
2525
var job = Job.Default
2626
.WithWarmupCount(1) // 1 warmup is enough for our purpose
27-
.WithIterationTime(TimeInterval.FromMilliseconds(250)) // the default is 0.5s per iteration, which is slighlty too much for us
27+
.WithIterationTime(TimeInterval.FromMilliseconds(250)) // the default is 0.5s per iteration, which is slightly too much for us
2828
.WithMinIterationCount(15)
2929
.WithMaxIterationCount(20); // we don't want to run more that 20 iterations
3030

test/Directory.Packages.props

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<Project>
2+
<Import Project="$([MSBuild]::GetPathOfFileAbove(Directory.Packages.props, $(MSBuildThisFileDirectory)..))" />
3+
4+
<!-- Testing Packages -->
5+
<ItemGroup>
6+
<PackageVersion Include="FluentAssertions" Version="5.9.0" />
7+
<PackageVersion Include="Microsoft.AspNetCore.TestHost" Version="8.0.1" />
8+
<PackageVersion Include="Microsoft.Extensions.Diagnostics.Testing" Version="8.1.0" />
9+
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.4.1" />
10+
<PackageVersion Include="Moq" Version="4.18.4" />
11+
<PackageVersion Include="System.IO.Abstractions.TestingHelpers" Version="2.1.0.227" />
12+
<PackageVersion Include="xunit" Version="2.4.1" />
13+
<PackageVersion Include="xunit.runner.visualstudio" Version="2.8.2" />
14+
</ItemGroup>
15+
16+
<!-- Supporting Packages -->
17+
<ItemGroup>
18+
<PackageVersion Include="Microsoft.AspNet.WebApi.Core" Version="5.2.6" />
19+
<PackageVersion Include="Microsoft.Azure.DocumentDB.Core" Version="2.11.2" />
20+
<PackageVersion Include="Microsoft.Azure.WebJobs.Extensions.Storage" Version="4.0.5-11874" />
21+
<PackageVersion Include="Microsoft.Azure.Storage.Blob" Version="11.2.3" />
22+
</ItemGroup>
23+
24+
</Project>
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<Project>
2+
3+
<PropertyGroup>
4+
<ManagePackageVersionsCentrally>false</ManagePackageVersionsCentrally>
5+
</PropertyGroup>
6+
<!--
7+
<ItemGroup>
8+
<PackageVersion Include="Microsoft.Azure.WebJobs.Extensions.Storage" Version="5.3.1" />
9+
<PackageVersion Include="Microsoft.Azure.WebJobs.Extensions.Http" Version="3.2.0" />
10+
<PackageVersion Include="Microsoft.Azure.WebJobs.Extensions.Timers.Storage" Version="1.0.0-beta.1" />
11+
<PackageVersion Include="Microsoft.Azure.WebJobs.Extensions.DurableTask" Version="2.7.0" />
12+
<PackageVersion Include="Microsoft.Azure.WebJobs.Extensions.EventHubs" Version="4.2.0" />
13+
<PackageVersion Include="Microsoft.Azure.WebJobs.Extensions.ServiceBus" Version="5.4.0" />
14+
</ItemGroup> -->
15+
16+
</Project>

0 commit comments

Comments
 (0)