Skip to content

Commit

Permalink
Enforce env startup hook precedence over runtimeconfig startup hooks
Browse files Browse the repository at this point in the history
  • Loading branch information
tomdegoede committed Nov 19, 2021
1 parent 8fa1369 commit faba436
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
15 changes: 10 additions & 5 deletions src/installer/tests/HostActivation.Tests/StartupHooks.cs
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ public void Muxer_activation_of_RuntimeConfig_StartupHook_Succeeds()
}

[Fact]
public void Muxer_activation_of_RuntimeConfig_And_Environment_StartupHooks_Succeeds()
public void Muxer_activation_of_RuntimeConfig_And_Environment_StartupHooks_SucceedsInExpectedOrder()
{
var fixture = sharedTestState.PortableAppFixture.Copy();
var dotnet = fixture.BuiltDotnet;
Expand All @@ -147,16 +147,21 @@ public void Muxer_activation_of_RuntimeConfig_And_Environment_StartupHooks_Succe
var startupHook2Fixture = sharedTestState.StartupHookWithDependencyFixture.Copy();
var startupHook2Dll = startupHook2Fixture.TestProject.AppDll;

// RuntimeConfig and Environment startup hook
// include any char to counter output from other threads such as in #57243
const string wildcardPattern = @"[\r\n\s.]*";

// RuntimeConfig and Environment startup hooks in expected order
dotnet.Exec(appDll)
.EnvironmentVariable(startupHookVarName, startupHook2Dll)
.CaptureStdOut()
.CaptureStdErr()
.Execute()
.Should().Pass()
.And.HaveStdOutContaining("Hello from startup hook!")
.And.HaveStdOutContaining("Hello from startup hook with dependency!")
.And.HaveStdOutContaining("Hello World");
.And.HaveStdOutMatching("Hello from startup hook with dependency!" +
wildcardPattern +
"Hello from startup hook!" +
wildcardPattern +
"Hello World");
}

// Empty startup hook variable
Expand Down
2 changes: 2 additions & 0 deletions src/native/corehost/hostpolicy/hostpolicy_context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,8 @@ int hostpolicy_context_t::initialize(hostpolicy_init_t &hostpolicy_init, const a
const pal::char_t *config_startup_hooks;
if (coreclr_properties.try_get(common_property::StartUpHooks, &config_startup_hooks))
{
// env startup hooks shoold have precedence over config startup hooks
// therefore append config_startup_hooks AFTER startup_hooks
startup_hooks.push_back(PATH_SEPARATOR);
startup_hooks.append(config_startup_hooks);
}
Expand Down

0 comments on commit faba436

Please sign in to comment.