Commit Graph

235 Commits

Author SHA1 Message Date
Rafael Mendonça França
1bc9db4a06
Merge pull request #47483 from palkan/fix/channel-test-case-test-server
Fix using TestServer in ConnectionStub
2023-03-03 18:23:21 -05:00
Haroon Ahmed
627322eff4 Add a fake configuration with the ability to override the
subscription_adapter, so we no longer have to use openstruct.
2023-02-23 23:23:19 +00:00
Vladimir Dementyev
8fff6d609c
fix: do not use TestServer in ConnectionStub
It's an internal testing entity, we cannot use it in a test case class
2023-02-23 15:31:58 -05:00
Rafael Mendonça França
177b9494e3
[Action Cable] Stop logging filtered params
Co-Autored-By: Kartikey Tanna <tannakartikey@gmail.com>
2023-02-08 17:22:39 +00:00
Jean Boussier
3d0d027bfd
Merge pull request #47204 from StephaneRob/feat-improve-assert-broadcast-on-message
feat: improve `assert_broadcast_on` error message
2023-02-05 00:24:46 +01:00
StephaneRob
1333260e11 feat: improve assert_broadcast_on error message 2023-02-04 19:48:41 +01:00
Matthew Draper
4b560ab00c Increase redis subscription timeout in Action Cable test 2023-02-04 21:58:17 +10:30
Rafael Mendonça França
847cc9f8cb
Merge pull request #41415 from zedtux/features/actioncable/token
Allows passing sub protocols with ActionCable
2023-01-18 16:37:55 -05:00
Vladimir Dementyev
ae649b152e
feat: restore Action Cable Redis pub/sub listener on connection failure
Closes #27659
2022-11-23 21:53:10 -05:00
Jonathan Hefner
1edc5ea918
Merge pull request #46427 from cpb/cpb-fix-clear-reloadable-connections-deprecation-warning
Fix clear_reloadable_connections! deprecation warning
2022-11-04 18:31:59 -05:00
Caleb Buxton
598e9f36cb Fix clear_reloadable_connections! deprecation warning
This fixes the following warning when running Action Cable tests:

  ```
  DEPRECATION WARNING: Calling `ActiveRecord::Base.clear_reloadable_connections! is deprecated. Please call the method directly on the connection handler; for example: `ActiveRecord::Base.connection_handler.clear_reloadable_connections!`.
  ```
2022-11-04 15:50:48 -07:00
Caleb Buxton
6e9675c6bf Fix clear_all_connections! NoMethodError
This fixes the following error when running Action Cable tests:

  ```
  NoMethodError: undefined method `clear_all_connections!' for #<ActiveRecord::ConnectionAdapters::PostgreSQLAdapter
  actioncable/test/subscription_adapter/postgresql_test.rb:38:in `teardown'
  ```
2022-11-04 15:30:33 -07:00
Jonathan Hefner
25ae059d16 Fix clear_all_connections! deprecation warning
This fixes the following warning when running Action Cable tests:

  ```
  DEPRECATION WARNING: Calling `ActiveRecord::Base.clear_all_connections! is deprecated. Please call the method directly on the connection handler; for example: `ActiveRecord::Base.connection_handler.clear_all_connections!`.
  ```
2022-10-25 15:01:42 -05:00
Guillaume Hain
6edb465bcf
Allows adding more protocols to the WebSocket sub protocols 2022-10-19 09:00:15 +02:00
Jean Boussier
d917896f45 Enable verbose mode in test and report warnings as errors
We recently let a few very easy to avoid warnings get merged.
The root cause is that locally the test suite doesn't run in
verbose mode unless you explictly pass `-w`.

On CI warnings are enabled, but there is no reason to look at the
build output unless something is failing. And even if one wanted
to do that, that would be particularly work intensive since warnings
may be specific to a Ruby version etc.

Because of this I believe we should:

  - Always run the test suite with warnings enabled.
  - Raise an error if a warning is unexpected.

We've been using this pattern for a long time at Shopify both in private
and public repositories.
2022-10-11 09:25:18 +02:00
mansakondo
3a6ab41595 Fix #45738 2022-09-25 14:57:32 +02:00
MSP-Greg
6c674e4425
Updates for Puma 6 2022-09-22 12:40:54 -05:00
mansakondo
27a967ef70 Add ability to handle reconnects with the connected() callback 2022-09-14 12:14:58 +02:00
Jean Boussier
7587b7e99a Action Cable redis-rb 5+ compatibility
- Pass configuration as symbols
- Stop messing with the raw client
2022-08-22 09:01:27 +02:00
Jean Boussier
f2ab66da73 Stop testing hiredis
The driver being used is an implementation detail of `redis-rb`.
If somehow something break on one driver but not the other, it should
be reported to redis-rb and fixed there.

