From 2855b7376e543aaed3dcba17107791210dfe178c Mon Sep 17 00:00:00 2001 From: Ricardo Pereira Date: Wed, 17 Feb 2016 14:58:17 +0000 Subject: [PATCH 1/3] RTL10b --- ablySpec/RealtimeClientChannel.swift | 108 +++++++++++++++++++++++++++ 1 file changed, 108 insertions(+) diff --git a/ablySpec/RealtimeClientChannel.swift b/ablySpec/RealtimeClientChannel.swift index 3a1d65ea9..086dfab0d 100644 --- a/ablySpec/RealtimeClientChannel.swift +++ b/ablySpec/RealtimeClientChannel.swift @@ -1217,6 +1217,114 @@ class RealtimeClientChannel: QuickSpec { expect(restChannelHistoryMethodWasCalled).to(beTrue()) } + // RTL10b + context("supports the param untilAttach") { + + it("should be false as default") { + let query = ARTRealtimeHistoryQuery() + expect(query.untilAttach).to(equal(false)) + } + + struct CaseTest { + let untilAttach: Bool + } + + let cases = [CaseTest(untilAttach: true), CaseTest(untilAttach: false)] + + for caseItem in cases { + it("where value is \(caseItem.untilAttach), should pass the querystring param from_serial with the serial number assigned to the channel") { + let client = ARTRealtime(options: AblyTests.commonAppSetup()) + defer { client.close() } + let channel = client.channels.get("test") + + let mockExecutor = MockHTTPExecutor() + client.rest.httpExecutor = mockExecutor + + let query = ARTRealtimeHistoryQuery() + query.untilAttach = caseItem.untilAttach + + expect(channel.state).toEventually(equal(ARTRealtimeChannelState.Attached), timeout: testTimeout) + + waitUntil(timeout: testTimeout) { done in + try! channel.history(query) { _, errorInfo in + expect(errorInfo).to(beNil()) + done() + } + } + + let queryString = mockExecutor.requests.last!.URL!.query + + if query.untilAttach { + expect(queryString).to(contain("from_serial=\(channel.attachSerial)")) + } + else { + expect(queryString).toNot(contain("from_serial")) + } + } + } + + it("should retrieve messages prior to the moment that the channel was attached") { + let options = AblyTests.commonAppSetup() + let client1 = ARTRealtime(options: options) + defer { client1.close() } + + options.autoConnect = false + let client2 = ARTRealtime(options: options) + defer { client2.close() } + + let channel1 = client1.channels.get("test") + channel1.attach() + expect(channel1.state).toEventually(equal(ARTRealtimeChannelState.Attached), timeout: testTimeout) + + var messages = [ARTMessage]() + for i in 0..<20 { + messages.append(ARTMessage(name: nil, data: "message \(i)")) + } + waitUntil(timeout: testTimeout) { done in + channel1.publish(messages) { errorInfo in + expect(errorInfo).to(beNil()) + done() + } + } + + client2.connect() + let channel2 = client1.channels.get("test") + channel2.attach() + expect(channel2.state).toEventually(equal(ARTRealtimeChannelState.Attached), timeout: testTimeout) + + var counter = 20 + channel2.subscribe { message in + expect(message.data as? String).to(equal("message \(counter)")) + counter += 1 + } + + messages = [ARTMessage]() + for i in 20..<40 { + messages.append(ARTMessage(name: nil, data: "message \(i)")) + } + waitUntil(timeout: testTimeout) { done in + channel1.publish(messages) { errorInfo in + expect(errorInfo).to(beNil()) + done() + } + } + + let query = ARTRealtimeHistoryQuery() + query.untilAttach = true + + waitUntil(timeout: testTimeout) { done in + try! channel2.history(query) { result, errorInfo in + expect(result!.items).to(haveCount(20)) + expect(result!.hasNext).to(beFalse()) + expect((result!.items.first! as! ARTMessage).data as? String).to(equal("message 19")) + expect((result!.items.last! as! ARTMessage).data as? String).to(equal("message 0")) + done() + } + } + } + + } + // RTL10c it("should return a PaginatedResult page") { let realtime = ARTRealtime(options: AblyTests.commonAppSetup()) From f88d8c61b6476a293185bbf4a985b0c97a33da4c Mon Sep 17 00:00:00 2001 From: Ricardo Pereira Date: Fri, 19 Feb 2016 12:30:18 +0000 Subject: [PATCH 2/3] RTL10b: pending --- ablySpec/RealtimeClientChannel.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ablySpec/RealtimeClientChannel.swift b/ablySpec/RealtimeClientChannel.swift index 086dfab0d..34a662b55 100644 --- a/ablySpec/RealtimeClientChannel.swift +++ b/ablySpec/RealtimeClientChannel.swift @@ -1218,7 +1218,7 @@ class RealtimeClientChannel: QuickSpec { } // RTL10b - context("supports the param untilAttach") { + pending("supports the param untilAttach") { it("should be false as default") { let query = ARTRealtimeHistoryQuery() From 2ce3622bbcd8cf3e8178233a0859750ebbbcc3d1 Mon Sep 17 00:00:00 2001 From: Ricardo Pereira Date: Tue, 23 Feb 2016 00:00:12 +0000 Subject: [PATCH 3/3] RTL10b: when channel is not attached --- ably-ios/ARTTypes.h | 4 ++++ ablySpec/RealtimeClientChannel.swift | 20 ++++++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/ably-ios/ARTTypes.h b/ably-ios/ARTTypes.h index c9ffc014b..b3bafb86f 100644 --- a/ably-ios/ARTTypes.h +++ b/ably-ios/ARTTypes.h @@ -57,6 +57,10 @@ typedef NS_ENUM(NSInteger, ARTDataQueryError) { ARTDataQueryErrorTimestampRange = 2, }; +typedef NS_ENUM(NSInteger, ARTRealtimeHistoryError) { + ARTRealtimeHistoryErrorNotAttached = ARTDataQueryErrorTimestampRange + 1 +}; + ART_ASSUME_NONNULL_BEGIN /// Decompose API key diff --git a/ablySpec/RealtimeClientChannel.swift b/ablySpec/RealtimeClientChannel.swift index 34a662b55..2f8a0cb09 100644 --- a/ablySpec/RealtimeClientChannel.swift +++ b/ablySpec/RealtimeClientChannel.swift @@ -1225,6 +1225,26 @@ class RealtimeClientChannel: QuickSpec { expect(query.untilAttach).to(equal(false)) } + it("should invoke an error when the untilAttach is specified and the channel is not attached") { + let client = ARTRealtime(options: AblyTests.commonAppSetup()) + defer { client.close() } + let channel = client.channels.get("test") + + let query = ARTRealtimeHistoryQuery() + query.untilAttach = true + + do { + try channel.history(query, callback: { _, _ in }) + } + catch ARTRealtimeHistoryError.NotAttached { + return + } + catch { + fail("Shouldn't raise a global error") + } + fail("Should raise an error") + } + struct CaseTest { let untilAttach: Bool }