File: WaitHandleTest.cs

package info (click to toggle)
mono 6.14.1%2Bds2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,282,732 kB
  • sloc: cs: 11,182,461; xml: 2,850,281; ansic: 699,123; cpp: 122,919; perl: 58,604; javascript: 30,841; asm: 21,845; makefile: 19,602; sh: 10,973; python: 4,772; pascal: 925; sql: 859; sed: 16; php: 1
file content (686 lines) | stat: -rw-r--r-- 18,443 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
//
// WaitHandleTest.cs
//
// Author:
//	Sebastien Pouliot  <sebastien@ximian.com>
//
// Copyright (C) 2009 Novell, Inc (http://www.novell.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
// 
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
// 
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//


using System;
using System.Diagnostics;
using System.Collections.Generic;
using System.Threading;

using NUnit.Framework;

namespace MonoTests.System.Threading {

	[TestFixture]
	public class WaitHandleTest {

		TimeSpan Infinite = new TimeSpan (-10000);	// -10000 ticks == -1 ms
		TimeSpan SmallNegative = new TimeSpan (-2);	// between 0 and -1.0 (infinite) ms
		TimeSpan Negative = new TimeSpan (-20000);	// really negative

		WaitHandle [] TooLarge = new Mutex [65];
		WaitHandle [] Empty = new Mutex [1];
		WaitHandle [] Single = new Mutex [1] { new Mutex (true) };


		[Test]
		[ExpectedException (typeof (ArgumentNullException))]
		public void WaitAny_WaitHandle_Null ()
		{
			WaitHandle.WaitAny (null);
		}

		[Test]
		[ExpectedException (typeof (NotSupportedException))]
		public void WaitAny_WaitHandle_TooLarge ()
		{
			WaitHandle.WaitAny (TooLarge);
		}

		[Test]
		[ExpectedException (typeof (ArgumentNullException))]
		public void WaitAny_WaitHandle_Empty ()
		{
			WaitHandle.WaitAny (Empty);
		}

		[Test]
		public void WaitAny_WaitHandle ()
		{
			Assert.AreEqual (0, WaitHandle.WaitAny (Single), "WaitAny");
		}

		[Test]
		[ExpectedException (typeof (ArgumentNullException))]
		public void WaitAny_WaitHandleNull_Int ()
		{
			WaitHandle.WaitAny (null, -1);
		}

		[Test]
		[ExpectedException (typeof (NotSupportedException))]
		public void WaitAny_WaitHandle_TooLarge_Int ()
		{
			WaitHandle.WaitAny (TooLarge, -1);
		}

		[Test]
		[ExpectedException (typeof (ArgumentNullException))]
		public void WaitAny_WaitHandle_Empty_Int ()
		{
			WaitHandle.WaitAny (Empty, -1);
		}

		[Test]
		public void WaitAny_WaitHandle_Int ()
		{
			// -1 is infinite
			Assert.AreEqual (0, WaitHandle.WaitAny (Single, -1), "WaitAny");
		}

		[Test]
		[ExpectedException (typeof (ArgumentOutOfRangeException))]
		public void WaitAny_WaitHandle_Int_Negative ()
		{
			Assert.AreEqual (0, WaitHandle.WaitAny (Single, -2), "WaitAny");
		}

		[Test]
		[ExpectedException (typeof (ArgumentNullException))]
		public void WaitAny_WaitHandleNull_TimeSpan ()
		{
			WaitHandle.WaitAny (null, Infinite);
		}

		[Test]
		[ExpectedException (typeof (NotSupportedException))]
		public void WaitAny_WaitHandle_TooLarge_TimeSpan ()
		{
			WaitHandle.WaitAny (TooLarge, Infinite);
		}

		[Test]
		[ExpectedException (typeof (ArgumentNullException))]
		public void WaitAny_WaitHandle_Empty_TimeSpan ()
		{
			WaitHandle.WaitAny (Empty, Infinite);
		}

		[Test]
		public void WaitAny_WaitHandle_TimeSpan ()
		{
			Assert.AreEqual (Timeout.Infinite, (int) Infinite.TotalMilliseconds, "Infinite");
			Assert.AreEqual (0, WaitHandle.WaitAny (Single, Infinite), "WaitAny-Infinite");
			Assert.AreEqual (0, WaitHandle.WaitAny (Single, SmallNegative), "WaitAny-SmallNegative");
		}

