|
15 | 15 | using Microsoft.Azure.WebJobs.Script.Config;
|
16 | 16 | using Microsoft.Azure.WebJobs.Script.Configuration;
|
17 | 17 | using Microsoft.Azure.WebJobs.Script.Description;
|
| 18 | +using Microsoft.Azure.WebJobs.Script.Diagnostics; |
18 | 19 | using Microsoft.Azure.WebJobs.Script.Eventing;
|
19 | 20 | using Microsoft.Azure.WebJobs.Script.Workers.Rpc;
|
20 | 21 | using Microsoft.Extensions.Configuration;
|
@@ -404,6 +405,71 @@ public async Task Initialize_WithLatestSiteExtensionVersion_LogsWarning()
|
404 | 405 | }
|
405 | 406 | }
|
406 | 407 |
|
| 408 | + [Theory] |
| 409 | + [InlineData("dotnet", "", "", "", "dotnet")] |
| 410 | + [InlineData("dotnet", "~2", "", "", "dotnet-~2")] |
| 411 | + [InlineData("python", "~2", "", "", "python")] |
| 412 | + [InlineData("python", "~2", "", "3.6", "python-3.6")] |
| 413 | + [InlineData("python", "~3", "~8", "3.7", "python-3.7")] |
| 414 | + [InlineData("node", "~3", "", "3.6", "node")] |
| 415 | + [InlineData("node", "~2", "~8", "3.6", "node-~8")] |
| 416 | + [InlineData("powershell", "~2", "", "", "powershell")] |
| 417 | + [InlineData("powershell", "~2", "~10", "3.6", "powershell")] |
| 418 | + [InlineData("java", "~3", "", "", "java")] |
| 419 | + [InlineData("java", "~3", "~8", "3.6", "java")] |
| 420 | + public async Task Initialize_WithRuntimeAndWorkerVersion_ReportRuntimeToMetricsTable( |
| 421 | + string functionsWorkerRuntime, |
| 422 | + string functionsExtensionVersion, |
| 423 | + string websiteNodeDefaultVersion, |
| 424 | + string functionsWorkerRuntimeVersion, |
| 425 | + string expectedRuntimeStack) |
| 426 | + { |
| 427 | + try |
| 428 | + { |
| 429 | + using (var tempDirectory = new TempDirectory()) |
| 430 | + { |
| 431 | + string rootPath = Path.Combine(tempDirectory.Path, Guid.NewGuid().ToString()); |
| 432 | + Directory.CreateDirectory(rootPath); |
| 433 | + var metricsLogger = new TestMetricsLogger(); |
| 434 | + var environment = new TestEnvironment(); |
| 435 | + |
| 436 | + environment.SetEnvironmentVariable( |
| 437 | + RpcWorkerConstants.FunctionWorkerRuntimeSettingName, functionsWorkerRuntime); |
| 438 | + environment.SetEnvironmentVariable( |
| 439 | + EnvironmentSettingNames.FunctionsExtensionVersion, functionsExtensionVersion); |
| 440 | + environment.SetEnvironmentVariable( |
| 441 | + EnvironmentSettingNames.WebsiteNodeDefaultVersion, websiteNodeDefaultVersion); |
| 442 | + environment.SetEnvironmentVariable( |
| 443 | + RpcWorkerConstants.FunctionWorkerRuntimeVersionSettingName, functionsWorkerRuntimeVersion); |
| 444 | + |
| 445 | + IHost host = new HostBuilder() |
| 446 | + .ConfigureServices(s => |
| 447 | + { |
| 448 | + s.AddSingleton<IEnvironment>(environment); |
| 449 | + }) |
| 450 | + .ConfigureDefaultTestWebScriptHost( |
| 451 | + null, |
| 452 | + o => |
| 453 | + { |
| 454 | + o.ScriptPath = rootPath; |
| 455 | + }, |
| 456 | + false, |
| 457 | + s => |
| 458 | + { |
| 459 | + s.AddSingleton<IMetricsLogger>(metricsLogger); |
| 460 | + }) |
| 461 | + .Build(); |
| 462 | + var scriptHost = host.GetScriptHost(); |
| 463 | + await scriptHost.InitializeAsync(); |
| 464 | + Assert.Single(metricsLogger.LoggedEvents, e => e.Equals($"host.startup.runtime.language.{expectedRuntimeStack}")); |
| 465 | + } |
| 466 | + } |
| 467 | + finally |
| 468 | + { |
| 469 | + EnvironmentExtensions.BaseDirectory = null; |
| 470 | + } |
| 471 | + } |
| 472 | + |
407 | 473 | // TODO: Newer TODO - ApplyConfiguration no longer exists. Validate logic (moved to HostJsonFileConfigurationSource)
|
408 | 474 | // TODO: Move this test into a new WebJobsCoreScriptBindingProvider class since
|
409 | 475 | // the functionality moved. Also add tests for the ServiceBus config, etc.
|
|
0 commit comments