using NUnit.Framework;
using System;
+using System.Diagnostics;
using System.Text;
using System.Threading;
using Mono.Unix;
static Thread CreateWaitSignalThread (UnixSignal signal, int timeout)
{
Thread t1 = new Thread(delegate() {
- DateTime start = DateTime.Now;
+ var sw = Stopwatch.StartNew ();
bool r = signal.WaitOne (timeout, false);
- DateTime end = DateTime.Now;
+ sw.Stop ();
Assert.AreEqual (signal.Count, 1);
Assert.AreEqual (r, true);
- if ((end - start) > new TimeSpan (0, 0, timeout/1000))
+ if (sw.Elapsed > new TimeSpan (0, 0, timeout/1000))
throw new InvalidOperationException ("Signal slept too long");
});
return t1;
{
Thread t1 = new Thread (delegate () {
using (UnixSignal a = new UnixSignal (Signum.SIGINT)) {
- DateTime start = DateTime.Now;
+ var sw = Stopwatch.StartNew ();
bool r = a.WaitOne (5000, false);
- DateTime end = DateTime.Now;
+ sw.Stop ();
Assert.AreEqual (a.Count, 1);
Assert.AreEqual (r, true);
- if ((end - start) > new TimeSpan (0, 0, 5))
+ if (sw.Elapsed > new TimeSpan (0, 0, 5))
throw new InvalidOperationException ("Signal slept too long");
}
});
{
Thread t1 = new Thread (delegate () {
using (UnixSignal a = new UnixSignal (Signum.SIGINT)) {
- DateTime start = DateTime.Now;
+ var sw = Stopwatch.StartNew ();
int idx = UnixSignal.WaitAny (new UnixSignal[]{a}, 5000);
- DateTime end = DateTime.Now;
+ sw.Stop ();
Assert.AreEqual (idx, 0);
Assert.AreEqual (a.Count, 1);
- if ((end - start) > new TimeSpan (0, 0, 5))
+ if (sw.Elapsed > new TimeSpan (0, 0, 5))
throw new InvalidOperationException ("Signal slept too long");
}
});
Thread t1 = new Thread (delegate () {
using (UnixSignal a = new UnixSignal (Signum.SIGINT))
using (UnixSignal b = new UnixSignal (Signum.SIGTERM)) {
- DateTime start = DateTime.Now;
+ var sw = Stopwatch.StartNew ();
int idx = UnixSignal.WaitAny (new UnixSignal[]{a, b}, 5000);
- DateTime end = DateTime.Now;
+ sw.Stop ();
Assert.AreEqual (idx, 1);
Assert.AreEqual (a.Count, 0);
Assert.AreEqual (b.Count, 1);
- if ((end - start) > new TimeSpan (0, 0, 5))
+ if (sw.Elapsed > new TimeSpan (0, 0, 5))
throw new InvalidOperationException ("Signal slept too long");
}
});
public void TestNoEmit ()
{
using (UnixSignal u = new UnixSignal (Signum.SIGINT)) {
- DateTime start = DateTime.Now;
+ var sw = Stopwatch.StartNew ();
bool r = u.WaitOne (5100, false);
Assert.AreEqual (r, false);
- DateTime end = DateTime.Now;
- if ((end - start) < new TimeSpan (0, 0, 5))
- throw new InvalidOperationException ("Signal didn't block for 5s; blocked for " + (end-start).ToString());
+ sw.Stop ();
+ if (sw.Elapsed < new TimeSpan (0, 0, 5))
+ throw new InvalidOperationException ("Signal didn't block for 5s; blocked for " + sw.Elapsed.TotalSeconds.ToString());
}
}