Skip to content
Merged
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
39 changes: 33 additions & 6 deletions src/core/Akka.Cluster.Tests/ClusterLogSpec.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

using System;
using System.Linq;
using System.Threading.Tasks;
using Akka.Actor;
using Akka.Configuration;
using Akka.TestKit;
Expand Down Expand Up @@ -67,6 +68,18 @@ protected void Join(string expected)
.ExpectOne(() => _cluster.Join(_selfAddress));
});
}
/// <summary>
/// The expected log info pattern to intercept after a <see cref="Cluster.Join(Address)"/>.
/// </summary>
protected async Task JoinAsync(string expected)
{
await WithinAsync(TimeSpan.FromSeconds(10), async () =>
{
await EventFilter
.Info(contains: expected)
.ExpectOneAsync(TimeSpan.FromMinutes(1), () => _cluster.Join(_selfAddress));

@eaba eaba Jan 28, 2022 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The default timeout was 3s....bumped this up to see how that goes! The test failed at times due to timeout.

});
}

/// <summary>
/// The expected log info pattern to intercept after a <see cref="Cluster.Down(Address)"/>.
Expand All @@ -81,6 +94,20 @@ protected void Down(string expected)
.ExpectOne(() => _cluster.Down(_selfAddress));
});
}

/// <summary>
/// The expected log info pattern to intercept after a <see cref="Cluster.Down(Address)"/>.
/// </summary>
/// <param name="expected"></param>
protected async Task DownAsync(string expected)
{
await WithinAsync(TimeSpan.FromSeconds(10), async () =>
{
await EventFilter
.Info(contains: expected)
.ExpectOneAsync(() => _cluster.Down(_selfAddress));
});
}
}

public class ClusterLogDefaultSpec : ClusterLogSpec
Expand All @@ -90,13 +117,13 @@ public ClusterLogDefaultSpec(ITestOutputHelper output)
{ }

[Fact]
public void A_cluster_must_log_a_message_when_becoming_and_stopping_being_a_leader()
public async Task A_cluster_must_log_a_message_when_becoming_and_stopping_being_a_leader()
{
_cluster.Settings.LogInfo.ShouldBeTrue();
_cluster.Settings.LogInfoVerbose.ShouldBeFalse();
Join("is the new leader");
await JoinAsync("is the new leader");
AwaitUp();
Down("is no longer leader");
await DownAsync("is no longer leader");
}
}

Expand Down Expand Up @@ -125,12 +152,12 @@ public ClusterLogVerboseEnabledSpec(ITestOutputHelper output)
{ }

[Fact]
public void A_cluster_must_log_verbose_cluster_events_when_log_info_verbose_is_on()
public async Task A_cluster_must_log_verbose_cluster_events_when_log_info_verbose_is_on()
{
_cluster.Settings.LogInfoVerbose.ShouldBeTrue();
Join(upLogMessage);
await JoinAsync(upLogMessage);
AwaitUp();
Down(downLogMessage);
await DownAsync(downLogMessage);
}
}
}