Skip to content

Commit

Permalink
test
Browse files Browse the repository at this point in the history
  • Loading branch information
rsamoilov committed Aug 1, 2024
1 parent 601335c commit 2c56aef
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 19 deletions.
3 changes: 2 additions & 1 deletion spec/integration/integration_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -336,10 +336,11 @@
end
end

sleep 1.5
sleep 2.5

threads.each do |thread|
client = thread.value
puts "[integration spec] #{client.messages}"
expect(client.messages.last).to include("synced from time.com")
end
end
Expand Down
52 changes: 34 additions & 18 deletions spec/support/websocket_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,44 @@ def with_websocket_connection(url, headers: {})

class WebSocketTestClient
def initialize(url, headers: {})
@url = url
@headers = headers
connect
end

def connected?
@ws.handshake.valid? && @ws_data[:connected] && !@ws_data[:closed]
end

def send(data)
2.times do
@ws.send(data)
break
rescue Errno::EBADF
puts "[with_websocket_connection] reconnecting..."
@ws.connect(@url, headers: @headers)
end

sleep 0.1
end

def heartbeats
@ws_data[:heartbeats]
end

def messages
@ws_data[:messages]
end

private

def connect
ws_data = { connected: false, closed: false, heartbeats: [], messages: [] }

@ws = WebSocket::Client::Simple.connect(url, headers:) do |ws|
@ws = WebSocket::Client::Simple.connect(@url, headers: @headers) do |ws|
ws.on :open do
ws_data[:connected] = true
ws_data[:closed] = false
end

ws.on :message do |msg|
Expand All @@ -32,22 +65,5 @@ def initialize(url, headers: {})

sleep 0.1
end

def connected?
@ws.handshake.valid? && @ws_data[:connected] && !@ws_data[:closed]
end

def send(data)
@ws.send(data)
sleep 0.1
end

def heartbeats
@ws_data[:heartbeats]
end

def messages
@ws_data[:messages]
end
end
end

0 comments on commit 2c56aef

Please sign in to comment.