Commit Graph

49 Commits

Author SHA1 Message Date
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
Yasuo Honda
15e37b1fad Address uninitialized constant PostgresqlAdapterTest::ChannelPrefixTest (NameError)
```
$ bundle exec ruby -w -Itest test/subscription_adapter/postgresql_test.rb
Traceback (most recent call last):
	1: from test/subscription_adapter/postgresql_test.rb:8:in `<main>'
test/subscription_adapter/postgresql_test.rb:10:in `<class:PostgresqlAdapterTest>': uninitialized constant PostgresqlAdapterTest::ChannelPrefixTest (NameError)
```

https://travis-ci.org/rails/rails/jobs/493530508

Follow up #35276
2019-02-15 02:10:38 +00:00
Vladimir Dementyev
c43c839847 feat: support channel_prefix in pg subscription adapter 2019-02-14 16:22:03 -08:00
Vladimir Dementyev
3cd69fa2c0
Allow passing custom config to ActionCable::Server::Base
That allows us to create a separate, isolated Action Cable server
instance within the same app.
2019-02-12 17:17:46 -05:00
Matthew Draper
287920ca7d Respect ENV variables when finding DBs etc for the test suite
If they're not set we'll still fall back to localhost, but this makes it
possible to run the tests against a remote Postgres / Redis / whatever.
2019-02-06 01:20:06 +10:30
Ryuta Kamizono
abfc1db01f Fix test case to ensure default connection id is filled
Follow up of #33798.
2018-09-07 04:00:00 +09:00
Ilia Kasianenko
bcd11e07b5 ActionCable: add id option to redis adapter config 2018-09-05 16:54:44 +03:00
Vladimir Dementyev
f7dd2d67d6
Add Action Cable test adapter 2018-08-19 19:06:30 -04:00
Rafael França
9204c0c5fa
Merge pull request #33102 from bogdanvlviv/refactor-actioncable-tests
Refactor actioncable's tests
2018-06-08 18:54:57 -04:00
Rafael Mendonça França
c07c708cf6
Merge pull request #27577 from maclover7/jm-fix-27547
Action Cable owns database connection, not Active Record
2018-06-08 18:21:05 -04:00
bogdanvlviv
74a9a29277
Include ActiveSupport::Testing::MethodCallAssertions to ActionCable::TestCase
Remove all `include ActiveSupport::Testing::MethodCallAssertions`
in actioncable's tests since we can do it only in `ActionCable::TestCase`
in order to prevent code duplication.
We use the same approach for other modules of Rails.
2018-06-08 23:29:05 +03:00
bogdanvlviv
d97f1670bd
Inherit all actioncable's test classes from ActionCable::TestCase
We have defined `ActionCable::TestCase` in `actioncable/test/test_helper.rb`
that we can use in order to prevent code duplication and build common
interface for actioncable's test.
2018-06-08 23:23:06 +03:00
Daniel Colson
94333a4c31 Use assert_predicate and assert_not_predicate 2018-01-25 23:32:59 -05:00
Jeremy Daer
8f2490b57f Action Cable: run Redis tests against a default config without a password
Simplify our dev testing and CI story since we're also testing against
Redis for the Active Support cache store.

