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
32 changes: 32 additions & 0 deletions src/core/Akka.Tests/Actor/Setup/ActorSystemSetupSpec.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
//-----------------------------------------------------------------------

using System;
using System.Collections.Generic;
using Akka.Actor;
using Akka.Actor.Setup;
using Akka.TestKit;
Expand Down Expand Up @@ -107,5 +108,36 @@ public void ActorSystemSettingsShouldBeAvailableFromExtendedActorSystem()
system?.Terminate().Wait(TimeSpan.FromSeconds(5));
}
}

/// <summary>
/// Reproduction for https://github.com/akkadotnet/akka.net/issues/5728
/// </summary>
[Fact]
public void ActorSystemSetupBugFix5728Reproduction()
{
// arrange
var setups = new HashSet<Akka.Actor.Setup.Setup>();
setups.Add(new DummySetup("Blantons"));
setups.Add(new DummySetup2("Colonel E.H. Taylor"));

var actorSystemSetup = ActorSystemSetup.Empty;

foreach (var s in setups)
{
actorSystemSetup = actorSystemSetup.And(s);
}

// act
var dummySetup = actorSystemSetup.Get<DummySetup>();
var dummySetup2 = actorSystemSetup.Get<DummySetup2>();

// shouldn't exist
var dummySetup3 = actorSystemSetup.Get<DummySetup3>();

// assert
dummySetup.HasValue.Should().BeTrue();

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This assertion failed prior to these changes.

dummySetup2.HasValue.Should().BeTrue();
dummySetup3.HasValue.Should().BeFalse();
}
}
}
3 changes: 2 additions & 1 deletion src/core/Akka/Actor/Setup/ActorSystemSetup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,8 @@ public Option<T> Get<T>() where T:Setup
/// <returns>A new, immutable <see cref="ActorSystemSetup"/> instance.</returns>
public ActorSystemSetup WithSetup<T>(T setup) where T : Setup
{
return new ActorSystemSetup(_setups.SetItem(typeof(T), setup));
var typeT = setup.GetType();

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Resolve type from the object, rather than the method signature.

return new ActorSystemSetup(_setups.SetItem(typeT, setup));
}

/// <summary>
Expand Down