Skip to content

Commit 8247b41

Browse files
committed
* Consolidate duplicated code.
1 parent 3596df7 commit 8247b41

File tree

1 file changed

+22
-38
lines changed

1 file changed

+22
-38
lines changed

projects/Test/Integration/TestFloodPublishing.cs

+22-38
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,24 @@ public async Task TestUnthrottledFloodPublishing()
104104
string queueName = q.QueueName;
105105

106106
var exceptions = new ConcurrentBag<Exception>();
107+
108+
async Task WaitPublishTasksAsync(ICollection<ValueTask> publishTasks)
109+
{
110+
foreach (ValueTask pt in publishTasks)
111+
{
112+
try
113+
{
114+
await pt;
115+
}
116+
catch (Exception ex)
117+
{
118+
exceptions.Add(ex);
119+
}
120+
}
121+
122+
publishTasks.Clear();
123+
}
124+
107125
var stopwatch = Stopwatch.StartNew();
108126
int publishCount = 0;
109127
try
@@ -118,18 +136,7 @@ public async Task TestUnthrottledFloodPublishing()
118136
{
119137
if (stopwatch.Elapsed > ElapsedMax)
120138
{
121-
foreach (ValueTask pt in publishTasks)
122-
{
123-
try
124-
{
125-
await pt;
126-
}
127-
catch (Exception ex)
128-
{
129-
exceptions.Add(ex);
130-
}
131-
}
132-
publishTasks.Clear();
139+
await WaitPublishTasksAsync(publishTasks);
133140
return;
134141
}
135142

@@ -139,33 +146,11 @@ public async Task TestUnthrottledFloodPublishing()
139146

140147
if (i % 128 == 0)
141148
{
142-
foreach (ValueTask pt in publishTasks)
143-
{
144-
try
145-
{
146-
await pt;
147-
}
148-
catch (Exception ex)
149-
{
150-
exceptions.Add(ex);
151-
}
152-
}
153-
publishTasks.Clear();
149+
await WaitPublishTasksAsync(publishTasks);
154150
}
155151
}
156152

157-
foreach (ValueTask pt in publishTasks)
158-
{
159-
try
160-
{
161-
await pt;
162-
}
163-
catch (Exception ex)
164-
{
165-
exceptions.Add(ex);
166-
}
167-
}
168-
publishTasks.Clear();
153+
await WaitPublishTasksAsync(publishTasks);
169154
}));
170155
}
171156

@@ -178,8 +163,7 @@ public async Task TestUnthrottledFloodPublishing()
178163

179164
Assert.True(_conn.IsOpen);
180165
Assert.False(sawUnexpectedShutdown);
181-
// if (IsVerbose)
182-
if (true)
166+
if (IsVerbose)
183167
{
184168
_output.WriteLine("[INFO] published {0} messages in {1}, exceptions: {2}",
185169
publishCount, stopwatch.Elapsed, exceptions.Count);

0 commit comments

Comments
 (0)