Directly test whether db, host, password, etc are passed through as
config instead of spinning up a Redis server with a password set on it.
2017-11-13 01:34:59 -07:00
Rafael Mendonça França
48766e32d3
Removed deprected evented redis adapter 2017-10-23 12:50:45 -04:00
Kir Shatrov
385825fb70 Use frozen string literal in actioncable/ 2017-07-23 23:30:29 +03:00
palkan
be806d8696 Fix postgresql adapter setup for ActionCable tests
(cherry picked from commit e2093c1f678175bde7c37c848686d979427346e1)
(cherry picked from commit d7dbe48273bd9e0adb1de5b52e3cdaeb4a65630b)
2017-07-11 16:38:30 +03:00
palkan
2bce7777b7 [Fix #28751] Hash stream long stream identifiers when using Postgres adapter 2017-07-06 17:34:05 +03:00
Ryuta Kamizono
6aa658e329 Remove redundant assert_respond_to
It is covered by following assertion.
2017-07-03 00:16:53 +09:00
Matthew Draper
87b3e226d6 Revert "Merge pull request #29540 from kirs/rubocop-frozen-string"
This reverts commit 3420a14590c0e6915d8b6c242887f74adb4120f9, reversing
changes made to afb66a5a598ce4ac74ad84b125a5abf046dcf5aa.
2017-07-02 02:15:17 +09:30
Kir Shatrov
cfade1ec7e Enforce frozen string in Rubocop 2017-07-01 02:11:03 +03:00
Marc Ignacio
f55ecc6a7c Allows for other common redis options to be in cable.yml, by default
- Adds RedisAdapterTest::AlternateConfiguration to account
  for a relatively common alternative setup, as it’s used
  as the first example in the
  [Redis rubygem](https://github.com/redis/redis-rb#getting-started)

- Supplies original RedisAdapterTest with more complete
  redis:// url format by adding a ‘userinfo’ (blank user),
  so that it resembles the alternate configuration

- Supplies original EventedRedisAdapterTest with more complete
  redis:// url as well

- Adds before_script to start redis-server with password as a daemon
  and with explicit defaults copied from the default redis.conf
  (Instead of using Travis' default init/upstart scripts for `redis` service)
2017-06-22 16:15:47 +08:00
bogdanvlviv
6673cf7071
Use require_relative instead of require with full path 2017-06-14 12:10:17 +03:00
Jon Moss
686f6a762f Action Cable owns database connection, not Active Record
Before this commit, the database connection used in Action Cable's
PostgreSQL adapter was "owned" by `ActiveRecord::Base.connection_pool`.
This meant that if, for example, `#clear_reloadable_connections!` was called on the pool, Active
Record would "steal" the database connection from Action Cable, and
would cause all sorts of issues. This became evident during file
reloads; despite Action Cable trying its hardest to return its borrowed
database connection to Active Record via `@pubsub.shutdown`, Active Record calls
`#clear_reloadable_connections!` on the connection pool, and due to the order of callbacks, Active
Record's callback was being executed first. This meant that if you tried
to rerender a view after a file was reloaded, you would have to wait
through Active Record's timeout and such.

Now, Action Cable takes direct ownership of the database connection it
uses. It removes the connection from the pool to avoid the situation
described above. Action Cable also makes sure to call `#disconnect!` on
the connection when appropriate, to match the previous behavior of
Active Record.

[ Jon Moss & Matthew Draper]
2017-03-25 12:44:20 -04:00
Matthew Draper
3721b859b6 Deprecate the EventedRedis subscription adapter
Unlike Faye support, it seems a bit too documented to remove without
warning. So, here's a warning.
2017-02-23 10:48:30 +10:30
Chad Ingram
a9c4dcee8d Add channel_prefix support to ActionCable redis/evented_redis adapters. 2017-01-17 23:21:39 -05:00
Matthew Draper
162e889f16 Prevent race condition when launching EventMachine reactor
reactor_running? will be true just after the thread enters
EventMachine.run; reactor_thread only gets set after the internal
initialize_event_machine method has been called, the C extension is set
up, and it is entering its run loop.
2016-11-30 22:55:04 +10:30
Matthew Draper
39fb3069f8 Don't shut down adapters that haven't been set
We hit when we skip the PostgreSQL adapter.
2016-10-04 06:40:38 +10:30
Matthew Draper
a5abc310cd Shut down EventMachine before re-enabling warnings 2016-10-02 12:25:33 +10:30
Matthew Draper
d44177d45e Remove Faye mode
No deprecation, because it was never documented.
2016-10-01 15:35:59 +09:30
Ryuta Kamizono
762e3f05f3 Add Style/EmptyLines in .rubocop.yml and remove extra empty lines 2016-08-07 17:50:59 +09:00
Xavier Noria
f8477f13bf applies new string literal convention in actioncable/test
The current code base is not uniform. After some discussion,
we have chosen to go with double quotes by default.
2016-08-06 19:15:15 +02:00
mmmpa
711d232f93 Add guard to broadcast. 2016-05-26 05:22:56 +09:00
Jeremy Daer
b168eb5819 Cable message encoding
* Introduce a connection coder responsible for encoding Cable messages
  as WebSocket messages, defaulting to `ActiveSupport::JSON` and duck-
  typing to any object responding to `#encode` and `#decode`.
* Consolidate encoding responsibility to the connection. No longer
  explicitly JSON-encode from channels or other sources. Pass Cable
  messages as Hashes to `#transmit` and rely on it to encode.
* Introduce stream encoders responsible for decoding pubsub messages.
  Preserve the currently raw encoding, but make it easy to use JSON.
  Same duck type as the connection encoder.
* Revert recent data normalization/quoting (#23649) which treated
  `identifier` and `data` values as nested JSON objects rather than as
  opaque JSON-encoded strings. That dealt us an awkward hand where we'd
  decode JSON strings… or not, but always encode as JSON. Embedding
  JSON object values directly is preferably, no extra JSON encoding,
  but that should be a purposeful protocol version change rather than
  ambiguously, inadvertently supporting multiple message formats.
2016-03-31 07:08:16 -07:00
Kasper Timm Hansen
dacfdf03d3 Cable: Shush pop warnings when skipping Postgres tests.
`skip` raises an exception to abort the execution of the test, so
`super` would never be called and thus `@rx_adapter` and `@tx_adapter`
would never have been defined at the time of teardown.

Define them just before skipping and zap the warnings.
2016-03-26 21:49:18 +01:00
Kasper Timm Hansen
f6b4bf6593 Shush up EM::Hiredis when running tests.
EM::Hiredis were spewing screenfuls of warnings when running the Action Cable tests.

Copied over the technique that shushes up faye-websocket in the client tests, so
we can reduce the noise ratio.

Note: there's still warnings spewed after tests have finished when EM::Hiredis shuts
down. I haven't been able to shush them up yet.
2016-03-26 21:05:02 +01:00
Jeremy Daer
d448918027 AC: skip PG adapter tests if the db isn't available 2016-03-11 16:32:19 -07:00
Matthew Draper
a373be9da4 Support faye-websocket + EventMachine as an option 2016-03-02 12:17:15 +10:30
Tara Scherner de la Fuente
926a24a751 remove args from assert_nothing_raised in tests 2016-02-22 22:56:23 -08:00
Kasper Timm Hansen
3ae8eb13cb Don't rely on the global server as a receiver.
The `WorkerTest`'s `Receiver` is imporsonating an `ActionCable::Connection::Base`, but
just delegates the logger to `ActionCable.logger`.

This creates a mismatch as the connection requires the logger to be a
`TaggedLoggerProxy`'ied logger, while the server doesn't.

Thus to ensure an exception isn't raised when the worker tries to call `tag`
other tests have to assign a proxied logger to their test server.

Instead of forcing change on other tests, have Receiver adhere to the connection
contract and use a `TaggedLoggerProxy`.

As a consequence remove more setup from the tests.
2016-02-14 17:46:48 +01:00
Kasper Timm Hansen
861ece99bb Default connection class to ActionCable::Connection::Base.
Instead of depending on ApplicationCable::Connection being defined at initialize
we should inject it in the Railtie.

Thus we can kill more setup in the tests too.
2016-02-14 17:46:48 +01:00
Kasper Timm Hansen
661298176c Inject Rails' channel paths in engine.
We were explicitly referencing Rails.root in ActionCable::Server::Configuration.initialize,
thereby coupling ourselves to Rails.

Instead add `app/channels` to Rails' app paths and assign the existent files
to `channel_paths`.

Users can still append to those load paths with `<<` and `push` in `config/application.rb`.

This means we can remove the custom `Dir` lookup in `channel_paths` and the Rails
and root definitions in the tests.
2016-02-14 17:46:48 +01:00
Matthew Draper
e77368637e Switch the default redis adapter to a single-stream model
This new adapter does get a little more intimate with the redis-rb gem's
implementation than I would like, but it's the least bad of the
approaches I've come up with.
2016-02-01 01:56:47 +10:30
Matthew Draper
74497eabd5 Revert "Revert "Eliminate the EventMachine dependency"" 2016-01-30 03:46:37 +10:30
David Heinemeier Hansson
9ea7aa84d1 Revert "Eliminate the EventMachine dependency" 2016-01-27 14:33:15 +01:00
Matthew Draper
503fe757c7 Ditch the EM error logging helper
We're no longer doing our work in the EM event loop, so errors are quite
unlikely, and if they do occur, they're not really our responsibility to
handle.
2016-01-24 22:54:04 +10:30
Matthew Draper
68a9060d02 Using a hacked faye-websocket, drop EventMachine 2016-01-24 22:51:06 +10:30
Matthew Draper
9ff28c10eb Add tests for the ActionCable adapters 2016-01-24 21:13:40 +10:30
Jon Moss
4c5d5b75ab ActionCable::StorageAdapter ==> ActionCable::SubscriptionAdapter 2016-01-18 18:59:30 -05:00