Skip to content

Commit ffa9943

Browse files
author
Emile Joubert
committed
Improve tests for connection blocked handling
1 parent 8da11f9 commit ffa9943

File tree

1 file changed

+27
-10
lines changed

1 file changed

+27
-10
lines changed

projects/client/Unit/src/unit/TestConnectionBlocked.cs

Lines changed: 27 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -41,15 +41,10 @@
4141
using NUnit.Framework;
4242

4343
using System;
44-
using System.IO;
4544
using System.Text;
46-
using System.Collections;
4745
using System.Threading;
4846
using System.Diagnostics;
4947

50-
using RabbitMQ.Client;
51-
using RabbitMQ.Client.Impl;
52-
using RabbitMQ.Util;
5348
using RabbitMQ.Client.Events;
5449

5550
namespace RabbitMQ.Client.Unit {
@@ -74,7 +69,11 @@ public void TestConnectionBlockedNotification()
7469
if(!notified) {
7570
Monitor.Wait(lockObject, TimeSpan.FromSeconds(8));
7671
}
77-
Assert.IsTrue(notified);
72+
}
73+
if (!notified)
74+
{
75+
Unblock();
76+
Assert.Fail("Unblock notification not received.");
7877
}
7978
}
8079

@@ -88,8 +87,11 @@ public void HandleBlocked(IConnection sender, ConnectionBlockedEventArgs args)
8887

8988
public void HandleUnblocked(IConnection sender)
9089
{
91-
notified = true;
92-
Monitor.PulseAll(lockObject);
90+
lock (lockObject)
91+
{
92+
notified = true;
93+
Monitor.PulseAll(lockObject);
94+
}
9395
}
9496

9597

@@ -123,20 +125,35 @@ protected void ExecCommand(string ctl, string args)
123125
cmd = ctl;
124126
} else {
125127
cmd = "cmd.exe";
126-
args = "/y /c " + ctl + " " + args;
128+
args = "/c " + ctl + " -n rabbit@" + (Environment.GetEnvironmentVariable("COMPUTERNAME")).ToLower() + " " + args;
127129
}
128130

129131
try {
130132
proc.StartInfo.FileName = cmd;
131133
proc.StartInfo.Arguments = args;
134+
proc.StartInfo.RedirectStandardError = true;
135+
proc.StartInfo.RedirectStandardOutput = true;
132136

133137
proc.Start();
138+
String stderr = proc.StandardError.ReadToEnd();
139+
String stdout = proc.StandardOutput.ReadToEnd();
140+
proc.WaitForExit();
141+
if (stderr.Length > 0)
142+
{
143+
ReportExecFailure(cmd, args, stderr + "\n" + stdout);
144+
}
145+
134146
} catch (Exception e) {
135-
Console.WriteLine("Failed to run subprocess with args " + args + " : " + e.Message);
147+
ReportExecFailure(cmd, args, e.Message);
136148
throw e;
137149
}
138150
}
139151

152+
protected void ReportExecFailure(String cmd, String args, String msg)
153+
{
154+
Console.WriteLine("Failure while running " + cmd + " " + args + ":\n" + msg);
155+
}
156+
140157
public static bool IsRunningOnMono()
141158
{
142159
return Type.GetType("Mono.Runtime") != null;

0 commit comments

Comments
 (0)