Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add env var check for worker runtime in StartHostAction #4198

Open
wants to merge 2 commits into
base: v4.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -737,7 +737,13 @@ private void EnsureWorkerRuntimeIsSet()
return;
}

if (GlobalCoreToolsSettings.CurrentWorkerRuntimeOrNone == WorkerRuntime.None)
var environmentRuntimeSettingValue = Environment.GetEnvironmentVariable(Constants.FunctionsWorkerRuntime);
if (environmentRuntimeSettingValue is not null)
{
GlobalCoreToolsSettings.CurrentWorkerRuntime = WorkerRuntimeLanguageHelper.NormalizeWorkerRuntime(environmentRuntimeSettingValue);
}

else if (GlobalCoreToolsSettings.CurrentWorkerRuntimeOrNone == WorkerRuntime.None)
{
SelectionMenuHelper.DisplaySelectionWizardPrompt("worker runtime");
IDictionary<WorkerRuntime, string> workerRuntimeToDisplayString = WorkerRuntimeLanguageHelper.GetWorkerToDisplayStrings();
Expand Down
60 changes: 60 additions & 0 deletions test/Azure.Functions.Cli.Tests/E2E/StartTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1115,6 +1115,66 @@ await CliTester.Run(new RunConfiguration[]

}

[Fact]
public async Task Start_MissingLocalSettingsJson_SetWithEnvVar_SuccessfulFunctionExecution()
{
try
{
Environment.SetEnvironmentVariable("FUNCTIONS_WORKER_RUNTIME", "dotnet-isolated");

await CliTester.Run(new RunConfiguration[]
{
new RunConfiguration
{
Commands = new[]
{
$"init . --worker-runtime dotnet-isolated",
$"new --template Httptrigger --name HttpTriggerFunc",
},
CommandTimeout = TimeSpan.FromSeconds(300),
},
new RunConfiguration
{
PreTest = (workingDir) =>
{
var LocalSettingsJson = Path.Combine(workingDir, "local.settings.json");
File.Delete(LocalSettingsJson);
},
Commands = new[]
{
$"start --port {_funcHostPort}",
},
ExpectExit = false,
OutputContains = new[]
{
$"local.settings.json",
"Functions:",
$"HttpTriggerFunc: [GET,POST] http://localhost:{_funcHostPort}/api/HttpTriggerFunc"
},
OutputDoesntContain = new string[]
{
"Initializing function HTTP routes"
},
Test = async (_, p,_) =>
{
using (var client = new HttpClient() { BaseAddress = new Uri($"http://localhost:{_funcHostPort}/") })
{
(await WaitUntilReady(client)).Should().BeTrue(because: _serverNotReady);
var response = await client.GetAsync("/api/HttpTriggerFunc?name=Test");
response.StatusCode.Should().Be(HttpStatusCode.OK);
await Task.Delay(TimeSpan.FromSeconds(2));
p.Kill();
}
}
}
}, _output);
}
finally
{
Environment.SetEnvironmentVariable("FUNCTIONS_WORKER_RUNTIME", null);
}
}

private async Task<bool> WaitUntilReady(HttpClient client)
{
for (var limit = 0; limit < 10; limit++)
Expand Down