41
41
using NUnit . Framework ;
42
42
43
43
using System ;
44
- using System . IO ;
45
44
using System . Text ;
46
- using System . Collections ;
47
45
using System . Threading ;
48
46
using System . Diagnostics ;
49
47
50
- using RabbitMQ . Client ;
51
- using RabbitMQ . Client . Impl ;
52
- using RabbitMQ . Util ;
53
48
using RabbitMQ . Client . Events ;
54
49
55
50
namespace RabbitMQ . Client . Unit {
@@ -74,7 +69,11 @@ public void TestConnectionBlockedNotification()
74
69
if ( ! notified ) {
75
70
Monitor . Wait ( lockObject , TimeSpan . FromSeconds ( 8 ) ) ;
76
71
}
77
- Assert . IsTrue ( notified ) ;
72
+ }
73
+ if ( ! notified )
74
+ {
75
+ Unblock ( ) ;
76
+ Assert . Fail ( "Unblock notification not received." ) ;
78
77
}
79
78
}
80
79
@@ -88,8 +87,11 @@ public void HandleBlocked(IConnection sender, ConnectionBlockedEventArgs args)
88
87
89
88
public void HandleUnblocked ( IConnection sender )
90
89
{
91
- notified = true ;
92
- Monitor . PulseAll ( lockObject ) ;
90
+ lock ( lockObject )
91
+ {
92
+ notified = true ;
93
+ Monitor . PulseAll ( lockObject ) ;
94
+ }
93
95
}
94
96
95
97
@@ -123,20 +125,35 @@ protected void ExecCommand(string ctl, string args)
123
125
cmd = ctl ;
124
126
} else {
125
127
cmd = "cmd.exe" ;
126
- args = "/y / c " + ctl + " " + args ;
128
+ args = "/c " + ctl + " -n rabbit@" + ( Environment . GetEnvironmentVariable ( "COMPUTERNAME" ) ) . ToLower ( ) + " " + args ;
127
129
}
128
130
129
131
try {
130
132
proc . StartInfo . FileName = cmd ;
131
133
proc . StartInfo . Arguments = args ;
134
+ proc . StartInfo . RedirectStandardError = true ;
135
+ proc . StartInfo . RedirectStandardOutput = true ;
132
136
133
137
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
+
134
146
} catch ( Exception e ) {
135
- Console . WriteLine ( "Failed to run subprocess with args " + args + " : " + e . Message ) ;
147
+ ReportExecFailure ( cmd , args , e . Message ) ;
136
148
throw e ;
137
149
}
138
150
}
139
151
152
+ protected void ReportExecFailure ( String cmd , String args , String msg )
153
+ {
154
+ Console . WriteLine ( "Failure while running " + cmd + " " + args + ":\n " + msg ) ;
155
+ }
156
+
140
157
public static bool IsRunningOnMono ( )
141
158
{
142
159
return Type . GetType ( "Mono.Runtime" ) != null ;
0 commit comments