Skip to content
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

Poller tests fix #960

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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 @@ -51,8 +51,8 @@ public void ResponsePoll()
}
}

[Fact]
public void Monitoring()
[Fact(Timeout=5000)]
public async void Monitoring()
{
var listeningEvent = new ManualResetEvent(false);
var acceptedEvent = new ManualResetEvent(false);
Expand Down Expand Up @@ -80,11 +80,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 @@ -767,8 +783,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;

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

Assumes.NotNull(m_address.Address);
Assumes.NotNull(m_handle);

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)
{
try
Expand Down
3 changes: 2 additions & 1 deletion src/NetMQ/Core/Transports/V2Encoder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ protected override void Next()

private void SizeReady()
{
Assumes.NotNull(m_inProgress.UnsafeData);
// this assumption is now deprecated.
//Assumes.NotNull(m_inProgress.UnsafeData);

// Write message body into the buffer.
NextStep(new ByteArraySegment(m_inProgress.UnsafeData, m_inProgress.UnsafeOffset),
Expand Down