-
-
Notifications
You must be signed in to change notification settings - Fork 98
Fix intermittent issues on CI #36
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,16 +2,11 @@ | |
|
|
||
| require "json" | ||
| require "socket" | ||
| require "forwardable" | ||
| require "websocket/driver" | ||
|
|
||
| module Capybara::Cuprite | ||
| class Browser | ||
| class WebSocket | ||
| extend Forwardable | ||
|
|
||
| delegate close: :@driver | ||
|
|
||
| attr_reader :url, :messages | ||
|
|
||
| def initialize(url, logger) | ||
|
|
@@ -22,7 +17,9 @@ def initialize(url, logger) | |
| @driver = ::WebSocket::Driver.client(self) | ||
| @messages = Queue.new | ||
|
|
||
| @driver.on(:open, &method(:on_open)) | ||
| @driver.on(:message, &method(:on_message)) | ||
| @driver.on(:close, &method(:on_close)) | ||
|
|
||
| @thread = Thread.new do | ||
| begin | ||
|
|
@@ -39,10 +36,8 @@ def initialize(url, logger) | |
| @driver.start | ||
| end | ||
|
|
||
| def send_message(data) | ||
| json = data.to_json | ||
| @driver.text(json) | ||
| @logger&.puts("\n\n>>> #{json}") | ||
| def on_open(_event) | ||
| sleep 0.01 # https://github.com/faye/websocket-driver-ruby/issues/46 | ||
| end | ||
|
|
||
| def on_message(event) | ||
|
|
@@ -51,9 +46,24 @@ def on_message(event) | |
| @logger&.puts(" <<< #{event.data}\n") | ||
| end | ||
|
|
||
| def on_close(_event) | ||
| @messages.close | ||
| @thread.kill | ||
| end | ||
|
|
||
| def send_message(data) | ||
| json = data.to_json | ||
| @driver.text(json) | ||
| @logger&.puts("\n\n>>> #{json}") | ||
| end | ||
|
|
||
| def write(data) | ||
| @sock.write(data) | ||
| end | ||
|
|
||
| def close | ||
| @driver.close | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should Socket#close also call
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| end | ||
| end | ||
| end | ||
| end | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've just read that github issue now - would it be possible to loop/sleep here until the state of the socket is not "connecting"? I'm not sure if that is possible, but if it is it might be more reliable, and also it would be easier to understand why the code is sleeping
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe that looping in here will hang the only thread we have and make it even worse but I haven't tried it so I can be wrong. All callbacks get executed in
@threadand if we don't return fromon_openwe may never change state. I don't fully understand how to handle it properly so asked @jcoglan for a perfect solution but he didn't have time to answer yet.