Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Added a simple test for sending pings & receiving pongs

  • Loading branch information...
commit c584d2dad5694d64f88e93603d7d6fb419332031 1 parent cfb4b40
Martyn Loughran authored
Showing with 30 additions and 2 deletions.
  1. +30 −2 spec/integration/draft13_spec.rb
32 spec/integration/draft13_spec.rb
View
@@ -49,8 +49,8 @@ def start_client
em {
EM.add_timer(0.1) do
EventMachine::WebSocket.start(:host => "0.0.0.0", :port => 12345) { }
-
- # Create a fake client which sends draft 07 handshake
+
+ # Create a fake client which sends draft 13 handshake
connection = EM.connect('0.0.0.0', 12345, Draft07FakeWebSocketClient)
connection.send_data(format_request(@request))
@@ -60,6 +60,34 @@ def start_client
done
}
end
+ # TODO: This test would be much nicer with a real websocket client...
+ it "should support sending pings and binding to onpong" do
+ em {
+ EventMachine::WebSocket.start(:host => "0.0.0.0", :port => 12345) { |ws|
+ ws.onopen {
+ ws.should be_pingable
+ EM.next_tick {
+ ws.ping('hello').should == true
+ }
+
+ }
+ ws.onpong { |data|
+ data.should == 'hello'
+ done
+ }
+ }
+
+ # Create a fake client which sends draft 13 handshake
+ connection = EM.connect('0.0.0.0', 12345, Draft07FakeWebSocketClient)
+ connection.send_data(format_request(@request))
+
+ # Confusing, fake onmessage means any data after the handshake
+ connection.onmessage { |data|
+ # This is what a ping looks like
+ data.should == "\x89\x05hello"
+ # This is what a pong looks like
+ connection.send_data("\x8a\x05hello")
+ }
}
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.