Skip to content

Commit 4f16bca

Browse files
committed
Refactors
1 parent 4707f0c commit 4f16bca

File tree

4 files changed

+14
-22
lines changed

4 files changed

+14
-22
lines changed

Tests/Consumer/ConsumerOutcomeTests.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,6 @@ public async Task DiscardedMessageShouldBeDeadLeadLetteredWhenConfigured()
170170
string dlqQueueName = $"dlq_{_queueName}";
171171
await DeclareDeadLetterTopology(_queueName, dlqQueueName);
172172

173-
//this.connection.consumerBuilder().queue(q).messageHandler((ctx, msg) -> ctx.discard()).build();
174173
IConsumerBuilder queueConsumerBuilder = _connection.ConsumerBuilder()
175174
.Queue(_queueName)
176175
.MessageHandler((cxt, msg) =>

Tests/Consumer/ConsumerPauseTests.cs

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -220,16 +220,7 @@ public async Task ConsumerGracefulShutdownExample()
220220

221221
consumer.Pause();
222222

223-
DateTime start = DateTime.Now;
224-
while (consumer.UnsettledMessageCount != 0)
225-
{
226-
await Task.Delay(TimeSpan.FromMilliseconds(100));
227-
DateTime now = DateTime.Now;
228-
if (start - now > _waitSpan)
229-
{
230-
Assert.Fail("consumer.UnsettledMessageCount never reached zero!");
231-
}
232-
}
223+
await WaitUntilStable(() => consumer.UnsettledMessageCount, 0);
233224

234225
await consumer.CloseAsync();
235226
consumer.Dispose();

Tests/Consumer/StreamConsumerTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -506,7 +506,7 @@ Task MessageHandler(IContext cxt, IMessage msg)
506506

507507
using (IConsumer consumer = await consumerBuilder0.BuildAndStartAsync())
508508
{
509-
await WaitUntilStable(() => (int)Interlocked.Read(ref receivedCount));
509+
await WaitUntilStable<long>(() => Interlocked.Read(ref receivedCount));
510510
await consumer.CloseAsync();
511511
}
512512

Tests/IntegrationTest.cs

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -171,49 +171,51 @@ protected Task WhenTaskCompletes(Task task)
171171
return task.WaitAsync(_waitSpan);
172172
}
173173

174-
protected async Task WaitUntilStable(Func<int> getValue, int? stableValue = null)
174+
protected static async Task WaitUntilStable<T>(Func<T> getValue, T? stableValue = default)
175+
where T : IEquatable<T>
175176
{
176177
const int iterations = 20;
177178
int iteration = 0;
178-
int val0 = int.MinValue;
179-
int val1 = int.MaxValue;
179+
T val0;
180+
T val1;
180181
do
181182
{
182183
await Task.Delay(250);
183184
val0 = getValue();
184185
await Task.Delay(250);
185186
val1 = getValue();
186187
iteration++;
187-
if (stableValue is not null && val1 == stableValue)
188+
if (stableValue is not null && val1.Equals(stableValue))
188189
{
189190
break;
190191
}
191-
} while (val0 != val1 && iteration < iterations);
192+
} while (false == val0.Equals(val1) && iteration < iterations);
192193

193194
if (iteration == iterations)
194195
{
195196
Assert.Fail($"value did not stabilize as expected (stableValue: {stableValue})");
196197
}
197198
}
198199

199-
protected async Task WaitUntilStable(Func<Task<int>> getValue, int? stableValue = null)
200+
protected static async Task WaitUntilStable<T>(Func<Task<T>> getValue, T? stableValue = default)
201+
where T : IEquatable<T>
200202
{
201203
const int iterations = 20;
202204
int iteration = 0;
203-
int val0 = int.MinValue;
204-
int val1 = int.MaxValue;
205+
T val0;
206+
T val1;
205207
do
206208
{
207209
await Task.Delay(250);
208210
val0 = await getValue();
209211
await Task.Delay(250);
210212
val1 = await getValue();
211213
iteration++;
212-
if (stableValue is not null && val1 == stableValue)
214+
if (stableValue is not null && val1.Equals(stableValue))
213215
{
214216
break;
215217
}
216-
} while (val0 != val1 && iteration < iterations);
218+
} while (false == val0.Equals(val1) && iteration < iterations);
217219

218220
if (iteration == iterations)
219221
{

0 commit comments

Comments
 (0)