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

Merged Yavor work, refactoring and RSA1 tests #23

Merged
merged 22 commits into from
Oct 8, 2015
Merged

Merged Yavor work, refactoring and RSA1 tests #23

merged 22 commits into from
Oct 8, 2015

Conversation

ricardopereira
Copy link
Contributor

No description provided.

@ricardopereira ricardopereira changed the title [WIP] Realtime tests [WIP] Realtime client tests Sep 28, 2015
@mattheworiordan
Copy link
Member

Thanks for the WIP update.

@ricardopereira
Copy link
Contributor Author

Little update
I was implementing the test for RTC1e(realtimeHost and restHost changes) and I faced some problems:

  1. Weird test results;
  2. No error when the WebSocket tries to connect an invalid host.

tl;dr
⚠️ Important rule for async tests:
We must ensure the test does not finish until the asynchronous call is done and the best solution for those cases is: XCTestExpectation.


I suspected the problem was the asynchronous code. So I created a new project and made some tests.

First test:

describe("quick") {
  it("does it performs well with background work") {
    dispatch_async(dispatch_get_main_queue()) {
        expect(false).to(equal(true))
        NSLog("Done")
    }
  }
}

And my surprise was: Test Case '-[ProjectTests.ProjectTests quick__does_it_performs_well_with_background_work]' passed (0.002 seconds).

I need something in order to block the test from finishing before the async code does

Second test:

describe("async") {
  it("does it performs well with background work") {
    var done = false

    dispatch_async(dispatch_get_main_queue()) {
        expect(false).to(equal(true))
        NSLog("Done")
        done = true
    }

    // Wait until finished
    while !done {
        CFRunLoopRunInMode(kCFRunLoopDefaultMode, CFTimeInterval(0.1), false)
    }
  }
}

Result: [ProjectTests.ProjectTests quick__does_it_performs_well_with_background_work] : failed - expected to equal <true>, got <false>

Success!
Now the test works with asynchronous code but I think using a while loop isn't the best approach.

I investigated more about it and Xcode testing suite has a nice feature for those cases 🙈.
The code:

describe("async") {
  it("does it performs well with background work") {
    let expectation = self.expectationWithDescription("async")

    CFRunLoopPerformBlock(CFRunLoopGetMain(), kCFRunLoopCommonModes) {
        expect(false).to(equal(true))
        NSLog("Done")

        expectation.fulfill()
    }

    self.waitForExpectationsWithTimeout(10.0, handler: nil)
  }
}

Rename the status property to state
Fix the member names of ARTState
Make Channel#history, Presence#history and Presence#get follow the query pattern same as RestClient#stats
There is a lot that can be shared between the Realtime and REST implementations of Channels, Presence and Messages, so this path mostly deals with getting things in place in anticipation of the sweet, sweet code reuse.

In the mean time this adds the `channels` attribute on `ARTRest`, as well as tests for channel creation, publishing and presence.
Move to a new (testable) composable HTTP pipeline
Use NSError instead of ARTErrorInfo
 - Back to Xcode 6 version
 - No warnings
@mattheworiordan
Copy link
Member

@ricardopereira FYI, in Ruby we had similar issues in regards to ensuring the test waits before completion. Fortunately, Ruby is quite flexible, and what I was able to do was wrap our test blocks / closures with an EventMachine block that will wait until the EventMachine reactor (evented system) is explicitly killed, see https://github.com/ably/ably-ruby/blob/master/spec/support/event_machine_helper.rb#L67-L104 if it means anything to you.

I also recently realise that we were not closing connections explicitly automatically at the end of tests, so added ably/ably-ruby@1abbc8c to ensure a connection is closed from one test before the next test starts

@ricardopereira ricardopereira changed the title [WIP] Realtime client tests [WIP] Auth tests Oct 6, 2015
@ricardopereira ricardopereira changed the title [WIP] Auth tests Merged Yavor work, refactoring and RSA1 tests Oct 8, 2015
@ricardopereira
Copy link
Contributor Author

@mattheworiordan merge please.

