AnyEvent-WebSocket-Client

 view release on metacpan or  search on metacpan

t/anyevent_websocket_connection.t  view on Meta::CPAN

use utf8;
use lib 't/lib';
use Test2::Plugin::EV;
use Test2::Plugin::AnyEvent::Timeout;
use Test2::V0 -no_srand => 1;
use Test2::Tools::WebSocket::Connection qw( create_connection_pair create_connection_and_handle );
use AnyEvent::WebSocket::Connection;

subtest 'send' => sub {

  my($x,$y) = create_connection_pair;

  my $round_trip = sub {

    my($message) = @_;

    my $done = AnyEvent->condvar;

    $y->on(next_message => sub {
      my(undef, $message) = @_;
      $done->send($message);
    });

    $x->send($message);

    $done->recv;

  };

  subtest 'string' => sub {

    is(
      $round_trip->('hello world'),
      object {
        call body => 'hello world';
      },
    );
  };

  require AnyEvent::WebSocket::Message;

  subtest 'message object' => sub {

    is(
      $round_trip->(AnyEvent::WebSocket::Message->new(
        body => 'And another one',
      )),
      object {
        call body => 'And another one';
      },
    );

  };

  subtest 'is_text' => sub {

    is(
      $round_trip->(AnyEvent::WebSocket::Message->new(
        opcode => 1,
        body   => 'xx',
      )),
      object {
        call body => 'xx';
        call is_text => T();

 view all matches for this distribution
 view release on metacpan -  search on metacpan

( run in 0.525 second using v1.00-cache-2.02-grep-82fe00e-cpan-2c419f77a38b )