| 1 |
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. See License.txt in the project root for license information. |
| 2 |
|
| 3 |
using System; |
| 4 |
using System.Reactive.Concurrency; |
| 5 |
using System.Reactive.Linq; |
| 6 |
|
| 7 |
namespace ReactiveTests.Stress.Linq |
| 8 |
{ |
| 9 |
public class Delay |
| 10 |
{ |
| 11 |
/// <summary> |
| 12 |
/// Tests OnError messages are propagated all the time. |
| 13 |
/// </summary> |
| 14 |
public static void Errors() |
| 15 |
{ |
| 16 |
while (true) |
| 17 |
{ |
| 18 |
foreach (var N in new[] { 1, 10, 100, 1000, 10000, 100000 }) |
| 19 |
{ |
| 20 |
Console.WriteLine("N = {0}", N); |
| 21 |
foreach (var d in new[] { 1, 10, 20, 50, 100, 200, 250, 500 }) |
| 22 |
{ |
| 23 |
try |
| 24 |
{ |
| 25 |
var ex = new Exception(); |
| 26 |
Observable.Range(0, N, NewThreadScheduler.Default).Concat(Observable.Throw<int>(ex)).Delay(TimeSpan.FromMilliseconds(d), NewThreadScheduler.Default).Count().Wait(); |
| 27 |
} |
| 28 |
catch (Exception) |
| 29 |
{ |
| 30 |
Console.Write("."); |
| 31 |
continue; |
| 32 |
} |
| 33 |
|
| 34 |
throw new InvalidOperationException("Didn't throw!"); |
| 35 |
} |
| 36 |
Console.WriteLine(); |
| 37 |
} |
| 38 |
} |
| 39 |
} |
| 40 |
|
| 41 |
/// <summary> |
| 42 |
/// Tests no OnNext messages are lost. |
| 43 |
/// </summary> |
| 44 |
public static void OnNextMessages() |
| 45 |
{ |
| 46 |
while (true) |
| 47 |
{ |
| 48 |
foreach (var N in new[] { 1, 10, 100, 1000, 10000, 100000 }) |
| 49 |
{ |
| 50 |
Console.WriteLine("N = {0}", N); |
| 51 |
foreach (var d in new[] { 1, 10, 20, 50, 100, 200, 250, 500 }) |
| 52 |
{ |
| 53 |
var n = Observable.Range(0, N, NewThreadScheduler.Default).Delay(TimeSpan.FromMilliseconds(d), NewThreadScheduler.Default).Count().Wait(); |
| 54 |
if (n != N) |
| 55 |
throw new InvalidOperationException("Lost OnNext message!"); |
| 56 |
|
| 57 |
Console.Write("."); |
| 58 |
} |
| 59 |
Console.WriteLine(); |
| 60 |
} |
| 61 |
} |
| 62 |
} |
| 63 |
} |
| 64 |
} |