Skip to content

Poller tests fix #960

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 6 commits into from
Closed
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
30 changes: 23 additions & 7 deletions src/NetMQ.Tests/NetMQPollerTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ public void ResponsePoll()
}
}

[Fact]
public void Monitoring()
[Fact(Timeout=5000)]
public async Task Monitoring()
{
var listeningEvent = new ManualResetEvent(false);
var acceptedEvent = new ManualResetEvent(false);
Expand Down Expand Up @@ -81,11 +81,27 @@ public void Monitoring()
req.Connect("tcp://127.0.0.1:" + port);
req.SendFrame("a");

rep.SkipFrame();
// keep the test from blocking when something goes wrong.
var timeout = new CancellationTokenSource(5000).Token;
Exception? e = null;

await Task.Run(() =>
{
try
{
rep.SkipFrame();

rep.SendFrame("b");

rep.SendFrame("b");
req.SkipFrame();
}
catch (Exception ex)
{
e = ex;
}
}, timeout);

req.SkipFrame();
Assert.Null(e);

Assert.True(listeningEvent.WaitOne(300));
Assert.True(connectedEvent.WaitOne(300));
Expand Down Expand Up @@ -768,8 +784,8 @@ public void ChangeTimerInterval()

Assert.Equal(3, count);

Assert.True(Math.Abs(length1 - 30) <= 10.0);
Assert.True(Math.Abs(length2 - 60) <= 10.0);
Assert.InRange(Math.Abs(length1 - 30), 0, 10);
Assert.InRange(Math.Abs(length2 - 60), 0, 10);
}

[Fact]
Expand Down
2 changes: 1 addition & 1 deletion src/NetMQ/Core/Transports/ByteArraySegment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public ByteArraySegment(ByteArraySegment otherSegment, int offset)
/// <summary>
/// Get the number of bytes within the buffer that is past the Offset (ie, buffer-length minus offset).
/// </summary>
public int Size => m_innerBuffer.Length - Offset;
public int Size => m_innerBuffer == null ? 0 : m_innerBuffer.Length - Offset;
Copy link
Member

Choose a reason for hiding this comment

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

I'm not sure about this change. Code shouldn't be using an initialised version of this struct. The buffer should always be non-null. If it's null here, then there's a bug somewhere else. That is the bug that should probably be identified and fixed. At least that's my working assumption.


/// <summary>
/// Add the given value to the offset.
Expand Down
2 changes: 1 addition & 1 deletion src/NetMQ/Core/Transports/Tcp/TcpListener.cs
Original file line number Diff line number Diff line change
Expand Up @@ -123,11 +123,11 @@ public virtual void SetAddress(string addr)
m_address.Resolve(addr, m_options.IPv4Only);

Assumes.NotNull(m_address.Address);


try
{
m_handle = AsyncSocket.Create(m_address.Address.AddressFamily, SocketType.Stream, ProtocolType.Tcp);

Assumes.NotNull(m_handle);

if (!m_options.IPv4Only && m_address.Address.AddressFamily == AddressFamily.InterNetworkV6)
Expand Down
Loading