Skip to content

Commit b03c7bf

Browse files
committed
Update new test method
1 parent 56fb132 commit b03c7bf

File tree

2 files changed

+26
-52
lines changed

2 files changed

+26
-52
lines changed

src/WebJobs.Script/Diagnostics/OpenTelemetry/OpenTelemetryConfigurationExtensions.cs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -68,18 +68,19 @@ private static IOpenTelemetryBuilder ConfigureMetrics(this IOpenTelemetryBuilder
6868
return builder.WithMetrics(builder =>
6969
{
7070
builder.AddAspNetCoreInstrumentation()
71-
.AddRuntimeInstrumentation()
72-
.AddProcessInstrumentation()
73-
.AddMeter(HostMetrics.FaasMeterName)
74-
.AddView(HostMetrics.FaasInvokeDuration, new ExplicitBucketHistogramConfiguration
75-
{
76-
Boundaries = new double[] { 0.005, 0.01, 0.025, 0.05, 0.075, 0.1, 0.25, 0.5, 0.75, 1, 2.5, 5, 7.5, 10 }
77-
});
71+
.AddRuntimeInstrumentation()
72+
.AddProcessInstrumentation()
73+
.AddMeter(HostMetrics.FaasMeterName)
74+
.AddView(HostMetrics.FaasInvokeDuration, new ExplicitBucketHistogramConfiguration
75+
{
76+
Boundaries = new double[] { 0.005, 0.01, 0.025, 0.05, 0.075, 0.1, 0.25, 0.5, 0.75, 1, 2.5, 5, 7.5, 10 }
77+
});
7878

7979
if (enableOtlp)
8080
{
8181
builder.AddOtlpExporter();
8282
}
83+
8384
if (enableAzureMonitor)
8485
{
8586
builder.AddAzureMonitorMetricExporter(opt => ConfigureAzureMonitorOptions(opt, azMonConnectionString, credential));

test/WebJobs.Script.Tests/ScriptStartupTypeDiscovererTests.cs

Lines changed: 18 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -492,57 +492,23 @@ public async Task GetExtensionsStartupTypes_BundlesNotConfiguredBindingsConfigur
492492
[Fact]
493493
public async Task GetExtensionsStartupTypes_NoBindings_In_ExtensionJson()
494494
{
495-
TestMetricsLogger testMetricsLogger = new TestMetricsLogger();
496-
497-
using var directory = new TempDirectory();
498-
var binPath = Path.Combine(directory.Path, "bin");
499-
Directory.CreateDirectory(binPath);
500-
501-
void CopyToBin(string path)
495+
ExtensionInstall storage1 = new("AzureStorageBlobs", typeof(AzureStorageWebJobsStartup));
496+
ExtensionInstall storage2 = new("Storage", typeof(AzureStorageWebJobsStartup))
502497
{
503-
File.Copy(path, Path.Combine(binPath, Path.GetFileName(path)));
504-
}
498+
HintPath = "Microsoft.Azure.WebJobs.Extensions.Storage.dll"
499+
};
505500

506-
CopyToBin(typeof(AzureStorageWebJobsStartup).Assembly.Location);
507-
508-
string extensionJson = $$"""
509-
{
510-
"extensions": [
511-
{
512-
"name": "Storage",
513-
"typeName": "{{typeof(AzureStorageWebJobsStartup).AssemblyQualifiedName}}",
514-
"hintPath": "Microsoft.Azure.WebJobs.Extensions.Storage.dll"
515-
},
516-
{
517-
"Name": "AzureStorageBlobs",
518-
"TypeName": "{{typeof(AzureStorageWebJobsStartup).AssemblyQualifiedName}}"
519-
}
520-
]
521-
}
522-
""";
523-
524-
File.WriteAllText(Path.Combine(binPath, "extensions.json"), extensionJson);
525-
526-
TestLoggerProvider testLoggerProvider = new TestLoggerProvider();
527-
LoggerFactory factory = new LoggerFactory();
528-
factory.AddProvider(testLoggerProvider);
529-
var testLogger = factory.CreateLogger<ScriptStartupTypeLocator>();
530-
531-
var mockExtensionBundleManager = new Mock<IExtensionBundleManager>();
532-
mockExtensionBundleManager.Setup(e => e.IsExtensionBundleConfigured()).Returns(true);
533-
mockExtensionBundleManager.Setup(e => e.GetExtensionBundleDetails()).Returns(Task.FromResult(new ExtensionBundleDetails() { Id = "bundleID", Version = "1.0.0" }));
534-
mockExtensionBundleManager.Setup(e => e.GetExtensionBundleBinPathAsync()).Returns(Task.FromResult(binPath));
535-
536-
var languageWorkerOptions = new TestOptionsMonitor<LanguageWorkerOptions>(new LanguageWorkerOptions());
537-
var mockFunctionMetadataManager = GetTestFunctionMetadataManager(languageWorkerOptions);
538-
OptionsWrapper<ExtensionRequirementOptions> optionsWrapper = new(new ExtensionRequirementOptions());
539-
var discoverer = new ScriptStartupTypeLocator(directory.Path, testLogger, mockExtensionBundleManager.Object, mockFunctionMetadataManager, testMetricsLogger, optionsWrapper);
501+
string binPath = InstallExtensions(storage1, storage2);
502+
_bundleManager.Setup(e => e.IsExtensionBundleConfigured()).Returns(true);
503+
_bundleManager.Setup(e => e.GetExtensionBundleDetails()).ReturnsAsync(new ExtensionBundleDetails() { Id = "bundleID", Version = "1.0.0" });
504+
_bundleManager.Setup(e => e.GetExtensionBundleBinPathAsync()).ReturnsAsync(binPath);
505+
ScriptStartupTypeLocator discoverer = CreateSystemUnderTest();
540506

541507
// Act
542508
var types = await discoverer.GetExtensionsStartupTypesAsync();
543509

544510
// Assert
545-
AreExpectedMetricsGenerated(testMetricsLogger);
511+
AreExpectedMetricsGenerated();
546512
Assert.Equal(types.Count(), 2);
547513
Assert.Equal(typeof(AzureStorageWebJobsStartup).FullName, types.FirstOrDefault().FullName);
548514
}
@@ -703,6 +669,8 @@ private bool AreExpectedMetricsGenerated()
703669

704670
private class ExtensionInstall(string name, Type startupType, params string[] bindings)
705671
{
672+
public string HintPath { get; init; }
673+
706674
public static ExtensionInstall Storage(bool includeBinding = false)
707675
{
708676
string[] bindings = includeBinding ? ["blob"] : [];
@@ -727,7 +695,12 @@ public static ExtensionInstall Http()
727695

728696
public ExtensionReference GetReference()
729697
{
730-
ExtensionReference reference = new() { Name = name, TypeName = startupType.AssemblyQualifiedName };
698+
ExtensionReference reference = new()
699+
{
700+
Name = name,
701+
TypeName = startupType.AssemblyQualifiedName,
702+
HintPath = HintPath,
703+
};
731704
foreach (string binding in bindings ?? Enumerable.Empty<string>())
732705
{
733706
reference.Bindings.Add(binding);

0 commit comments

Comments
 (0)