-
Notifications
You must be signed in to change notification settings - Fork 28
/
Copy pathIdentityProcessorVerificationTest.cs
173 lines (136 loc) · 5.88 KB
/
IdentityProcessorVerificationTest.cs
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
using System;
using Xunit;
using Xunit.Abstractions;
using Reactive.Streams.TCK.Tests.Support;
namespace Reactive.Streams.TCK.Tests
{
public class IdentityProcessorVerificationTest : TCKVerificationSupport
{
private static readonly long DefaultTimeoutMilliseconds =
TestEnvironment.EnvironmentDefaultTimeoutMilliseconds();
private static readonly long DefaultNoSignalsTimeoutMilliseconds =
TestEnvironment.EnvironmentDefaultNoSignalsTimeoutMilliseconds();
[SkippableFact]
public void Required_spec104_mustCallOnErrorOnAllItsSubscribersIfItEncountersANonRecoverableError_shouldBeIgnored()
{
RequireTestSkip(() =>
{
new Spec104IgnoreVerification(NewTestEnvironment())
.Required_spec104_mustCallOnErrorOnAllItsSubscribersIfItEncountersANonRecoverableError();
}, "The Publisher under test only supports 1 subscribers, while this test requires at least 2 to run");
}
[TestFixture(Ignore = "Helper verification for single test")]
private sealed class Spec104WaitingVerification : IdentityProcessorVerification<int>
{
/// <summary>
/// We need this constructor for NUnit even if the fixture is ignored
/// </summary>
public Spec104WaitingVerification() : base(new TestEnvironment())
{
}
private sealed class Processor : IProcessor<int, int>
{
private sealed class Subscription : ISubscription
{
private readonly ISubscriber<int> _subscriber;
public Subscription(ISubscriber<int> subscriber)
{
_subscriber = subscriber;
}
public void Request(long n) => _subscriber.OnNext(0);
public void Cancel()
{
}
}
public void OnNext(int element)
{
// noop
}
public void OnSubscribe(ISubscription subscription) => subscription.Request(1);
public void OnError(Exception cause)
{
// noop
}
public void OnComplete()
{
// noop
}
public void Subscribe(ISubscriber<int> subscriber)
=> subscriber.OnSubscribe(new Subscription(subscriber));
}
private sealed class Publisher : IPublisher<int>
{
public void Subscribe(ISubscriber<int> subscriber)
{
subscriber.OnSubscribe(new LamdaSubscription(onRequest: _ =>
{
for (var i = 0; i < 10; i++)
subscriber.OnNext(i);
}));
}
}
public Spec104WaitingVerification(TestEnvironment environment, long publisherReferenceGcTimeoutMillis)
: base(environment, publisherReferenceGcTimeoutMillis)
{
}
public override int CreateElement(int element) => element;
public override IProcessor<int, int> CreateIdentityProcessor(int bufferSize) => new Processor();
public override IPublisher<int> CreateHelperPublisher(long elements) => new Publisher();
public override IPublisher<int> CreateFailedPublisher() => null;
}
[SkippableFact]
public void Required_spec104_mustCallOnErrorOnAllItsSubscribersIfItEncountersANonRecoverableError_shouldFailWhileWaitingForOnError()
{
RequireTestFailure(() =>
{
new Spec104WaitingVerification(NewTestEnvironment(), DefaultTimeoutMilliseconds)
.Required_spec104_mustCallOnErrorOnAllItsSubscribersIfItEncountersANonRecoverableError();
}, "Did not receive expected error on downstream within " + DefaultTimeoutMilliseconds);
}
[TestFixture(Ignore = "Helper verification for single test")]
private sealed class Spec104IgnoreVerification : IdentityProcessorVerification<int>
{
/// <summary>
/// We need this constructor for NUnit even if the fixture is ignored
/// </summary>
public Spec104IgnoreVerification() : base(new TestEnvironment())
{
}
public Spec104IgnoreVerification(TestEnvironment environment) : base(environment)
{
}
public override int CreateElement(int element) => element;
public override IProcessor<int, int> CreateIdentityProcessor(int bufferSize) => new NoopProcessor();
public override IPublisher<int> CreateFailedPublisher() => null;
public override IPublisher<int> CreateHelperPublisher(long elements) => null;
// can only support 1 subscribe => unable to run this test
public override long MaxSupportedSubscribers { get; } = 1;
}
private static TestEnvironment NewTestEnvironment()
=> new TestEnvironment(DefaultTimeoutMilliseconds, DefaultNoSignalsTimeoutMilliseconds);
// FAILING IMPLEMENTATIONS //
private sealed class NoopProcessor : IProcessor<int, int>
{
public void OnNext(int element)
{
// noop
}
public void OnSubscribe(ISubscription subscription)
{
// noop
}
public void OnError(Exception cause)
{
// noop
}
public void OnComplete()
{
// noop
}
public void Subscribe(ISubscriber<int> subscriber)
{
// noop
}
}
}
}