@@ -40,23 +40,26 @@ namespace RabbitMQ.Client.Unit
4040 [ TestFixture ]
4141 public class TestAsyncConsumerExceptions : IntegrationFixture
4242 {
43+ private static Exception TestException = new Exception ( "oops" ) ;
44+
4345 protected void TestExceptionHandlingWith ( IBasicConsumer consumer ,
4446 Action < IModel , string , IBasicConsumer , string > action )
4547 {
46- object o = new object ( ) ;
48+ var resetEvent = new AutoResetEvent ( false ) ;
4749 bool notified = false ;
4850 string q = _model . QueueDeclare ( ) ;
4951
50-
5152 _model . CallbackException += ( m , evt ) =>
5253 {
54+ if ( evt . Exception != TestException ) return ;
55+
5356 notified = true ;
54- Monitor . PulseAll ( o ) ;
57+ resetEvent . Set ( ) ;
5558 } ;
5659
5760 string tag = _model . BasicConsume ( q , true , consumer ) ;
5861 action ( _model , q , consumer , tag ) ;
59- WaitOn ( o ) ;
62+ resetEvent . WaitOne ( ) ;
6063
6164 Assert . IsTrue ( notified ) ;
6265 }
@@ -122,7 +125,7 @@ public override Task HandleBasicDeliver(string consumerTag,
122125 IBasicProperties properties ,
123126 ReadOnlyMemory < byte > body )
124127 {
125- return Task . FromException ( new Exception ( "oops" ) ) ;
128+ return Task . FromException ( TestException ) ;
126129 }
127130 }
128131
@@ -134,7 +137,7 @@ public ConsumerFailingOnCancel(IModel model) : base(model)
134137
135138 public override Task HandleBasicCancel ( string consumerTag )
136139 {
137- return Task . FromException ( new Exception ( "oops" ) ) ;
140+ return Task . FromException ( TestException ) ;
138141 }
139142 }
140143
@@ -146,7 +149,7 @@ public ConsumerFailingOnShutdown(IModel model) : base(model)
146149
147150 public override Task HandleModelShutdown ( object model , ShutdownEventArgs reason )
148151 {
149- return Task . FromException ( new Exception ( "oops" ) ) ;
152+ return Task . FromException ( TestException ) ;
150153 }
151154 }
152155
@@ -158,7 +161,7 @@ public ConsumerFailingOnConsumeOk(IModel model) : base(model)
158161
159162 public override Task HandleBasicConsumeOk ( string consumerTag )
160163 {
161- return Task . FromException ( new Exception ( "oops" ) ) ;
164+ return Task . FromException ( TestException ) ;
162165 }
163166 }
164167
@@ -170,7 +173,7 @@ public ConsumerFailingOnCancelOk(IModel model) : base(model)
170173
171174 public override Task HandleBasicCancelOk ( string consumerTag )
172175 {
173- return Task . FromException ( new Exception ( "oops" ) ) ;
176+ return Task . FromException ( TestException ) ;
174177 }
175178 }
176179 }
0 commit comments