Also `redis-rb` `5.0` has a totally new client and hiredis binding
so all this code no longer works with redis-rb 5.0.
2022-08-22 09:01:27 +02:00
Jeremy Daer
df88a42e5f Merge branch 'main' into feat/ac-remote-disconnect-notice
* main: (21 commits)
  feat: action cable connection callbacks
  fix: action cable stream_test errors
  Adds test coverage for #attach method behaviour in activestorage
  Address QueryCacheTest#test_query_cache_does_not_allow_sql_key_mutation failure
  Fixes ActiveStorage proxy downloads of files over 5mb in S3-like storage services
  Fixes development Action Mailbox new mail form
  Squash commits
  Include the unexpected class in InvalidParameterKey message
  Support unbounded time ranges for PostgreSQL
  Fix CHANGELOG alignment [ci-skip]
  Add ability to ignore tables by regexp for SQL schema dumps
  Improve `rails s` error message when no server could be found.
  Fix MySQL warning when creating Active Record's test databases
  Add `--js` and --skip-javascript` options to `rails new`
  Fix parsing operator classes for index columns in PostgreSQL
  Fix rails test command to handle leading dot slash
  Document that url_for can take classes
  Don't change the encoding of frozen parameters
  Update working_with_javascript_in_rails.md
  Avoid query from calculations on contradictory relation
  ...
2022-05-16 12:40:31 -07:00
Vladimir Dementyev
5d6c1f64ea feat: action cable connection callbacks 2022-05-16 12:24:38 -07:00
Vladimir Dementyev
c5423e9a9c fix: action cable stream_test errors 2022-05-16 12:22:09 -07:00
Vladimir Dementyev
2d0f9c5844 Send disconnect message during remote disconnect
Send {type: :disconnect} message to a client before closing the connection when initiated by server.remote_connections.where(...).disconnect
2022-05-11 13:59:23 -04:00
Xavier Noria
b7ae3cba6d Load with Zeitwerk 2022-03-05 08:19:49 +01:00
Dan Spinosa
6d7c12274e
Client ensures subscribe command is confirmed. (#41581)
A SubscriptionGuarantor maintains a set of pending subscriptions,
resending the subscribe command unless and until the subscription
is confirmed or rejected by the server or cancelled client-side.

A race condition in the ActionCable server - where an unsubscribe
is sent, followed rapidly by a subscribe, but handled in the reverse
order - necessitates this enhancement.  Indeed, the subscriptions created
and torn down by Turbo Streams amplifies the existence of this race
condition.
2021-09-26 10:06:27 -07:00
Rafael França
ddaf3b2cb3
Merge pull request #42574 from leastbad/connection_identifier
add connection_identifier to ConnectionStub
2021-09-23 19:19:07 -04:00
luizkowalski
868a63c695 Update guide and actioncable tests to use appropriate concurrent-ruby class 2021-09-15 17:50:49 +02:00
Xavier Noria
89801b2a43 Depend on ruby/debug, replacing Byebug
ruby/debug is a new debugger that is going to ship with CRuby.

It makes sense for Rails to switch to this one because that is
where the language is heading, and because Byebug is not fully
compatible with Zeitwerk. See

    https://github.com/deivid-rodriguez/byebug/issues/564

While ruby/debug has not been heavily tested with Zeitwerk,
casual usage seems to suggest it works without issues, including
explicit namespaces, which is where Byebug and Zeitwerk conflict.

Byebug is terrific, thanks a lot for all these years. ❤️
2021-09-08 17:35:41 +02:00
Rafael Mendonça França
90868dab14
Allow testing action cable with a different redis port 2021-08-04 18:17:47 -04:00
leastbad
b18e6ba6bd add connection_identifier assertion to ConnectionStub test 2021-06-24 07:53:02 -04:00
Jonathan Hefner
cc9a9e8503 Prevent thundering herd of Action Cable clients
This commit makes a few changes to the Action Cable client to prevent a
"thundering herd" of client reconnects after server connectivity loss:

* The client will wait a random amount between 1x and 3x of the stale
  threshold after the server's last ping before making the first
  reconnection attempt.
* Subsequent reconnection attempts now use exponential backoff instead
  of logarithmic backoff.  To allow the delay between reconnection
  attempts to increase slowly at first, the default exponentiation base
  is < 2.
* Random jitter is applied to each delay between reconnection attempts.

Co-authored-by: John Williams <john@veloshots.com>
2021-02-02 10:43:05 -06:00
Daniel Colson
d092c133c7
Do not allow subscribing to Base channel
Closes #40482

Prior to this commit it was possible to subscribe with
`ActionCable::Channel::Base` as the subscription class. While it doesn't
seem possible to exploit this in away way, it also doesn't seem like
something we need to allow.

This commit swaps [Module#>=][gte] with [Module#>][gt] to prevent
subscribing to a channel when `ActionCable::Channel::Base` is the
subscription class.

[gte]: https://ruby-doc.org/core-2.5.3/Module.html#method-i-3E-3D
[gt]: https://ruby-doc.org/core-2.5.3/Module.html#method-i-3E
2020-11-24 22:30:03 -05:00
Tim Craft
7f41ab2b0e Use indifferent access for config hash in actioncable postgresql test 2020-06-10 13:52:43 +01:00
justin talbott
d2571e560c add rescue_with support to ActionCable::Connection::Base
and update ActionCable guide to describe exception handling usage

# Please enter the commit message for your changes. Lines starting
# with '#' will be ignored, and an empty message aborts the commit.
#
# On branch master
# Your branch is behind 'origin/master' by 5 commits, and can be fast-forwarded.
#
# Changes to be committed:
#	modified:   actioncable/CHANGELOG.md
#	modified:   actioncable/lib/action_cable/connection/base.rb
#	modified:   actioncable/lib/action_cable/connection/subscriptions.rb
#	modified:   actioncable/test/connection/subscriptions_test.rb
#	modified:   guides/source/action_cable_overview.md
#
2020-03-20 14:49:38 -07:00
Atul Bhosale
ec69083cf3
Add method ActionCable::Channel#stream_or_reject_for to stream if record is present, otherwise reject the connection (#38375) 2020-03-07 10:09:08 -08:00
aminamos
7bb0706f2c update from PR #36222 2020-02-12 13:31:43 -05:00
Zhang Kang
96b74fe433 Introduce ActionCable::Channel#stop_stream_from/for to unsubscribe specific streams (#37171)
* Like `ActionCable::Channel#stop_all_streams`, but for specific streams
2020-01-17 13:39:06 -08:00
Sergey Ponomarev
723375147b Add ActionCable subscription connection identificator to PostgreSQL adapter
* You can distinguish connection among others with specific `application_name`

    ```sql
    SELECT application_name FROM pg_stat_activity;
    /*
        application_name
    ------------------------
    psql
    ActionCable-PID-42
    (2 rows)
    */
     ```

  * It's possible to customize connection identification with `id` option in `cable.yml`

    `ActionCable-PID-#{$$}` is the default value

  * Related tests refactoring

  * `ActionCable::Server#config.cable` is no mutated anymore inside Redis subscription adapter
