@@ -40,23 +40,26 @@ namespace RabbitMQ.Client.Unit
40
40
[ TestFixture ]
41
41
public class TestAsyncConsumerExceptions : IntegrationFixture
42
42
{
43
+ private static Exception TestException = new Exception ( "oops" ) ;
44
+
43
45
protected void TestExceptionHandlingWith ( IBasicConsumer consumer ,
44
46
Action < IModel , string , IBasicConsumer , string > action )
45
47
{
46
- object o = new object ( ) ;
48
+ var resetEvent = new AutoResetEvent ( false ) ;
47
49
bool notified = false ;
48
50
string q = _model . QueueDeclare ( ) ;
49
51
50
-
51
52
_model . CallbackException += ( m , evt ) =>
52
53
{
54
+ if ( evt . Exception != TestException ) return ;
55
+
53
56
notified = true ;
54
- Monitor . PulseAll ( o ) ;
57
+ resetEvent . Set ( ) ;
55
58
} ;
56
59
57
60
string tag = _model . BasicConsume ( q , true , consumer ) ;
58
61
action ( _model , q , consumer , tag ) ;
59
- WaitOn ( o ) ;
62
+ resetEvent . WaitOne ( ) ;
60
63
61
64
Assert . IsTrue ( notified ) ;
62
65
}
@@ -122,7 +125,7 @@ public override Task HandleBasicDeliver(string consumerTag,
122
125
IBasicProperties properties ,
123
126
ReadOnlyMemory < byte > body )
124
127
{
125
- return Task . FromException ( new Exception ( "oops" ) ) ;
128
+ return Task . FromException ( TestException ) ;
126
129
}
127
130
}
128
131
@@ -134,7 +137,7 @@ public ConsumerFailingOnCancel(IModel model) : base(model)
134
137
135
138
public override Task HandleBasicCancel ( string consumerTag )
136
139
{
137
- return Task . FromException ( new Exception ( "oops" ) ) ;
140
+ return Task . FromException ( TestException ) ;
138
141
}
139
142
}
140
143
@@ -146,7 +149,7 @@ public ConsumerFailingOnShutdown(IModel model) : base(model)
146
149
147
150
public override Task HandleModelShutdown ( object model , ShutdownEventArgs reason )
148
151
{
149
- return Task . FromException ( new Exception ( "oops" ) ) ;
152
+ return Task . FromException ( TestException ) ;
150
153
}
151
154
}
152
155
@@ -158,7 +161,7 @@ public ConsumerFailingOnConsumeOk(IModel model) : base(model)
158
161
159
162
public override Task HandleBasicConsumeOk ( string consumerTag )
160
163
{
161
- return Task . FromException ( new Exception ( "oops" ) ) ;
164
+ return Task . FromException ( TestException ) ;
162
165
}
163
166
}
164
167
@@ -170,7 +173,7 @@ public ConsumerFailingOnCancelOk(IModel model) : base(model)
170
173
171
174
public override Task HandleBasicCancelOk ( string consumerTag )
172
175
{
173
- return Task . FromException ( new Exception ( "oops" ) ) ;
176
+ return Task . FromException ( TestException ) ;
174
177
}
175
178
}
176
179
}
0 commit comments