Sha256: 8305ac9fe85b8e99c1cc973ce61748848b97bb0d0e697538e6c26b8643499dbe

Contents?: true

Size: 1.97 KB

Versions: 2

Compression:

Stored size: 1.97 KB

Contents

require 'spec_helper'

describe Celluloid::IO::UNIXServer do
  let(:example_port) { assign_port }

  describe "#accept" do

    let(:payload) { 'ohai' }

    context "inside Celluloid::IO" do
      it "should be evented" do
        with_unix_server do |subject|
          expect(within_io_actor { Celluloid::IO.evented? }).to be_truthy
        end
      end

      it "accepts a connection and returns a Celluloid::IO::UNIXSocket" do
        pending if RUBY_PLATFORM == 'java'
        with_unix_server do |subject|
          thread = Thread.new { UNIXSocket.new(example_unix_sock) }
          peer = within_io_actor { subject.accept }
          expect(peer).to be_a Celluloid::IO::UNIXSocket

          client = thread.value
          client.write payload
          expect(peer.read(payload.size)).to eq payload
        end
      end

      it "raises if server already up" do
        with_unix_server do |subject|
          within_io_actor do
            expect {
              Celluloid::IO::UNIXServer.open(example_unix_sock)
            }.to raise_error(Errno::EADDRINUSE)
          end
        end
      end

      context "outside Celluloid::IO" do
        it "should be blocking" do
          with_unix_server do |subject|
            expect(Celluloid::IO).not_to be_evented
          end
        end

        it "accepts a connection and returns a Celluloid::IO::UNIXSocket" do
          with_unix_server do |subject|
            thread = Thread.new { UNIXSocket.new(example_unix_sock) }
            peer   = subject.accept
            expect(peer).to be_a Celluloid::IO::UNIXSocket

            client = thread.value
            client.write payload
            expect(peer.read(payload.size)).to eq payload
          end
        end

        it "raises if server already up" do
          with_unix_server do |subject|
            expect {
              Celluloid::IO::UNIXServer.open(example_unix_sock)
            }.to raise_error(Errno::EADDRINUSE)
          end
        end

      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
celluloid-io-0.17.1 spec/celluloid/io/unix_server_spec.rb
celluloid-io-0.17.0 spec/celluloid/io/unix_server_spec.rb