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!`.
```
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'
```
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!`.
```
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.
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.
* 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
...
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.
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. ❤️
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>
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
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
#
* 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
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.
* 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
* 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]