		[Test]
		[ExpectedException (typeof (ArgumentOutOfRangeException))]
		public void WaitAny_WaitHandle_TimeSpan_Negative ()
		{
			Assert.AreEqual (0, WaitHandle.WaitAny (Single, Negative), "WaitAny");
		}

		[Test]
		[ExpectedException (typeof (ArgumentOutOfRangeException))]
		public void WaitAny_WaitHandle_TimeSpan_MaxValue ()
		{
			Assert.AreEqual (0, WaitHandle.WaitAny (Single, TimeSpan.MaxValue), "WaitAny");
		}


		[Test]
		[ExpectedException (typeof (ArgumentNullException))]
		public void WaitAll_WaitHandle_Null ()
		{
			WaitHandle.WaitAll (null);
		}

		[Test]
		[ExpectedException (typeof (NotSupportedException))]
		public void WaitAll_WaitHandle_TooLarge ()
		{
			WaitHandle.WaitAll (TooLarge);
		}

		[Test]
		[ExpectedException (typeof (ArgumentNullException))]
		public void WaitAll_WaitHandle_Empty ()
		{
			WaitHandle.WaitAll (Empty);
		}

		[Test]
		public void WaitAll_WaitHandle ()
		{
			Assert.IsTrue (WaitHandle.WaitAll (Single), "WaitAll");
		}

		[Test]
		[ExpectedException (typeof (ArgumentNullException))]
		public void WaitAll_WaitHandleNull_Int ()
		{
			WaitHandle.WaitAll (null, -1);
		}

		[Test]
		[ExpectedException (typeof (NotSupportedException))]
		public void WaitAll_WaitHandle_TooLarge_Int ()
		{
			WaitHandle.WaitAll (TooLarge, -1);
		}

		[Test]
		[ExpectedException (typeof (ArgumentNullException))]
		public void WaitAll_WaitHandle_Empty_Int ()
		{
			WaitHandle.WaitAll (Empty, -1);
		}

		[Test]
		public void WaitAll_WaitHandle_Int ()
		{
			// -1 is infinite
			Assert.IsTrue (WaitHandle.WaitAll (Single, -1), "WaitAll");
		}

		[Test]
		[ExpectedException (typeof (ArgumentOutOfRangeException))]
		public void WaitAll_WaitHandle_Int_Negative ()
		{
			Assert.IsTrue (WaitHandle.WaitAll (Single, -2), "WaitAll");
		}

		[Test]
		[ExpectedException (typeof (ArgumentNullException))]
		public void WaitAll_WaitHandleNull_TimeSpan ()
		{
			WaitHandle.WaitAll (null, Infinite);
		}

		[Test]
		[ExpectedException (typeof (NotSupportedException))]
		public void WaitAll_WaitHandle_TooLarge_TimeSpan ()
		{
			WaitHandle.WaitAll (TooLarge, Infinite);
		}

		[Test]
		[ExpectedException (typeof (ArgumentNullException))]
		public void WaitAll_WaitHandle_Empty_TimeSpan ()
		{
			WaitHandle.WaitAll (Empty, Infinite);
		}

		[Test]
		public void WaitAll_WaitHandle_TimeSpan ()
		{
			Assert.AreEqual (Timeout.Infinite, (int) Infinite.TotalMilliseconds, "Infinite");
			Assert.IsTrue (WaitHandle.WaitAll (Single, Infinite), "WaitAll-Infinite");
			Assert.IsTrue (WaitHandle.WaitAll (Single, SmallNegative), "WaitAll-SmallNegative");
		}

		[Test]
		[ExpectedException (typeof (ArgumentOutOfRangeException))]
		public void WaitAll_WaitHandle_TimeSpan_Negative ()
		{
			Assert.IsTrue (WaitHandle.WaitAll (Single, Negative), "WaitAll");
		}

		[Test]
		[ExpectedException (typeof (ArgumentOutOfRangeException))]
		public void WaitAll_WaitHandle_TimeSpan_MaxValue ()
		{
			Assert.IsTrue (WaitHandle.WaitAll (Single, TimeSpan.MaxValue), "WaitAll");
		}


		[Test]
		public void WaitOne ()
		{
			Assert.IsTrue (Single [0].WaitOne (), "WaitOne");
		}

		[Test]
		public void WaitOne_Int ()
		{
			// -1 is infinite
			Assert.IsTrue (Single [0].WaitOne (-1), "WaitOne");
		}

