@@ -18,6 +18,7 @@ public record Response;
18
18
19
19
public class PubSubClusterFixture : BaseInMemoryClusterFixture
20
20
{
21
+ private readonly bool _useDefaultTopicRegistration ;
21
22
public const string SubscriberKind = "Subscriber" ;
22
23
public const string TimeoutSubscriberKind = "TimeoutSubscriber" ;
23
24
@@ -28,26 +29,34 @@ public class PubSubClusterFixture : BaseInMemoryClusterFixture
28
29
29
30
public ITestOutputHelper ? Output ;
30
31
31
- public PubSubClusterFixture ( ) : base ( 3 , config =>
32
+ public PubSubClusterFixture ( ) : this ( 3 , false ) { } // xunit requires single, public, parameterless constructor
33
+
34
+ internal PubSubClusterFixture ( int clusterSize , bool useDefaultTopicRegistration ) : base ( clusterSize , config =>
32
35
config
33
36
. WithActorRequestTimeout ( TimeSpan . FromSeconds ( 1 ) )
34
37
. WithPubSubConfig ( PubSubConfig . Setup ( )
35
38
. WithSubscriberTimeout ( TimeSpan . FromSeconds ( 2 ) )
36
39
)
37
- )
38
- {
39
- }
40
+ ) => _useDefaultTopicRegistration = useDefaultTopicRegistration ;
40
41
41
42
private readonly InMemorySubscribersStore _subscribersStore = new ( ) ;
42
43
43
44
public Task < Subscribers > GetSubscribersForTopic ( string topic ) => _subscribersStore . GetAsync ( topic , CancellationToken . None ) ;
44
45
45
- protected override ClusterKind [ ] ClusterKinds => new [ ]
46
- {
47
- new ClusterKind ( TopicActor . Kind , Props . FromProducer ( ( ) => new TopicActor ( _subscribersStore ) ) ) ,
48
- new ClusterKind ( SubscriberKind , SubscriberProps ( ) ) ,
49
- new ClusterKind ( TimeoutSubscriberKind , TimeoutSubscriberProps ( ) )
50
- } ;
46
+ protected override ClusterKind [ ] ClusterKinds {
47
+ get {
48
+ var kinds = new List < ClusterKind >
49
+ {
50
+ new ( SubscriberKind , SubscriberProps ( ) ) ,
51
+ new ( TimeoutSubscriberKind , TimeoutSubscriberProps ( ) )
52
+ } ;
53
+
54
+ if ( ! _useDefaultTopicRegistration )
55
+ kinds . Add ( new ClusterKind ( TopicActor . Kind , Props . FromProducer ( ( ) => new TopicActor ( _subscribersStore ) ) ) ) ;
56
+
57
+ return kinds . ToArray ( ) ;
58
+ }
59
+ }
51
60
52
61
private Props SubscriberProps ( )
53
62
{
@@ -136,29 +145,39 @@ public async Task UnsubscribeAllFrom(string topic, string[] subscriberIds)
136
145
137
146
public async Task SubscribeTo ( string topic , string identity , string kind = PubSubClusterFixture . SubscriberKind )
138
147
{
139
- var subRes = await RandomMember ( ) . Subscribe ( topic , identity , kind ) ;
148
+ var subRes = await RandomMember ( ) . Subscribe ( topic , identity , kind , CancellationTokens . FromSeconds ( 5 ) ) ;
140
149
if ( subRes == null )
141
150
Output ? . WriteLine ( $ "{ kind } /{ identity } failed to subscribe due to timeout") ;
151
+ subRes . Should ( ) . NotBeNull ( "subscribing should not time out" ) ;
142
152
}
143
153
144
154
public async Task UnsubscribeFrom ( string topic , string identity , string kind = PubSubClusterFixture . SubscriberKind )
145
155
{
146
- var unsubRes = await RandomMember ( ) . Unsubscribe ( topic , identity , kind ) ;
156
+ var unsubRes = await RandomMember ( ) . Unsubscribe ( topic , identity , kind , CancellationTokens . FromSeconds ( 5 ) ) ;
147
157
if ( unsubRes == null )
148
158
Output ? . WriteLine ( $ "{ kind } /{ identity } failed to subscribe due to timeout") ;
159
+ unsubRes . Should ( ) . NotBeNull ( "unsubscribing should not time out" ) ;
149
160
}
150
161
151
162
public Task < PublishResponse ? > PublishData ( string topic , int data , CancellationToken cancel = default )
152
- => RandomMember ( )
163
+ {
164
+ if ( cancel == default ) cancel = CancellationTokens . FromSeconds ( 5 ) ;
165
+
166
+ return RandomMember ( )
153
167
. Publisher ( )
154
168
. Publish ( topic , new DataPublished ( data ) , cancel ) ;
169
+ }
155
170
156
171
public Task < PublishResponse ? > PublishDataBatch ( string topic , int [ ] data , CancellationToken cancel = default )
157
- => RandomMember ( )
172
+ {
173
+ if ( cancel == default ) cancel = CancellationTokens . FromSeconds ( 5 ) ;
174
+
175
+ return RandomMember ( )
158
176
. Publisher ( )
159
177
. PublishBatch (
160
178
topic ,
161
179
data . Select ( d => new DataPublished ( d ) ) . ToArray ( ) ,
162
180
cancel
163
181
) ;
182
+ }
164
183
}
0 commit comments