Skip to content

Commit c105a17

Browse files
author
petrov-e
committed
make test single thread
1 parent c0510aa commit c105a17

File tree

1 file changed

+19
-15
lines changed

1 file changed

+19
-15
lines changed

projects/Unit/TestFloodPublishing.cs

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
using NUnit.Framework;
4242
using RabbitMQ.Client.Events;
4343
using System;
44-
using System.Collections.Generic;
44+
using System.Diagnostics;
4545
using System.Text;
4646
using System.Threading;
4747
using System.Threading.Tasks;
@@ -89,7 +89,7 @@ public void TestUnthrottledFloodPublishing()
8989
public async Task TestMultithreadFloodPublishing()
9090
{
9191
string message = "test message";
92-
int threadCount = 4;
92+
int threadCount = 1;
9393
int publishCount = 100;
9494
var receivedCount = 0;
9595
byte[] sendBody = Encoding.UTF8.GetBytes(message);
@@ -105,7 +105,13 @@ public async Task TestMultithreadFloodPublishing()
105105
var tcs = new TaskCompletionSource<bool>();
106106
consumer.Received += (o, a) =>
107107
{
108-
Assert.AreEqual(message, Encoding.UTF8.GetString(a.Body.ToArray()));
108+
Console.WriteLine("Receiving");
109+
var receivedMessage = Encoding.UTF8.GetString(a.Body.ToArray());
110+
if (!receivedMessage.Equals(message))
111+
{
112+
Debugger.Break();
113+
}
114+
Assert.AreEqual(message, receivedMessage);
109115

110116
var result = Interlocked.Increment(ref receivedCount);
111117
if (result == threadCount * publishCount)
@@ -115,24 +121,22 @@ public async Task TestMultithreadFloodPublishing()
115121
};
116122

117123
string tag = m.BasicConsume(q.QueueName, true, consumer);
118-
var cts = new CancellationTokenSource(TimeSpan.FromSeconds(5));
119-
120-
124+
var cts = new CancellationTokenSource(TimeSpan.FromSeconds(30));
121125

122126
using (var timeoutRegistration = cts.Token.Register(() => tcs.SetCanceled()))
123127
{
124-
var tasks = new List<Task>();
125-
for (int i = 0; i < threadCount; i++)
126-
{
127-
tasks.Add(Task.Run(() => StartFlood(m, q.QueueName, bp, sendBody, publishCount)));
128-
}
129-
await Task.WhenAll(tasks);
128+
StartFlood(m, q.QueueName, bp, sendBody, publishCount);
129+
130+
//var tasks = new List<Task>();
131+
//for (int i = 0; i < threadCount; i++)
132+
//{
133+
// tasks.Add(Task.Run(() => StartFlood(m, q.QueueName, bp, sendBody, publishCount)));
134+
//}
135+
//await Task.WhenAll(tasks);
130136
await tcs.Task;
131137
}
132138
m.BasicCancel(tag);
133-
134-
135-
139+
await tcs.Task;
136140
Assert.AreEqual(threadCount * publishCount, receivedCount);
137141
}
138142

0 commit comments

Comments
 (0)