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
4 changes: 4 additions & 0 deletions src/Testing/CoreTests/Util/WolverineMessageNamingTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ public void use_the_version_if_it_exists()
[Fact]
public void use_interface_from_interop_message_naming()
{
// GH-3703: this used to fail whenever any earlier test in the assembly had already booted a host
// that named ConcreteMessage -- WolverineMessageNaming memoizes into a static map, and registering
// the interop assembly did not invalidate what was already in it. AddMessageInterfaceAssembly now
// clears the cache, so the registration below takes effect regardless of what ran first.
WolverineMessageNaming.AddMessageInterfaceAssembly(typeof(IInterfaceMessage).Assembly);

typeof(ConcreteMessage).ToMessageTypeName().ShouldBe(typeof(IInterfaceMessage).ToMessageTypeName());
Expand Down
17 changes: 17 additions & 0 deletions src/Wolverine/Util/WolverineMessageNaming.cs
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,8 @@ public static class WolverineMessageNaming
{
if (_namingStrategies[0] is T) return;
_namingStrategies.Insert(0, new T());

clearCache();
}

/// <summary>
Expand All @@ -163,7 +165,22 @@ public static class WolverineMessageNaming
public static void AddMessageInterfaceAssembly(Assembly assembly)
{
var naming = _namingStrategies.OfType<InteropAssemblyInterfaces>().Single();
if (naming.Assemblies.Contains(assembly)) return;

naming.Assemblies.Fill(assembly);

clearCache();
}

/// <summary>
/// Discard every memoized message type name. Changing the naming strategies invalidates any name
/// already resolved by the previous set -- a type cached under its full name by an earlier
/// <see cref="ToMessageTypeName(Type)"/> call (or by <see cref="PrepopulateCache"/> during a host
/// start) would otherwise keep that name forever and silently ignore the new strategy. See GH-3703.
/// </summary>
private static void clearCache()
{
_typeNames = ImHashMap<Type, string>.Empty;
}

public static string GetPrettyName(this Type t)
Expand Down
Loading