Skip to content

Commit

Permalink
Move task utils to test project where it belongs
Browse files Browse the repository at this point in the history
  • Loading branch information
tmatthey committed May 24, 2024
1 parent 92aae64 commit 4d3c831
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 20 deletions.
4 changes: 2 additions & 2 deletions src/NetMQ.Tests/NetMQMonitorTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public void StartAsync()
Thread.Sleep(200);
Assert.Equal(TaskStatus.Running, task.Status);
monitor.Stop();
Assert.True(Utils.Tasks.Wait(task, TimeSpan.FromMilliseconds(1000)));
Assert.True(TaskUtils.Wait(task, TimeSpan.FromMilliseconds(1000)));
}
}
#endif
Expand Down Expand Up @@ -154,7 +154,7 @@ public void MonitorDisposeProperlyWhenDisposedAfterMonitoredTcpSocket()
}
Thread.Sleep(100);
// Monitor.Dispose should complete
var completed = Utils.Tasks.Wait(Task.Factory.StartNew(() => monitor.Dispose()), TimeSpan.FromMilliseconds(1000));
var completed = TaskUtils.Wait(Task.Factory.StartNew(() => monitor.Dispose()), TimeSpan.FromMilliseconds(1000));
Assert.True(completed);
}
// NOTE If this test fails, it will hang because context.Dispose will block
Expand Down
18 changes: 9 additions & 9 deletions src/NetMQ.Tests/NetMQPollerTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,7 @@ public void RemoveSocket()

poller.Stop();
// await the pollerTask, 1ms should suffice
Utils.Tasks.Wait(pollerTask, TimeSpan.FromMilliseconds(1));
TaskUtils.Wait(pollerTask, TimeSpan.FromMilliseconds(1));
Assert.True(pollerTask.IsCompleted);
}
}
Expand Down Expand Up @@ -879,7 +879,7 @@ public void OneTask()
Assert.True(poller.CanExecuteTaskInline, "Should be on NetMQPoller thread");
});
task.Start(poller);
Utils.Tasks.Wait(task);
TaskUtils.Wait(task);

Assert.True(triggered);
}
Expand All @@ -894,7 +894,7 @@ public void SetsCurrentTaskScheduler()

var task = new Task(() => Assert.Same(TaskScheduler.Current, poller));
task.Start(poller);
Utils.Tasks.Wait(task);
TaskUtils.Wait(task);
}
}

Expand All @@ -911,7 +911,7 @@ public void CanExecuteTaskInline()

var task = new Task(() => Assert.True(poller.CanExecuteTaskInline));
task.Start(poller);
Utils.Tasks.Wait(task);
TaskUtils.Wait(task);
}
}

Expand Down Expand Up @@ -941,8 +941,8 @@ public void ContinueWith()
}, poller);

task.Start(poller);
Utils.Tasks.Wait(task);
Utils.Tasks.Wait(task2);
TaskUtils.Wait(task);
TaskUtils.Wait(task2);

Assert.Equal(threadId1, threadId2);
Assert.Equal(1, runCount1);
Expand Down Expand Up @@ -982,9 +982,9 @@ public void TwoThreads()
}
});

Utils.Tasks.Wait(t1, TimeSpan.FromMilliseconds(1000));
Utils.Tasks.Wait(t2, TimeSpan.FromMilliseconds(1000));
Utils.Tasks.WaitAll(allTasks.ToArray(), TimeSpan.FromMilliseconds(1000));
TaskUtils.Wait(t1, TimeSpan.FromMilliseconds(1000));
TaskUtils.Wait(t2, TimeSpan.FromMilliseconds(1000));
TaskUtils.WaitAll(allTasks.ToArray(), TimeSpan.FromMilliseconds(1000));

Assert.Equal(100, count1);
Assert.Equal(100, count2);
Expand Down
2 changes: 1 addition & 1 deletion src/NetMQ.Tests/NetMQQueueTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public void EnqueueShouldNotBlockWhenCapacityIsZero()
}
});

bool completed = Utils.Tasks.Wait(task, TimeSpan.FromSeconds(1));
bool completed = TaskUtils.Wait(task, TimeSpan.FromSeconds(1));
Assert.True(completed, "Enqueue task should have completed " + socketWatermarkCapacity + " enqueue within 1 second");
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/NetMQ.Tests/PgmTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -230,8 +230,8 @@ public void Sending1000Messages()
}
});

Utils.Tasks.Wait(pubTask);
Utils.Tasks.Wait(subTask);
TaskUtils.Wait(pubTask);
TaskUtils.Wait(subTask);

Assert.Equal(1000, count);
}
Expand Down Expand Up @@ -291,7 +291,7 @@ public void SubscriberCleanupOnUnbind(string address)

monitor.Stop();

Utils.Tasks.Wait(monitorTask);
TaskUtils.Wait(monitorTask);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/NetMQ.Tests/SocketTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ public void ReceiveMessageWithTimeout()
t1.Start();
t2.Start();

Utils.Tasks.WaitAll(new[]{t1, t2});
TaskUtils.WaitAll(new[]{t1, t2});
}
}

Expand Down
6 changes: 2 additions & 4 deletions src/NetMQ/Utils/Tasks.cs → src/NetMQ.Tests/TaskUtils.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;

namespace NetMQ.Utils
namespace NetMQ.Tests
{
internal class Tasks
internal class TaskUtils
{
internal static async Task PollUntil(Func<bool> condition, TimeSpan timeout)
{
Expand Down

0 comments on commit 4d3c831

Please sign in to comment.