		[Test]
		[ExpectedException (typeof (ArgumentOutOfRangeException))]
		public void WaitOne_Int_Negative ()
		{
			Assert.IsTrue (Single [0].WaitOne (-2), "WaitOne");
		}

		[Test]
		public void WaitOne_TimeSpan ()
		{
			Assert.AreEqual (Timeout.Infinite, (int) Infinite.TotalMilliseconds, "Infinite");
			Assert.IsTrue (Single [0].WaitOne (Infinite), "WaitOne-Infinite");
			Assert.IsTrue (Single [0].WaitOne (SmallNegative), "WaitOne-SmallNegative");
		}

		[Test]
		[ExpectedException (typeof (ArgumentOutOfRangeException))]
		public void WaitOne_TimeSpan_Negative ()
		{
			Assert.IsTrue (Single [0].WaitOne (Negative), "WaitOne");
		}

		[Test]
		[ExpectedException (typeof (ArgumentOutOfRangeException))]
		public void WaitOne_TimeSpan_MaxValue ()
		{
			Assert.IsTrue (Single [0].WaitOne (TimeSpan.MaxValue), "WaitOne");
		}

		[Test]
		[ExpectedException (typeof (ArgumentNullException))]
		public void WaitAll_Empty ()
		{
			WaitHandle.WaitAll (new WaitHandle [0]);
		}

		[Test]
		[ExpectedException (typeof (ArgumentException))]
		public void WaitAny_Empty ()
		{
			WaitHandle.WaitAny (new WaitHandle [0]);
		}

		[Test]
		[Category ("MultiThreaded")]
		public void InterrupedWaitAny ()
		{
			using (var m1 = new Mutex (true)) {
				using (var m2 = new Mutex (true)) {
					using (var done = new ManualResetEvent (false)) {
						var thread = new Thread (() =>
						{
							try {
								WaitHandle.WaitAny (new WaitHandle [] { m1, m2 });
							} catch (ThreadInterruptedException) {
								done.Set ();
							}
						});
						thread.Start ();
						Thread.Sleep (100); // wait a bit so the thread can enter its wait
						thread.Interrupt ();

						Assert.IsTrue (thread.Join (1000), "Join");
						Assert.IsTrue (done.WaitOne (1000), "done");

						m1.ReleaseMutex ();
						m2.ReleaseMutex ();
					}
				}
			}
		}
		
		[Test]
		[Category ("MultiThreaded")]
		public void InterrupedWaitAll ()
		{
			using (var m1 = new Mutex (true)) {
				using (var m2 = new Mutex (true)) {
					using (var done = new ManualResetEvent (false)) {
						var thread = new Thread (() =>
						                         {
							try {
								WaitHandle.WaitAll (new WaitHandle [] { m1, m2 });
							} catch (ThreadInterruptedException) {
								done.Set ();
							}
						});
						thread.Start ();
						Thread.Sleep (100); // wait a bit so the thread can enter its wait
						thread.Interrupt ();

						Assert.IsTrue (thread.Join (1000), "Join");
						Assert.IsTrue (done.WaitOne (1000), "done");

						m1.ReleaseMutex ();
						m2.ReleaseMutex ();
					}
				}
			}
		}
		
		[Test]
		[Category ("MultiThreaded")]
		public void InterrupedWaitOne ()
		{
			using (var m1 = new Mutex (true)) {
				using (var done = new ManualResetEvent (false)) {
					var thread = new Thread (() =>
					                         {
						try {
							m1.WaitOne ();
						} catch (ThreadInterruptedException) {
							done.Set ();
						}
					});
					thread.Start ();
					Thread.Sleep (100); // wait a bit so the thread can enter its wait
					thread.Interrupt ();

					Assert.IsTrue (thread.Join (1000), "Join");
					Assert.IsTrue (done.WaitOne (1000), "done");

					m1.ReleaseMutex ();
				}
			}
		}

		[Test]
		[Category ("MultiThreaded")]
		public void WaitOneWithAbandonedMutex ()
		{
			using (var m = new Mutex (false)) {
				var thread1 = new Thread (() => {
					m.WaitOne ();
				});
				thread1.Start ();
				Assert.IsTrue (thread1.Join (Timeout.Infinite), "thread1.Join");
				try {
					m.WaitOne ();
					Assert.Fail ("Expected AbandonedMutexException");
				} catch (AbandonedMutexException) {
				}
				// Current thread should own the Mutex now
				var signalled = false;
				var thread2 = new Thread (() => {
					signalled = m.WaitOne (100);
				});
				thread2.Start ();
				Assert.IsTrue (thread2.Join (Timeout.Infinite), "thread2.Join");
				Assert.IsFalse (signalled);

				// Since this thread owns the Mutex releasing it shouldn't fail
				m.ReleaseMutex ();
				// The Mutex should now be unowned
				try {
					m.ReleaseMutex ();
					Assert.Fail ("Expected ApplicationException");
				} catch (ApplicationException) {
				}
			}
		}

