Sha256: 694b99a6cef17317c09fbd7373a11267f3e10c7fff86ea4b3be073ffbd03c42d

Contents?: true

Size: 999 Bytes

Versions: 3

Compression:

Stored size: 999 Bytes

Contents

# frozen_string_literal: true

require_relative 'em_test_helper'
require 'em/io_streamer'

# below to stop 'already initialized constant' warning
EM::IOStreamer.__send__ :remove_const, :CHUNK_SIZE
EM::IOStreamer.const_set :CHUNK_SIZE, 2

class TestIOStreamer < Test::Unit::TestCase

  class StreamServer < EM::Connection
    def initialize(sent)
      @sent = sent
    end

    def post_init
      io = StringIO.new @sent
      EM::IOStreamer.new(self, io).callback { close_connection_after_writing }
    end
  end

  class StreamClient < EM::Connection
    def initialize(received)
      @received = received
    end

    def receive_data data
      @received << data
    end

    def unbind
      EM.stop
    end
  end

  def test_io_stream
    sent = 'this is a test'
    received = ''.dup
    EM.run do
      port = next_port
      EM.start_server '127.0.0.1', port, StreamServer, sent
      EM.connect '127.0.0.1', port, StreamClient, received
    end
    assert_equal sent, received
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
wj_eventmachine-1.3.2 tests/test_io_streamer.rb
wj_eventmachine-1.3.1 tests/test_io_streamer.rb
wj_eventmachine-1.3.0.dev.1 tests/test_io_streamer.rb