2019-12-31 13:23:01 +03:00
Richard Macklin
fefc304199
Enforce that actioncable compiled JS bundle is in sync with source code
We have run into issues in the past where the actioncable compiled
javascript bundle got out of sync with the source code. For example, in
30a0c7e04093add0b14be6da17c7496e7dd40e10 only the compiled bundle was
modified. This meant that anyone who ran `yarn build` in the actioncable
directory would then see a dirty git status indicating changes to the
compiled bundle, despite not having made any changes to the actioncable
javascript source code. We fixed that particular inconsistency in
a4c27588d5a1e6f270df42b7a305f03a9aee54f2. However, the same problem
could reoccur.

To address this, I've added a new test to enforce that actioncable's
compiled javascript bundle is in sync with the source code. When the
compiled bundle is in sync with the source code, the test will pass:

    $ bundle exec ruby -Itest test/javascript_package_test.rb
    Run options: --seed 19308

    # Running:

    yarn run v1.12.3
    $ yarn lint && bundle exec rake assets:codegen
    $ eslint app/javascript
    $ rollup --config rollup.config.js

    app/javascript/action_cable/index.js → app/assets/javascripts/action_cable.js...
    created app/assets/javascripts/action_cable.js in 762ms
      Done in 6.35s.
    .

    Finished in 7.130345s, 0.1402 runs/s, 0.1402 assertions/s.
    1 runs, 1 assertions, 0 failures, 0 errors, 0 skips