		[Test]
		[Category ("MultiThreaded")]
		public void WaitOneWithAbandonedMutexAndMultipleThreads ()
		{
			using (var m = new Mutex (true)) {
				var nonAbandoned = 0;
				var abandoned = 0;
				var n = 0;
				var threads = new List<Thread> ();
				for (int i = 0; i < 50; i++) {
					var thread = new Thread (() => {
						try {
							m.WaitOne ();
							nonAbandoned++;
						} catch (AbandonedMutexException) {
							abandoned++;
						}
						if (((n++) % 5) != 0)
							m.ReleaseMutex ();
					});
					thread.Start ();
					threads.Add (thread);
				}
				m.ReleaseMutex ();
				foreach (var thread in threads) {
					if (!thread.Join (1000)) {
						Assert.Fail ("Timed out");
					}
				}
				Assert.AreEqual (40, nonAbandoned);
				Assert.AreEqual (10, abandoned);
			}
		}

		[Test]
		[Category ("MultiThreaded")]
		public void WaitAnyWithSecondMutexAbandoned ()
		{
			using (var m1 = new Mutex (false)) {
				using (var m2 = new Mutex (false)) {
					var mainProceed = false;
					var thread2Proceed = false;
					var thread1 = new Thread (() => {
						m2.WaitOne ();
					});
					var thread2 = new Thread (() => {
						m1.WaitOne ();
						mainProceed = true;
						while (!thread2Proceed) {
							Thread.Sleep (10);
						}
						m1.ReleaseMutex ();
					});
					thread1.Start ();
					Assert.IsTrue (thread1.Join (Timeout.Infinite), "thread1.Join");
					thread2.Start ();
					while (!mainProceed) {
						Thread.Sleep (10);
					}
					try {
						WaitHandle.WaitAny (new WaitHandle [] { m1, m2 });
						Assert.Fail ("Expected AbandonedMutexException");
					} catch (AbandonedMutexException e) {
						Assert.AreEqual (1, e.MutexIndex);
						Assert.AreEqual (m2, e.Mutex);
					} finally {
						thread2Proceed = true;
						Assert.IsTrue (thread2.Join (Timeout.Infinite), "thread2.Join");
					}

					// Current thread should own the second Mutex now
					var signalled = -1;
					var thread3 = new Thread (() => {
						signalled = WaitHandle.WaitAny (new WaitHandle [] { m1, m2 }, 0);
					});
					thread3.Start ();
					Assert.IsTrue (thread3.Join (Timeout.Infinite), "thread3.Join");
					Assert.AreEqual (0, signalled);

					// Since this thread owns the second Mutex releasing it shouldn't fail
					m2.ReleaseMutex ();
					// Second Mutex should now be unowned
					try {
						m2.ReleaseMutex ();
						Assert.Fail ("Expected ApplicationException");
					} catch (ApplicationException) {
					}
					// .NET allows the first Mutex which is now abandoned to be released multiple times by this thread
					m1.ReleaseMutex ();
					m1.ReleaseMutex ();
				}
			}
		}

		[Test]
		[ExpectedException (typeof (AbandonedMutexException))]
		[Category ("MultiThreaded")]
		public void WaitAllWithOneAbandonedMutex ()
		{
			using (var m1 = new Mutex (false)) {
				using (var m2 = new Mutex (false)) {
					var thread = new Thread (() => {
						m1.WaitOne ();
					});
					thread.Start ();
					Assert.IsTrue (thread.Join (Timeout.Infinite), "thread.Join");
					WaitHandle.WaitAll (new WaitHandle [] { m1, m2 });
				}
			}
		}

#if MONO_FEATURE_THREAD_SUSPEND_RESUME
		[Test]
		[Category ("MultiThreaded")]
		public void WaitOneWithTimeoutAndSpuriousWake ()
		{
			/* This is to test that WaitEvent.WaitOne is not going to wait largely
			 * more than its timeout. In this test, it shouldn't wait more than
			 * 1500 milliseconds, with its timeout being 1000ms */

			using (ManualResetEvent mre = new ManualResetEvent (false))
			using (ManualResetEvent ready = new ManualResetEvent (false)) {
				var thread = new Thread (() => {
					ready.Set ();
					mre.WaitOne (1000);
				});

				thread.Start ();
				ready.WaitOne ();

				Thread.Sleep (10); // wait a bit so we enter mre.WaitOne

				var sw = Stopwatch.StartNew ();
				while (sw.ElapsedMilliseconds <= 500) {
					thread.Suspend ();
					thread.Resume ();
				}

				Assert.IsTrue (thread.Join (1000), "#1");
			}
		}

