Exemple #1
0
        public async Task ZipPackageFailure_DetectedOnSpecialization()
        {
            _settings.Add(EnvironmentSettingNames.AzureWebsiteInstanceId, Guid.NewGuid().ToString());
            var environment    = new TestEnvironment(_settings);
            var webHostBuilder = await CreateWebHostBuilderAsync("Windows", environment);

            IWebHost host = webHostBuilder.Build();

            await host.StartAsync();

            Assert.True(environment.IsPlaceholderModeEnabled());
            Assert.False(environment.IsContainerReady());

            // after the placeholder host is fully initialized but before we specialize
            // write the invalid zip marker file
            string markerFilePath = Path.Combine(_expectedScriptPath, ScriptConstants.RunFromPackageFailedFileName);

            File.WriteAllText(markerFilePath, "test");

            // now specialize the host
            environment.SetEnvironmentVariable(EnvironmentSettingNames.AzureWebsiteRunFromPackage, "1");
            environment.SetEnvironmentVariable(RpcWorkerConstants.FunctionWorkerRuntimeSettingName, "dotnet");
            environment.SetEnvironmentVariable(EnvironmentSettingNames.AzureWebsitePlaceholderMode, "0");
            environment.SetEnvironmentVariable(EnvironmentSettingNames.AzureWebsiteContainerReady, "1");

            Assert.False(environment.IsPlaceholderModeEnabled());
            Assert.True(environment.IsContainerReady());

            // wait for shutdown to be triggered
            var applicationLifetime = host.Services.GetServices <IApplicationLifetime>().Single();
            await TestHelpers.RunWithTimeoutAsync(() => applicationLifetime.ApplicationStopping.WaitHandle.WaitOneAsync(), TimeSpan.FromSeconds(30));

            // ensure the host was specialized and the expected error was logged
            string[] logLines = _loggerProvider.GetAllLogMessages().Where(p => p.FormattedMessage != null).Select(p => p.FormattedMessage).ToArray();
            Assert.True(logLines.Contains("Starting host specialization"));
            Assert.True(logLines.Contains($"Shutting down host due to presence of {markerFilePath}"));

            await host.StopAsync();

            host.Dispose();
        }