|
31 | 31 |
|
32 | 32 | using System; |
33 | 33 | using System.IO; |
34 | | -using System.Threading; |
35 | 34 | using System.Threading.Tasks; |
36 | 35 | using RabbitMQ.Client; |
37 | 36 | using RabbitMQ.Client.Exceptions; |
@@ -93,48 +92,27 @@ public async Task TestAbortWithSocketClosedOutOfBand() |
93 | 92 | [Fact] |
94 | 93 | public async Task TestDisposedWithSocketClosedOutOfBand() |
95 | 94 | { |
96 | | - await _channel.CloseAsync(); |
97 | | - await _conn.CloseAsync(); |
| 95 | + var tcs = new TaskCompletionSource<bool>(TaskCreationOptions.RunContinuationsAsynchronously); |
| 96 | + |
| 97 | + _channel.ChannelShutdown += (channel, args) => |
| 98 | + { |
| 99 | + _output.WriteLine("_channel.ChannelShutdown called"); |
| 100 | + tcs.SetResult(true); |
| 101 | + }; |
| 102 | + |
| 103 | + var c = (AutorecoveringConnection)_conn; |
| 104 | + Task frameHandlerCloseTask = c.CloseFrameHandlerAsync(); |
| 105 | + |
98 | 106 | try |
99 | 107 | { |
100 | | - // RmqDebug.Verbose(true); |
101 | | - // Console.SetOut(new TestOutputWriter(_output, _testDisplayName)); |
102 | | - var cf = new ConnectionFactory { AutomaticRecoveryEnabled = false }; |
103 | | - _conn = await cf.CreateConnectionAsync(); |
104 | | - _channel = await _conn.CreateChannelAsync(); |
105 | | - |
106 | | - var tcs = new TaskCompletionSource<bool>(TaskCreationOptions.RunContinuationsAsynchronously); |
107 | | - |
108 | | - _channel.ChannelShutdown += (channel, args) => |
109 | | - { |
110 | | - _output.WriteLine("_channel.ChannelShutdown called"); |
111 | | - tcs.SetResult(true); |
112 | | - }; |
113 | | - |
114 | | - // var c = (AutorecoveringConnection)_conn; |
115 | | - // await c.CloseFrameHandlerAsync(); |
116 | | - var c = (Connection)_conn; |
117 | | - await c.FrameHandler.CloseAsync(CancellationToken.None); |
118 | | - |
119 | | - try |
120 | | - { |
121 | | - _conn.Dispose(); |
122 | | - await WaitAsync(tcs, TimeSpan.FromSeconds(60), "channel shutdown"); |
123 | | - } |
124 | | - finally |
125 | | - { |
126 | | - _conn = null; |
127 | | - _channel = null; |
128 | | - } |
| 108 | + _conn.Dispose(); |
| 109 | + await WaitAsync(tcs, WaitSpan, "channel shutdown"); |
| 110 | + await frameHandlerCloseTask.WaitAsync(WaitSpan); |
129 | 111 | } |
130 | 112 | finally |
131 | 113 | { |
132 | | - RmqDebug.Verbose(false); |
133 | | - var standardOutput = new StreamWriter(Console.OpenStandardOutput()) |
134 | | - { |
135 | | - AutoFlush = true |
136 | | - }; |
137 | | - Console.SetOut(standardOutput); |
| 114 | + _conn = null; |
| 115 | + _channel = null; |
138 | 116 | } |
139 | 117 | } |
140 | 118 |
|
|
0 commit comments