public void single_send_is_thread_safe() { var counts = new CountingUDP(); var test = new Statsd(counts); // send some commands in parallel, `command' just being a number in sequence int sends = 1024, threads = 2; // appears sufficient to surface error most of the time but may vary by machine var sent = new ManualResetEvent[threads]; for (int i = 0; i < threads; i++) { var done = sent[i] = new ManualResetEvent(false); ThreadPool.QueueUserWorkItem(CreateSender(sends, threads, i, test, done)); } // allow threads to complete, cleanup WaitHandle.WaitAll(sent); foreach (IDisposable d in sent) d.Dispose(); counts.ExpectSequence(sends); }
public void single_send_is_thread_safe() { var counts = new CountingUDP(); var test = new Statsd(counts); // send some commands in parallel, `command' just being a number in sequence int sends = 1024, threads = 2; // appears sufficient to surface error most of the time but may vary by machine var sent = new ManualResetEvent[threads]; for (int i = 0; i < threads; i++) { var done = sent[i] = new ManualResetEvent(false); ThreadPool.QueueUserWorkItem(CreateSender(sends, threads, i, test, done)); } // allow threads to complete, cleanup WaitHandle.WaitAll(sent); foreach (IDisposable d in sent) { d.Dispose(); } counts.ExpectSequence(sends); }