-
-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
70 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# frozen_string_literal: true | ||
|
||
class BroadcastsController < ApplicationController | ||
around_action :maybe_disable_auto_batching | ||
|
||
def create | ||
params[:count].to_i.times do |num| | ||
ActionCable.server.broadcast "test", {count: num + 1} | ||
end | ||
|
||
head :created | ||
end | ||
|
||
private | ||
|
||
def maybe_disable_auto_batching(&block) | ||
return yield unless params[:disable_auto_batching] | ||
AnyCable.broadcast_adapter.batching(false, &block) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,4 +2,5 @@ | |
|
||
Rails.application.routes.draw do | ||
resources :sessions, only: [:create] | ||
resources :broadcasts, only: [:create] | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
# frozen_string_literal: true | ||
|
||
require "spec_helper" | ||
require "action_controller/test_case" | ||
|
||
describe "auto-batching", skip: !AnyCable.broadcast_adapter.respond_to?(:start_batching) do | ||
include ActionDispatch::Integration::Runner | ||
include ActionDispatch::IntegrationTest::Behavior | ||
|
||
# Delegates to `Rails.application`. | ||
def app | ||
::Rails.application | ||
end | ||
|
||
before { allow(AnyCable.broadcast_adapter).to receive(:raw_broadcast) } | ||
|
||
it "delivers broadcasts in a single batch" do | ||
post "/broadcasts", params: {count: 3} | ||
expect(AnyCable.broadcast_adapter).to have_received(:raw_broadcast).once | ||
end | ||
|
||
context "when auto_batching disabled" do | ||
it "delivers broadcast individually" do | ||
post "/broadcasts", params: {count: 4, disable_auto_batching: true} | ||
expect(AnyCable.broadcast_adapter).to have_received(:raw_broadcast).exactly(4).times | ||
end | ||
end | ||
end |