Skip to content
Closed
Show file tree
Hide file tree
Changes from 4 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 @@
}
}

[Fact]
public void Monitoring()
[Fact(Timeout=5000)]
public async void Monitoring()

Check warning on line 56 in src/NetMQ.Tests/NetMQPollerTest.cs

View workflow job for this annotation

GitHub Actions / windows

Support for 'async void' unit tests is being removed from xUnit.net v3. To simplify upgrading, convert the test to 'async Task' instead. (https://xunit.net/xunit.analyzers/rules/xUnit1048)

Check warning on line 56 in src/NetMQ.Tests/NetMQPollerTest.cs

View workflow job for this annotation

GitHub Actions / windows

Support for 'async void' unit tests is being removed from xUnit.net v3. To simplify upgrading, convert the test to 'async Task' instead. (https://xunit.net/xunit.analyzers/rules/xUnit1048)

Check warning on line 56 in src/NetMQ.Tests/NetMQPollerTest.cs

View workflow job for this annotation

GitHub Actions / ununtu

Support for 'async void' unit tests is being removed from xUnit.net v3. To simplify upgrading, convert the test to 'async Task' instead. (https://xunit.net/xunit.analyzers/rules/xUnit1048)

Check warning on line 56 in src/NetMQ.Tests/NetMQPollerTest.cs

View workflow job for this annotation

GitHub Actions / ununtu

Support for 'async void' unit tests is being removed from xUnit.net v3. To simplify upgrading, convert the test to 'async Task' instead. (https://xunit.net/xunit.analyzers/rules/xUnit1048)
{
var listeningEvent = new ManualResetEvent(false);
var acceptedEvent = new ManualResetEvent(false);
Expand Down Expand Up @@ -81,11 +81,27 @@
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;

Check warning on line 86 in src/NetMQ.Tests/NetMQPollerTest.cs

View workflow job for this annotation

GitHub Actions / windows

Converting null literal or possible null value to non-nullable type.

Check warning on line 86 in src/NetMQ.Tests/NetMQPollerTest.cs

View workflow job for this annotation

GitHub Actions / windows

Converting null literal or possible null value to non-nullable type.

Check warning on line 86 in src/NetMQ.Tests/NetMQPollerTest.cs

View workflow job for this annotation

GitHub Actions / ununtu

Converting null literal or possible null value to non-nullable type.

Check warning on line 86 in src/NetMQ.Tests/NetMQPollerTest.cs

View workflow job for this annotation

GitHub Actions / ununtu

Converting null literal or possible null value to non-nullable type.

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 @@

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
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,10 +33,11 @@

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),

Check warning on line 40 in src/NetMQ/Core/Transports/V2Encoder.cs

View workflow job for this annotation

GitHub Actions / windows

Possible null reference argument for parameter 'buffer' in 'ByteArraySegment.ByteArraySegment(byte[] buffer, int offset)'.

Check warning on line 40 in src/NetMQ/Core/Transports/V2Encoder.cs

View workflow job for this annotation

GitHub Actions / windows

Possible null reference argument for parameter 'buffer' in 'ByteArraySegment.ByteArraySegment(byte[] buffer, int offset)'.

Check warning on line 40 in src/NetMQ/Core/Transports/V2Encoder.cs

View workflow job for this annotation

GitHub Actions / windows

Possible null reference argument for parameter 'buffer' in 'ByteArraySegment.ByteArraySegment(byte[] buffer, int offset)'.

Check warning on line 40 in src/NetMQ/Core/Transports/V2Encoder.cs

View workflow job for this annotation

GitHub Actions / windows

Possible null reference argument for parameter 'buffer' in 'ByteArraySegment.ByteArraySegment(byte[] buffer, int offset)'.

Check warning on line 40 in src/NetMQ/Core/Transports/V2Encoder.cs

View workflow job for this annotation

GitHub Actions / windows

Possible null reference argument for parameter 'buffer' in 'ByteArraySegment.ByteArraySegment(byte[] buffer, int offset)'.

Check warning on line 40 in src/NetMQ/Core/Transports/V2Encoder.cs

View workflow job for this annotation

GitHub Actions / ununtu

Possible null reference argument for parameter 'buffer' in 'ByteArraySegment.ByteArraySegment(byte[] buffer, int offset)'.

Check warning on line 40 in src/NetMQ/Core/Transports/V2Encoder.cs

View workflow job for this annotation

GitHub Actions / ununtu

Possible null reference argument for parameter 'buffer' in 'ByteArraySegment.ByteArraySegment(byte[] buffer, int offset)'.

Check warning on line 40 in src/NetMQ/Core/Transports/V2Encoder.cs

View workflow job for this annotation

GitHub Actions / ununtu

Possible null reference argument for parameter 'buffer' in 'ByteArraySegment.ByteArraySegment(byte[] buffer, int offset)'.

Check warning on line 40 in src/NetMQ/Core/Transports/V2Encoder.cs

View workflow job for this annotation

GitHub Actions / ununtu

Possible null reference argument for parameter 'buffer' in 'ByteArraySegment.ByteArraySegment(byte[] buffer, int offset)'.

Check warning on line 40 in src/NetMQ/Core/Transports/V2Encoder.cs

View workflow job for this annotation

GitHub Actions / ununtu

Possible null reference argument for parameter 'buffer' in 'ByteArraySegment.ByteArraySegment(byte[] buffer, int offset)'.
m_inProgress.Size, MessageReadyState, true);
}

Expand Down
Loading