Skip to content
Merged
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 @@ -285,27 +285,6 @@ public void AddEnvironmentVariablesUsingPrefixWithDoubleUnderscores_Bind_PrefixM

[ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsThreadingSupported))]
public void BindingDoesNotThrowIfReloadedDuringBinding()
{
// Instrumentation for https://github.com/dotnet/runtime/issues/109904. Failfast to generate a crash dump when the test fails with NullReferenceException.
try
{
BindingDoesNotThrowIfReloadedDuringBindingWorker();
}
catch (NullReferenceException) when (FailFast())
{
}

static bool FailFast()
{
Environment.FailFast(
"Instrumentation for https://github.com/dotnet/runtime/issues/109904" + Environment.NewLine +
"Microsoft.Extensions.Configuration.EnvironmentVariables.Test.EnvironmentVariablesTest.BindingDoesNotThrowIfReloadedDuringBinding [FAIL]" + Environment.NewLine +
"System.NullReferenceException : Object reference not set to an instance of an object.");
return false;
}
}

private void BindingDoesNotThrowIfReloadedDuringBindingWorker()
{
var dic = new Dictionary<string, string>
{
Expand All @@ -317,8 +296,6 @@ private void BindingDoesNotThrowIfReloadedDuringBindingWorker()
configurationBuilder.AddEnvironmentVariables();
var config = configurationBuilder.Build();

MyOptions options = null;

using (var cts = new CancellationTokenSource(TimeSpan.FromMilliseconds(250)))
{
void ReloadLoop()
Expand All @@ -331,14 +308,17 @@ void ReloadLoop()

_ = Task.Run(ReloadLoop);

while (!cts.IsCancellationRequested)
MyOptions options;

do
{
options = config.Get<MyOptions>();
}
}
while (!cts.IsCancellationRequested);

Assert.Equal(-2, options.Number);
Assert.Equal("Foo", options.Text);
Assert.Equal(-2, options.Number);
Assert.Equal("Foo", options.Text);
}
}

private sealed class MyOptions
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -966,23 +966,19 @@ void ReloadLoop()

_ = Task.Run(ReloadLoop);

MyOptions options = null;
MyOptions options;

bool optionsInitialized = false;
while (!cts.IsCancellationRequested)
do
{
options = config.Get<MyOptions>();
optionsInitialized = true;
}
while (!cts.IsCancellationRequested);

if (optionsInitialized)
{
Assert.Equal("CmdValue1", options.CmdKey1);
Assert.Equal("IniValue1", options.IniKey1);
Assert.Equal("JsonValue1", options.JsonKey1);
Assert.Equal("MemValue1", options.MemKey1);
Assert.Equal("XmlValue1", options.XmlKey1);
}
Assert.Equal("CmdValue1", options.CmdKey1);
Assert.Equal("IniValue1", options.IniKey1);
Assert.Equal("JsonValue1", options.JsonKey1);
Assert.Equal("MemValue1", options.MemKey1);
Assert.Equal("XmlValue1", options.XmlKey1);
}
}

Expand Down
Loading