This is an automated email from the ASF dual-hosted git repository.
freeandnil pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/logging-log4net.git
The following commit(s) were added to refs/heads/master by this push:
new 7af40a15 https://issues.apache.org/jira/browse/LOG4NET-696 - added
timeout and log messages
7af40a15 is described below
commit 7af40a152e2a75bdac18eff3afe75ee8725ebc42
Author: Jan Friedrich <[email protected]>
AuthorDate: Sun May 11 21:48:21 2025 +0200
https://issues.apache.org/jira/browse/LOG4NET-696 - added timeout and log
messages
---
src/log4net.Tests/Appender/Internal/SimpleTelnetClient.cs | 7 ++++++-
src/log4net.Tests/Appender/TelnetAppenderTest.cs | 14 +++++++++++++-
2 files changed, 19 insertions(+), 2 deletions(-)
diff --git a/src/log4net.Tests/Appender/Internal/SimpleTelnetClient.cs
b/src/log4net.Tests/Appender/Internal/SimpleTelnetClient.cs
index 7d5b822b..72767bf7 100644
--- a/src/log4net.Tests/Appender/Internal/SimpleTelnetClient.cs
+++ b/src/log4net.Tests/Appender/Internal/SimpleTelnetClient.cs
@@ -41,11 +41,14 @@ internal sealed class SimpleTelnetClient(
/// <summary>
/// Runs the client (in a task)
/// </summary>
- internal void Run() => Task.Run(() =>
+ internal void Run(Action<string> log) => Task.Run(() =>
{
+ log("client: starting ...");
_client.Connect(new IPEndPoint(IPAddress.Loopback, port));
+ log("client: connected");
// Get a stream object for reading and writing
using NetworkStream stream = _client.GetStream();
+ log("client: has stream");
int i;
byte[] bytes = new byte[256];
@@ -54,9 +57,11 @@ internal sealed class SimpleTelnetClient(
while ((i = stream.Read(bytes, 0, bytes.Length)) != 0)
{
string data = System.Text.Encoding.ASCII.GetString(bytes, 0, i);
+ log("client: read: " + data);
received(data);
if (_cancellationTokenSource.Token.IsCancellationRequested)
{
+ log("client: canceled");
return;
}
}
diff --git a/src/log4net.Tests/Appender/TelnetAppenderTest.cs
b/src/log4net.Tests/Appender/TelnetAppenderTest.cs
index 48bf970b..0e8d5f84 100644
--- a/src/log4net.Tests/Appender/TelnetAppenderTest.cs
+++ b/src/log4net.Tests/Appender/TelnetAppenderTest.cs
@@ -70,11 +70,15 @@ public void TelnetTest()
XmlConfigurator.Configure(repository, log4NetConfig["log4net"]!);
using (SimpleTelnetClient telnetClient = new(Received, port))
{
- telnetClient.Run();
+ TestContext.Out.WriteLine("test: starting client ...");
+ telnetClient.Run(TestContext.Out.WriteLine);
WaitForReceived(1); // wait for welcome message
ILogger logger = repository.GetLogger("Telnet");
+ TestContext.Out.WriteLine("test: logging to client ...");
logger.Log(typeof(TelnetAppenderTest), Level.Info, logId, null);
+ TestContext.Out.WriteLine("test: waiting for message of client ...");
WaitForReceived(2); // wait for log message
+ TestContext.Out.WriteLine("test: canceling client ...");
}
repository.Shutdown();
Assert.That(received, Has.Count.EqualTo(2));
@@ -84,10 +88,18 @@ public void TelnetTest()
void WaitForReceived(int count)
{
+ int retries = 1;
while (received.Count < count)
{
+ retries++;
+ TestContext.Out.WriteLine($"receiver: waiting for message {count} of
client - retry {retries} failed");
+ if (retries > 100)
+ {
+ Assert.Fail("Timeout waiting for received messages");
+ }
Thread.Sleep(10);
}
+ TestContext.Out.WriteLine($"receiver: waiting for message {count} of
client - retry {retries} succeeded");
}
}
}
\ No newline at end of file