However, if the two are not in sync, the test will fail. For example, if
you were to apply the following patch (which only updates the source
code):

```
diff --git a/actioncable/app/javascript/action_cable/adapters.js b/actioncable/app/javascript/action_cable/adapters.js
index 4de8131438..d38d9a6a0b 100644
--- a/actioncable/app/javascript/action_cable/adapters.js
+++ b/actioncable/app/javascript/action_cable/adapters.js
@@ -1,4 +1,5 @@
 export default {
+  foo: self.foo,
   logger: self.console,
   WebSocket: self.WebSocket
 }
```

the test would then fail like this:

    $ bundle exec ruby -Itest test/javascript_package_test.rb
    Run options: --seed 26377

    # Running:

    yarn run v1.12.3
    $ yarn lint && bundle exec rake assets:codegen
    $ eslint app/javascript
    $ rollup --config rollup.config.js

    app/javascript/action_cable/index.js → app/assets/javascripts/action_cable.js...
    created app/assets/javascripts/action_cable.js in 776ms
      Done in 5.55s.
    F

    Failure:
    JavascriptPackageTest#test_compiled_code_is_in_sync_with_source_code [test/javascript_package_test.rb:16]:
    --- expected
    +++ actual
    @@ -3,6 +3,7 @@
     })(this, function(exports) {
       \"use strict\";
       var adapters = {
    +    foo: self.foo,
         logger: self.console,
         WebSocket: self.WebSocket
       };

    rails test test/javascript_package_test.rb:9

    Finished in 5.837403s, 0.1713 runs/s, 0.1713 assertions/s.
    1 runs, 1 assertions, 1 failures, 0 errors, 0 skips

Thus, the actioncable test suite will now prevent "the compiled bundle
is out of sync" issues going forward.
2019-10-19 02:26:31 +02:00
Akira Matsuda
8cc1bf9e2b Passing in a Hash instance as non-kwargs parameters has to be curly braced 2019-09-07 03:21:45 +09:00
Akira Matsuda
9a15149dab Keyword arguments is not a Hash 2019-09-07 03:20:07 +09:00
Rafael Mendonça França
967beb7229
Revert "MethodCallAssertions is a regular player of the team ActiveSupport::TestCase now"
This reverts commit 98d0f7ebd34b858f12a12dcf37ae54fdbb5cab64.
2019-08-02 00:24:21 -04:00
Akira Matsuda
98d0f7ebd3 MethodCallAssertions is a regular player of the team ActiveSupport::TestCase now
It's used everywhere, clean and mature enough
2019-08-02 05:36:15 +09:00
Akira Matsuda
0196551e60 Use match? where we don't need MatchData 2019-07-29 14:23:10 +09:00
Blake Stoddard
70d64169ae ActionCable: don't allowlist keys passed to the Redis initializer
Support all Redis features without needing to maintain a list of valid options that must stay in sync with the upstream client library.
2019-04-22 09:59:53 -04:00
Fumiaki MATSUSHIMA
61c4be4777 Output junit format test report 2019-04-04 14:34:46 +09:00
rmacklin
d03177ffbc Simplify ActionCable.createWebSocketURL and realphabetize exports (#35810)
* Remove unnecessary variable from ActionCable.createWebSocketURL

* Improve ActionCable test by creating the Consumer before reassigning URL

With this change, the test now actually verifies that the Consumer's url
property changes dynamically (from testURL to `${testURL}foo`).

* Fix alphabetization of ActionCable exports
2019-04-02 23:04:43 +02:00
Ryan Castner
6d488a22d3 feat(js): Dynamic ActionCable URL (#35579)
* Failing test case

* feat: Dynamic Url Generation

Change createWebSocketURL to be a closure that allows url to be evaluated at the time the webSocket is established

* refactor: createWebSocketURL to Consumer, remove need for closure

Move initial call to createWebSocketURL in createConsumer

* docs: Add documentation for dynamic url and string args to createConsumer

Co-Authored-By: rmacklin <rmacklin@users.noreply.github.com>

[Ryan Castner, rmacklin]
2019-03-31 19:41:12 +02:00
Ryan Castner
c7ca85ef31 feat(js): Dynamic Actioncable WebSocket URL
Allow createWebSocketURL fn to accept a function to generate the websocket URL rather than a string.
2019-03-07 22:14:20 -05:00