github.com/anycable/anycable-go@v1.5.1/etc/anyt/broadcast_tests/whisper_test.rb (about)

     1  # frozen_string_literal: true
     2  
     3  feature "Whisper" do
     4    channel do
     5      def subscribed
     6        stream_from "a", whisper: true
     7      end
     8    end
     9  
    10    let(:client2) { build_client(ignore: %w[ping welcome]) }
    11    let(:client3) { build_client(ignore: %w[ping welcome]) }
    12  
    13    before do
    14      subscribe_request = {command: "subscribe", identifier: {channel: channel}.to_json}
    15  
    16      client.send(subscribe_request)
    17      client2.send(subscribe_request)
    18      client3.send(subscribe_request)
    19  
    20      ack = {
    21        "identifier" => {channel: channel}.to_json, "type" => "confirm_subscription"
    22      }
    23  
    24      assert_message ack, client.receive
    25      assert_message ack, client2.receive
    26      assert_message ack, client3.receive
    27    end
    28  
    29    scenario %(
    30      Only other clients receive the whisper message
    31    ) do
    32      perform_request = {
    33        :command => "whisper",
    34        :identifier => {channel: channel}.to_json,
    35        "data" => {"event" => "typing", "user" => "Vova"}
    36      }
    37  
    38      client.send(perform_request)
    39  
    40      msg = {"identifier" => {channel: channel}.to_json, "message" => {"event" => "typing", "user" => "Vova"}}
    41  
    42      assert_message msg, client2.receive
    43      assert_message msg, client3.receive
    44      assert_raises(Anyt::Client::TimeoutError) do
    45        msg = client.receive(timeout: 0.5)
    46        raise "Client 1 should not receive the message: #{msg}"
    47      end
    48    end
    49  end