Skip to content

Commit

Permalink
Added a functional spec that reproduces issue #26.
Browse files Browse the repository at this point in the history
  • Loading branch information
lukeredpath committed Feb 29, 2012
1 parent 0f8de83 commit 7e4a8f5
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 1 deletion.
50 changes: 49 additions & 1 deletion Functional Specs/PrivateChannelsSpec.m
Expand Up @@ -72,7 +72,55 @@
});

[[expectFutureValue(theValue(failedToSubscribe)) shouldEventuallyBeforeTimingOutAfter(3)] beYes];
});
});
});

describe(@"Subscribing to multiple private channels with delays (see issue #26)", ^{

__block PTPusher *client = nil;

registerMatchers(@"PT");
enableClientDebugging();

beforeAll(^{
client = newTestClient();

// this requires the auth server to be running (rake authserver:start)
client.authorizationURL = [NSURL URLWithString:@"http://localhost:9292/private/slowauth"];
});

afterAll(^{
[client disconnect];
waitForClientToDisconnect(client);
});

it(@"should be successful", ^{
onAuthorizationRequired(^(NSMutableURLRequest *authRequest) {
NSLog(@"AUTHORIZING REQUEST");
[authRequest setHTTPBasicAuthUsername:@"admin" password:@"letmein"];
});

NSInteger numberToConnect = 5;

onConnect(^{
for (int i = 0; i < numberToConnect; i++) {
[client subscribeToPrivateChannelNamed:[NSString stringWithFormat:@"secret-channel-%d", i]];
}
});

__block NSInteger numberOfSubscribedChannels = 0;
__block BOOL allSubscribed = NO;

onSubscribe(^(PTPusherChannel *subscribedChannel) {
numberOfSubscribedChannels++;

if (numberOfSubscribedChannels == numberToConnect) {
allSubscribed = YES;
}
});

[[expectFutureValue(theValue(allSubscribed)) shouldEventuallyBeforeTimingOutAfter(10)] beYes];
});
});

SPEC_END
7 changes: 7 additions & 0 deletions Scripts/auth_server.rb
Expand Up @@ -41,6 +41,13 @@ class FakeAuthServer < Sinatra::Base
[200, {"Content-Type" => "application/json"}, response.to_json]
end

post "/private/slowauth" do
puts ">> Authenticating private channel:#{params[:channel_name]} socket:#{params[:socket_id]}"
response = Pusher[params[:channel_name]].authenticate(params[:socket_id])
sleep(1)
[200, {"Content-Type" => "application/json"}, response.to_json]
end

post "/presence/auth" do
puts ">> Authenticating presence channel:#{params[:channel_name]} socket:#{params[:socket_id]}"

Expand Down

0 comments on commit 7e4a8f5

Please sign in to comment.