mattheworiordan added a commit that referenced this pull request Oct 8, 2015
Merged Yavor work, refactoring and RSA1 tests
@mattheworiordan mattheworiordan merged commit 2f08729 into ably:master Oct 8, 2015
@ricardopereira ricardopereira deleted the realtime-tests branch October 16, 2015 08:57
ricardopereira added a commit that referenced this pull request Aug 22, 2019
 - This failed in RTP9a because it sometimes ends but the ACK/NACK of the last sent presence message has not arrived yet, it means the callback is pended. The callback is called when the connection closes (test ends), a "ARTErrorInfo with code 0, message: connection broken before receiving publishing acknowledgment." happens and it will crash because the callback is nil.

EXC_BAD_ACCESS (code=1, address=0x10) in ARTRealtimeChannel.m:335

Thread 3 Queue : io.ably.tests (serial)
#0	0x000000012186c6b4 in __47-[ARTRealtimeChannel publishPresence:callback:]_block_invoke.164 at /<redacted>/ably-cocoa/Source/ARTRealtimeChannel.m:335
#1	0x000000012186ecdd in __43-[ARTRealtimeChannel sendMessage:callback:]_block_invoke at /<redacted>/ably-cocoa/Source/ARTRealtimeChannel.m:450
#2	0x00000001218be38e in __22-[ARTEventEmitter on:]_block_invoke at /<redacted>/ably-cocoa/Source/ARTEventEmitter.m:209
#3	0x00000001083ff632 in -[__NSObserver _doit:] ()
#4	0x00000001094827bc in __CFNOTIFICATIONCENTER_IS_CALLING_OUT_TO_AN_OBSERVER__ ()
#5	0x0000000109481c3f in _CFXRegistrationPost ()
#6	0x0000000109481983 in ___CFXNotificationPost_block_invoke ()
#7	0x00000001095657c2 in -[_CFXNotificationRegistrar find:object:observer:enumerator:] ()
#8	0x00000001094812d1 in _CFXNotificationPost ()
#9	0x00000001083ffddb in -[NSNotificationCenter postNotificationName:object:userInfo:] ()
#10	0x00000001218bf843 in -[ARTEventEmitter emit:with:] at /<redacted>/ably-cocoa/Source/ARTEventEmitter.m:275
#11	0x0000000121915222 in -[ARTRealtime transition:withErrorInfo:] at /<redacted>/ably-cocoa/Source/ARTRealtime.m:429
#12	0x0000000121914c0a in -[ARTRealtime transition:] at /<redacted>/ably-cocoa/Source/ARTRealtime.m:412
#13	0x000000012191b755 in -[ARTRealtime onClosed] at /<redacted>/ably-cocoa/Source/ARTRealtime.m:768
#14	0x0000000121928933 in -[ARTRealtime realtimeTransport:didReceiveMessage:] at /<redacted>/ably-cocoa/Source/ARTRealtime.m:1392
#15	0x00000001218c4bef in -[ARTWebSocketTransport receive:] at /<redacted>/ably-cocoa/Source/ARTWebSocketTransport.m:109
#16	0x00000001218c4cbe in -[ARTWebSocketTransport receiveWithData:] at /<redacted>/ably-cocoa/Source/ARTWebSocketTransport.m:114
#17	0x00000001218c7c44 in -[ARTWebSocketTransport webSocketMessageData:] at /<redacted>/ably-cocoa/Source/ARTWebSocketTransport.m:367
#18	0x00000001218c77a0 in -[ARTWebSocketTransport webSocket:didReceiveMessage:] at /<redacted>/ably-cocoa/Source/ARTWebSocketTransport.m:349
#19	0x0000000121bf06c9 in __43-[SRWebSocket _handleFrameWithData:opCode:]_block_invoke.239 ()
#20	0x000000010b3e2ccf in _dispatch_call_block_and_release ()
#21	0x000000010b3e3d02 in _dispatch_client_callout ()
#22	0x000000010b3ea720 in _dispatch_lane_serial_drain ()
#23	0x000000010b3eb261 in _dispatch_lane_invoke ()
#24	0x000000010b3f3fcb in _dispatch_workloop_worker_thread ()
#25	0x000000010bb12611 in _pthread_wqthread ()
#26	0x000000010bb123fd in start_wqthread ()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants