Skip to content

Commit 0ab0d92

Browse files
committed
Extra channel closures have no effect
[#119367885]
1 parent 51b97a6 commit 0ab0d92

File tree

2 files changed

+45
-12
lines changed

2 files changed

+45
-12
lines changed

RMQClient/RMQSuspendResumeDispatcher.m

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ - (void)activateWithChannel:(id<RMQChannel>)channel
4040

4141
- (void)blockingWaitOn:(Class)method {
4242
[self.commandQueue blockingEnqueue:^{
43-
[self handleClosure:^{
43+
[self handleClosure:nil operation:^{
4444
[self.commandQueue suspend];
4545
}];
4646
}];
@@ -56,8 +56,8 @@ - (void)blockingWaitOn:(Class)method {
5656
- (void)sendSyncMethod:(id<RMQMethod>)method
5757
completionHandler:(void (^)(RMQFramesetValidationResult *result))completionHandler {
5858
[self.commandQueue enqueue:^{
59-
[self handleClosure:^{
60-
if ([method isKindOfClass:[RMQChannelClose class]]) {
59+
[self handleClosure:method operation:^{
60+
if ([self isClose:method]) {
6161
self.state = DispatcherStateClosedByClient;
6262
}
6363

@@ -85,7 +85,7 @@ - (void)sendSyncMethod:(id<RMQMethod>)method {
8585

8686
- (void)sendSyncMethodBlocking:(id<RMQMethod>)method {
8787
[self.commandQueue blockingEnqueue:^{
88-
[self handleClosure:^{
88+
[self handleClosure:method operation:^{
8989
RMQFrameset *frameset = [[RMQFrameset alloc] initWithChannelNumber:self.channelNumber method:method];
9090
[self.commandQueue suspend];
9191
[self.sender sendFrameset:frameset];
@@ -94,15 +94,15 @@ - (void)sendSyncMethodBlocking:(id<RMQMethod>)method {
9494

9595
[self.commandQueue blockingEnqueue:^{
9696
RMQFramesetValidationResult *result = [self.validator expect:method.syncResponse];
97-
if (result.error) {
97+
if (self.state == DispatcherStateOpen && result.error) {
9898
[self.delegate channel:self.channel error:result.error];
9999
}
100100
}];
101101
}
102102

103103
- (void)sendAsyncFrameset:(RMQFrameset *)frameset {
104104
[self.commandQueue enqueue:^{
105-
[self handleClosure:^{
105+
[self handleClosure:frameset.method operation:^{
106106
[self.sender sendFrameset:frameset];
107107
}];
108108
}];
@@ -113,7 +113,7 @@ - (void)sendAsyncMethod:(id<RMQMethod>)method {
113113
}
114114

115115
- (void)handleFrameset:(RMQFrameset *)frameset {
116-
if (self.state != DispatcherStateClosedByServer && [frameset.method isKindOfClass:[RMQChannelClose class]]) {
116+
if (self.state != DispatcherStateClosedByServer && [self isClose:frameset.method]) {
117117
self.state = DispatcherStateClosedByServer;
118118
[self.sender sendFrameset:[[RMQFrameset alloc] initWithChannelNumber:self.channelNumber
119119
method:[RMQChannelCloseOk new]]];
@@ -129,11 +129,12 @@ - (NSNumber *)channelNumber {
129129
return self.channel.channelNumber;
130130
}
131131

132-
- (void)handleClosure:(void (^)())operation {
133-
if (self.state != DispatcherStateOpen) {
134-
[self sendChannelClosedError];
135-
} else {
132+
- (void)handleClosure:(id<RMQMethod>)method
133+
operation:(void (^)())operation {
134+
if (self.state == DispatcherStateOpen) {
136135
operation();
136+
} else if (![self isClose:method]) {
137+
[self sendChannelClosedError];
137138
}
138139
}
139140

@@ -144,4 +145,8 @@ - (void)sendChannelClosedError {
144145
[self.delegate channel:self.channel error:error];
145146
}
146147

148+
- (BOOL)isClose:(id<RMQMethod>)method {
149+
return [method isKindOfClass:[RMQChannelClose class]];
150+
}
151+
147152
@end

RMQClientTests/RMQSuspendResumeDispatcherTest.swift

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ class RMQSuspendResumeDispatcherTest: XCTestCase {
7676
func testAsyncFramesetSendsFrameset() {
7777
let (dispatcher, q, sender, _, _) = setupActivated()
7878

79-
let frameset = RMQFrameset(channelNumber: 123, method: MethodFixtures.channelClose())
79+
let frameset = RMQFrameset(channelNumber: 123, method: MethodFixtures.basicAck(1, options: []))
8080
dispatcher.sendAsyncFrameset(frameset)
8181

8282
try! q.step()
@@ -184,6 +184,22 @@ class RMQSuspendResumeDispatcherTest: XCTestCase {
184184
XCTAssertNil(delegate.lastChannelError)
185185
}
186186

187+
func testAdditionalClientClosuresHaveNoEffect() {
188+
let (dispatcher, q, sender, delegate, _) = setupActivated()
189+
190+
dispatcher.sendSyncMethod(MethodFixtures.channelClose())
191+
try! q.step()
192+
dispatcher.handleFrameset(RMQFrameset(channelNumber: 123, method: MethodFixtures.channelCloseOk()))
193+
try! q.step()
194+
195+
sender.lastSentMethod = nil
196+
dispatcher.sendSyncMethodBlocking(MethodFixtures.channelClose())
197+
try! q.step()
198+
199+
XCTAssertNil(delegate.lastChannelError)
200+
XCTAssertNil(sender.lastSentMethod)
201+
}
202+
187203
// MARK: Server close tests
188204

189205
func testServerCloseCausesCloseOkToBeSentInResponse() {
@@ -223,6 +239,18 @@ class RMQSuspendResumeDispatcherTest: XCTestCase {
223239
XCTAssertFalse(q.suspended)
224240
}
225241

242+
func testClientCloseFollowingServerCloseHasNoEffect() {
243+
let (dispatcher, q, sender, delegate, _) = setupActivated()
244+
dispatcher.handleFrameset(RMQFrameset(channelNumber: 123, method: MethodFixtures.channelClose()))
245+
246+
sender.lastSentMethod = nil
247+
dispatcher.sendSyncMethodBlocking(MethodFixtures.channelClose())
248+
try! q.finish()
249+
250+
XCTAssertNil(delegate.lastChannelError)
251+
XCTAssertNil(sender.lastSentMethod)
252+
}
253+
226254
// MARK: Helpers
227255

228256
func setupActivated() -> (dispatcher: RMQSuspendResumeDispatcher, q: FakeSerialQueue, sender: SenderSpy, delegate: ConnectionDelegateSpy, ch: RMQAllocatedChannel) {

0 commit comments

Comments
 (0)