forked from akkadotnet/akka.net
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Suppress extremely chatty TimerScheduler debug messages (akkadotnet#7102
) * Suppress extremely chatty TimerScheduler debug messages * Move configuration to Settings class. * Update API approval list
- Loading branch information
Showing
6 changed files
with
135 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
103 changes: 103 additions & 0 deletions
103
src/core/Akka.Tests/Actor/Scheduler/TimerSchedulerDebugSpec.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
// ----------------------------------------------------------------------- | ||
// <copyright file="TimerSchedulerSettings.cs" company="Akka.NET Project"> | ||
// Copyright (C) 2013-2024 .NET Foundation <https://github.com/akkadotnet/akka.net> | ||
// </copyright> | ||
// ----------------------------------------------------------------------- | ||
|
||
using System; | ||
using System.Diagnostics; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using Akka.Actor; | ||
using Akka.Configuration; | ||
using Akka.TestKit; | ||
using FluentAssertions.Extensions; | ||
using Xunit; | ||
using Xunit.Abstractions; | ||
using Debug = Akka.Event.Debug; | ||
|
||
namespace Akka.Tests.Actor.Scheduler; | ||
|
||
internal sealed class TimerTestActor: UntypedActor, IWithTimers | ||
{ | ||
protected override void OnReceive(object message) | ||
{ | ||
switch (message) | ||
{ | ||
case "startTimer": | ||
Timers.StartSingleTimer("test", "test", 1.Seconds()); | ||
break; | ||
case "test": | ||
break; | ||
default: | ||
Unhandled(message); | ||
break; | ||
} | ||
} | ||
|
||
public ITimerScheduler Timers { get; set; } | ||
} | ||
|
||
public class TimerSchedulerDebug: TestKit.Xunit2.TestKit | ||
{ | ||
public TimerSchedulerDebug(ITestOutputHelper output) : base("akka.actor.debug.log-timers = true", null, output) | ||
{ | ||
} | ||
|
||
[Fact] | ||
public void ShouldHonorDebugFlag() | ||
{ | ||
Sys.EventStream.Subscribe(TestActor, typeof(Debug)); | ||
var timerActor = Sys.ActorOf<TimerTestActor>(); | ||
timerActor.Tell("startTimer"); | ||
|
||
FishForMessage(msg => msg is Debug dbg && dbg.Message.ToString()!.StartsWith("Start timer [")); | ||
} | ||
} | ||
|
||
public class TimerSchedulerSuppressDebug: TestKit.Xunit2.TestKit | ||
{ | ||
public TimerSchedulerSuppressDebug(ITestOutputHelper output) : base("akka.actor.debug.log-timers = false", null, output) | ||
{ | ||
} | ||
|
||
[Fact] | ||
public async Task ShouldHonorSuppressDebugFlag() | ||
{ | ||
Sys.EventStream.Subscribe(TestActor, typeof(Debug)); | ||
var timerActor = Sys.ActorOf<TimerTestActor>(); | ||
timerActor.Tell("startTimer"); | ||
|
||
await ExpectNoMsgAsync( | ||
predicate: msg => msg is Debug dbg && dbg.Message.ToString()!.StartsWith("Start timer ["), | ||
timeout: 1.Seconds()); | ||
} | ||
|
||
private async Task ExpectNoMsgAsync( | ||
Predicate<object> predicate, | ||
TimeSpan? timeout = null, | ||
CancellationToken cancellationToken = default) | ||
{ | ||
var deadline = DateTime.Now + (timeout ?? 3.Seconds()); | ||
var offset = 0.Seconds(); | ||
|
||
while (DateTime.Now < deadline) | ||
{ | ||
var stopwatch = Stopwatch.StartNew(); | ||
var (success, envelope) = await TryReceiveOneAsync(timeout - offset, cancellationToken); | ||
stopwatch.Stop(); | ||
offset += stopwatch.Elapsed; | ||
|
||
if(!success) | ||
continue; | ||
|
||
var message = envelope.Message; | ||
if (!predicate(message)) | ||
continue; | ||
|
||
Assertions.Fail("Expected no message to match predicate, received {0} instead.", message); | ||
break; | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters