Skip to content

Commit c1d244e

Browse files
committed
make sure these tests don't block the main test thread for debug build.
1 parent 528e3aa commit c1d244e

File tree

3 files changed

+24
-7
lines changed

3 files changed

+24
-7
lines changed

src/NetMQ.Tests/NetMQPollerTest.cs

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,8 @@ public void ResponsePoll()
5151
}
5252
}
5353

54-
[Fact]
55-
public void Monitoring()
54+
[Fact(Timeout=5000)]
55+
public async void Monitoring()
5656
{
5757
var listeningEvent = new ManualResetEvent(false);
5858
var acceptedEvent = new ManualResetEvent(false);
@@ -80,11 +80,27 @@ public void Monitoring()
8080
req.Connect("tcp://127.0.0.1:" + port);
8181
req.SendFrame("a");
8282

83-
rep.SkipFrame();
83+
// keep the test from blocking when something goes wrong.
84+
var timeout = new CancellationTokenSource(5000).Token;
85+
Exception e = null;
86+
87+
await Task.Run(() =>
88+
{
89+
try
90+
{
91+
rep.SkipFrame();
92+
93+
rep.SendFrame("b");
8494

85-
rep.SendFrame("b");
95+
req.SkipFrame();
96+
}
97+
catch (Exception ex)
98+
{
99+
e = ex;
100+
}
101+
}, timeout);
86102

87-
req.SkipFrame();
103+
Assert.Null(e);
88104

89105
Assert.True(listeningEvent.WaitOne(300));
90106
Assert.True(connectedEvent.WaitOne(300));

src/NetMQ/Core/Transports/ByteArraySegment.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public ByteArraySegment(ByteArraySegment otherSegment, int offset)
5757
/// <summary>
5858
/// Get the number of bytes within the buffer that is past the Offset (ie, buffer-length minus offset).
5959
/// </summary>
60-
public int Size => m_innerBuffer.Length - Offset;
60+
public int Size => m_innerBuffer == null ? 0 : m_innerBuffer.Length - Offset;
6161

6262
/// <summary>
6363
/// Add the given value to the offset.

src/NetMQ/Core/Transports/V2Encoder.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ protected override void Next()
3333

3434
private void SizeReady()
3535
{
36-
Assumes.NotNull(m_inProgress.UnsafeData);
36+
// this assumption is now deprecated.
37+
//Assumes.NotNull(m_inProgress.UnsafeData);
3738

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

0 commit comments

Comments
 (0)