Skip to content

Commit

Permalink
Fix: ActorSystem.Settings did not load config from app.config file (#…
Browse files Browse the repository at this point in the history
…4331)

* Fix: ActorSystem.Settings did not load config from app.config file

* ActorSystemImpl does not need to check for empty config, it can process empty config

* Move spec to ConfigurationSpec. Ignore test on core target (not supported)
  • Loading branch information
Arkatufus committed Mar 12, 2020
1 parent 45e0d50 commit 66ca8ae
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/core/Akka.Tests/App.config
Expand Up @@ -21,6 +21,7 @@
}
}
}
nonsense.entry = true
]]>
</hocon>
</akka>
Expand Down
15 changes: 15 additions & 0 deletions src/core/Akka.Tests/Configuration/ConfigurationSpec.cs
Expand Up @@ -5,6 +5,7 @@
// </copyright>
//-----------------------------------------------------------------------

using System;
using System.IO;
using Akka.Configuration.Hocon;
using System.Linq;
Expand Down Expand Up @@ -80,6 +81,20 @@ public void Deserializes_hocon_configuration_from_net_config_file()
#endif
}

// unit test for bug #4330
[Fact]
public void Should_load_config_from_app_config_file()
{
#if !CORECLR
var system = ActorSystem.Create(Guid.NewGuid().ToString());
system.Settings.Config.GetBoolean("nonsense.entry").ShouldBeTrue();
system.Terminate();
#else
// Skip this test for Linux targets
Output.WriteLine("This test is skipped.");
#endif
}

}

}
2 changes: 1 addition & 1 deletion src/core/Akka/Actor/ActorSystem.cs
Expand Up @@ -112,7 +112,7 @@ public static ActorSystem Create(string name, Config config)
/// <returns>A newly created actor system with the given name.</returns>
public static ActorSystem Create(string name)
{
return CreateAndStartSystem(name, ConfigurationFactory.Default());
return CreateAndStartSystem(name, ConfigurationFactory.Load());
}

private static ActorSystem CreateAndStartSystem(string name, Config withFallback)
Expand Down
2 changes: 1 addition & 1 deletion src/core/Akka/Actor/Internal/ActorSystemImpl.cs
Expand Up @@ -74,7 +74,7 @@ public ActorSystemImpl(string name, Config config)
$"Invalid ActorSystem name [{name}], must contain only word characters (i.e. [a-zA-Z0-9] plus non-leading '-')", nameof(name));

// Not checking for empty Config here, default values will be substituted in Settings class constructor (called in ConfigureSettings)
if(config.IsNullOrEmpty())
if(config is null)
throw new ArgumentNullException(nameof(config), $"Cannot create {typeof(ActorSystemImpl)}: Configuration must not be null.");

_name = name;
Expand Down

0 comments on commit 66ca8ae

Please sign in to comment.