		[Test]
		[Category ("MultiThreaded")]
		public void WaitAnyWithTimeoutAndSpuriousWake ()
		{
			/* This is to test that WaitEvent.WaitAny is not going to wait largely
			 * more than its timeout. In this test, it shouldn't wait more than
			 * 1500 milliseconds, with its timeout being 1000ms */

			using (ManualResetEvent mre1 = new ManualResetEvent (false))
			using (ManualResetEvent mre2 = new ManualResetEvent (false))
			using (ManualResetEvent ready = new ManualResetEvent (false)) {
				var thread = new Thread (() => {
					ready.Set ();
					WaitHandle.WaitAny (new [] { mre1, mre2 }, 1000);
				});

				thread.Start ();
				ready.WaitOne ();

				Thread.Sleep (10); // wait a bit so we enter WaitHandle.WaitAny ({mre1, mre2})

				var sw = Stopwatch.StartNew ();
				while (sw.ElapsedMilliseconds <= 500) {
					thread.Suspend ();
					thread.Resume ();
				}

				Assert.IsTrue (thread.Join (1000), "#1");
			}
		}

		[Test]
		[Category ("MultiThreaded")]
		public void WaitAllWithTimeoutAndSpuriousWake ()
		{
			/* This is to test that WaitEvent.WaitAll is not going to wait largely
			 * more than its timeout. In this test, it shouldn't wait more than
			 * 1500 milliseconds, with its timeout being 1000ms */

			using (ManualResetEvent mre1 = new ManualResetEvent (false))
			using (ManualResetEvent mre2 = new ManualResetEvent (false))
			using (ManualResetEvent ready = new ManualResetEvent (false)) {
				var thread = new Thread (() => {
					ready.Set ();
					WaitHandle.WaitAll (new [] { mre1, mre2 }, 1000);
				});

				thread.Start ();
				ready.WaitOne ();

				Thread.Sleep (10); // wait a bit so we enter WaitHandle.WaitAll ({mre1, mre2})

				var sw = Stopwatch.StartNew ();
				while (sw.ElapsedMilliseconds <= 500) {
					thread.Suspend ();
					thread.Resume ();
				}

				Assert.IsTrue (thread.Join (1000), "#1");
			}
		}
#endif // MONO_FEATURE_THREAD_SUSPEND_RESUME

		[Test]
		public static void SignalAndWait()
		{
			using (var eventToSignal = new AutoResetEvent (false))
			using (var eventToWait = new AutoResetEvent (false))
			{
				eventToWait.Set ();

				Assert.IsTrue (WaitHandle.SignalAndWait (eventToSignal, eventToWait), "#1");
				Assert.IsTrue (eventToSignal.WaitOne (), "#2");
			}
		}

		// https://github.com/mono/mono/issues/9089
		// Duplication is ok for WaitAny, exception for WaitAll.
		// System.DuplicateWaitObjectException: Duplicate objects in argument.
		[Test]
		public static void DuplicateWaitAny ()
		{
			using (var a = new ManualResetEvent (true))
			{
				var b = new ManualResetEvent [ ] { a, a };
				Assert.AreEqual (0, WaitHandle.WaitAny (b), "#1");
			}
		}

		// https://github.com/mono/mono/issues/9089
		// Duplication is ok for WaitAny, exception for WaitAll.
		// System.DuplicateWaitObjectException: Duplicate objects in argument.
		[Test]
		public static void DuplicateWaitAll ()
		{
			using (var a = new ManualResetEvent (true))
			{
				var b = new ManualResetEvent [ ] { a, a };
				try {
					WaitHandle.WaitAll (b);
					Assert.Fail ("Expected System.DuplicateWaitObjectException");
				} catch (DuplicateWaitObjectException) {
				}
			}
		}
	}
}