Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add rtl6d1 #802

Merged
merged 3 commits into from
Sep 28, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions Source/ARTProtocolMessage.m
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
// Copyright (c) 2014 Ably. All rights reserved.
//

#import "ARTDefault.h"
#import "ARTProtocolMessage.h"
#import "ARTProtocolMessage+Private.h"
#import "ARTStatus.h"
Expand Down Expand Up @@ -85,6 +86,9 @@ - (BOOL)mergeFrom:(ARTProtocolMessage *)other {
if (![other.channel isEqualToString:self.channel] || other.action != self.action) {
return NO;
}
if ([self mergeWouldExceedMaxSize:self.messages]) {
return NO;
}

switch (self.action) {
case ARTProtocolMessageMessage:
Expand All @@ -98,6 +102,24 @@ - (BOOL)mergeFrom:(ARTProtocolMessage *)other {
}
}

- (BOOL)mergeWouldExceedMaxSize:(NSArray<ARTMessage*>*)messages {
NSInteger queuedMessagesSize = 0;
for (ARTMessage *message in self.messages) {
queuedMessagesSize += [message messageSize];
}
NSInteger messagesSize = 0;
for (ARTMessage *message in messages) {
messagesSize += [message messageSize];
}
NSInteger totalSize = queuedMessagesSize + messagesSize;
NSInteger maxSize = [ARTDefault maxMessageSize];
if (_connectionDetails.maxMessageSize) {
maxSize = _connectionDetails.maxMessageSize;
}
return totalSize > maxSize;
}


- (void)setConnectionSerial:(int64_t)connectionSerial {
_connectionSerial =connectionSerial;
_hasConnectionSerial = true;
Expand Down
31 changes: 31 additions & 0 deletions Spec/RealtimeClientChannel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2057,6 +2057,37 @@ class RealtimeClientChannel: QuickSpec {
}
}
}

// RTL6d1
it("The resulting ProtocolMessage must not exceed the maxMessageSize") {
let options = AblyTests.commonAppSetup()
options.autoConnect = false
let client = AblyTests.newRealtime(options)
defer { client.dispose(); client.close() }
let channel = client.channels.get("test-maxMessageSize")
// This amount of messages would be beyond maxMessageSize, if bundled together
let messagesToBeSent = 1000

// call publish before connecting, so messages are queued
waitUntil(timeout: testTimeout*2) { done in
let partialDone = AblyTests.splitDone(messagesToBeSent, done: done)
for i in 1...messagesToBeSent {
channel.publish("initial initial\(i)", data: "message message\(i)") { error in
expect(error).to(beNil())
partialDone()
}
}
client.connect()
}

let transport = client.transport as! TestProxyTransport
let protocolMessages = transport.protocolMessagesSent.filter{ $0.action == .message }
// verify that messages are not bundled in a single protocol message
expect(protocolMessages.count).to(beGreaterThan(1))
// verify that all the messages have been sent
let messagesSent = protocolMessages.compactMap{$0.messages?.count}.reduce(0, +)
expect(messagesSent).to(equal(messagesToBeSent))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can't detect where the resulting ProtocolMesssage is not exceeding the maxMessageSize. I think you should check if the messages are being blocked if the total size is exceeding the maxMessageSize, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had exactly the same thought at first :)
But this is queued messages, so the iOS client should bundle them in a way that the resulting protocol message does not exceed max size.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh I see 😄 That's why the beGreaterThan(1).

}

// RTL6e
context("Unidentified clients using Basic Auth") {
Expand Down