1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00
rails--rails/actioncable/test/connection
Fumiaki MATSUSHIMA 788c908577 Fix unstable test test_delegate_socket_errors_to_on_error_handler
I often face the following error when running test/connection/client_socket_test.rb:

```
$ bin/test test/connection/client_socket_test.rb:38
Run options: --seed 44035

# Running:

F

Failure:
ActionCable::Connection::ClientSocketTest#test_delegate_socket_errors_to_on_error_handler
[/app/actioncable/test/connection/client_socket_test.rb:47]:
--- expected
+++ actual
@@ -1 +1 @@
-["foo"]
+["Broken pipe", "Broken pipe", "Broken pipe", "foo"]
```

It can be reproduced easily by applying the following patch:

```
diff --git a/actioncable/test/connection/client_socket_test.rb b/actioncable/test/connection/client_socket_test.rb
index 2051216010..6bb9f13ea7 100644
--- a/actioncable/test/connection/client_socket_test.rb
+++ b/actioncable/test/connection/client_socket_test.rb
@@ -34,7 +34,8 @@ def on_error(message)
     @server.config.allowed_request_origins = %w( http://rubyonrails.com )
   end

-  test "delegate socket errors to on_error handler" do
+  1000.times do |i|
+  test "delegate socket errors to on_error handler #{i}" do
     run_in_eventmachine do
       connection = open_connection

@@ -47,6 +48,7 @@ def on_error(message)
       assert_equal %w[ foo ], connection.errors
     end
   end
+  end

   test "closes hijacked i/o socket at shutdown" do
     run_in_eventmachine do
```

The cause is writing io from different thread at the same time.

`connection.process` sends handshake message from [StreamEventLoop's thread][] whereas
`connection.handle_open` sends welcome message from current thread.

[StreamEventLoop's thread]: 067fc779c4/actioncable/lib/action_cable/connection/stream_event_loop.rb (L75)
2017-11-23 14:37:06 +09:00
..
authorization_test.rb Use frozen string literal in actioncable/ 2017-07-23 23:30:29 +03:00
base_test.rb Use frozen string literal in actioncable/ 2017-07-23 23:30:29 +03:00
client_socket_test.rb Fix unstable test test_delegate_socket_errors_to_on_error_handler 2017-11-23 14:37:06 +09:00
cross_site_forgery_test.rb Use frozen string literal in actioncable/ 2017-07-23 23:30:29 +03:00
identifier_test.rb Use frozen string literal in actioncable/ 2017-07-23 23:30:29 +03:00
multiple_identifiers_test.rb Remove unused close_connection in Action Cable tests (#30195) 2017-08-11 14:09:53 -04:00
stream_test.rb Use frozen string literal in actioncable/ 2017-07-23 23:30:29 +03:00
string_identifier_test.rb Remove unused close_connection in Action Cable tests (#30195) 2017-08-11 14:09:53 -04:00
subscriptions_test.rb Use frozen string literal in actioncable/ 2017-07-23 23:30:29 +03:00