File: reactor_spec.rb

package info (click to toggle)
ruby-celluloid-io 0.16.2-5
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, sid, stretch
  • size: 432 kB
  • ctags: 189
  • sloc: ruby: 1,727; makefile: 6
file content (38 lines) | stat: -rw-r--r-- 914 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
require 'spec_helper'

describe Celluloid::IO::Reactor do
  let(:payload) { "balls" }
  
  it "shouldn't crash" do
    server = ::TCPServer.new example_addr, example_port
    
    thread = Thread.new { server.accept }
    
    socket = within_io_actor { Celluloid::IO::TCPSocket.new example_addr, example_port }
    peer = thread.value
    peer_thread = Thread.new { loop { peer << payload } }
    handle = false
    
    # Main server body:
    within_io_actor do
      begin
        timeout(2) do
          loop do
            socket.readpartial(2046)
          end
        end
      # rescuing timeout, ok. rescuing terminated error, is it ok? TODO: investigate
      rescue Celluloid::Task::TerminatedError, Timeout::Error
      ensure
        socket.readpartial(2046)
        handle = true
      end
    end
    
    expect(handle).to be_truthy
    
    server.close
    peer.close
    socket.close
  end
end