Debian Codegraph @

external/rx/Rx/NET/Source/Tests.System.Reactive/Stress/Linq/Replay.cs

raw
1 // Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. See License.txt in the project root for license information.
2
3 #if STRESS
4 using System;
5 using System.Collections.Generic;
6 using System.Linq;
7 using System.Text;
8 using System.Reactive.Concurrency;
9 using System.Threading;
10 using System.Reactive.Linq;
11
12 namespace ReactiveTests.Stress.Linq
13 {
14 public class Replay
15 {
16 /// <summary>
17 /// Tests the Replay operator with different schedulers, supporting ISchedulerLongRunning and otherwise.
18 /// Stresses the ScheduledObserver implementation with its counting logic.
19 /// </summary>
20 public static void DifferentSchedulers()
21 {
22 while (true)
23 {
24 for (int i = 100; i <= 10000; i *= 10)
25 {
26 foreach (var s in new IScheduler[] { Scheduler.Default, TaskPoolScheduler.Default, ThreadPoolScheduler.Instance })
27 {
28 foreach (var b in new[] { true, false })
29 {
30 var t = b ? s : s.DisableOptimizations();
31
32 var e = new ManualResetEvent(false);
33 var xs = Observable.Range(0, i, TaskPoolScheduler.Default.DisableOptimizations()).Do(_ => { }, () => e.Set());
34
35 var ys = xs.Replay(t);
36
37 var f = new ManualResetEvent(false);
38 var r = new List<int>();
39 ys.Subscribe(r.Add, () => f.Set());
40
41 ys.Connect();
42
43 e.WaitOne();
44 f.WaitOne();
45
46 if (!r.SequenceEqual(Enumerable.Range(0, i)))
47 throw new Exception();
48
49 Console.Write(".");
50 }
51 }
52 }
53 }
54 }
55 }
56 }
57 #endif