Sha256: cb9a9d653154a0eede4f4b22f1b80d5b06a8e6624588909a369d6728d7a1015c

Contents?: true

Size: 1.29 KB

Versions: 9

Compression:

Stored size: 1.29 KB

Contents

#!/usr/bin/env ruby
require 'test/unit'

# Unit test for io/tcpclient.rb
require_relative '../../io/tcpfns'
require_relative '../../io/tcpclient'

class TestTCPDbgClient < Test::Unit::TestCase

  include Trepanning::TCPPacking

  def test_basic
    client = Trepan::TCPDbgClient.new({ :open => false,
                                        :port => 1027,
                                        :host => 'localhost'
                                      })
    threads = []
    Thread.new do
      server = TCPServer.new('localhost', 1027)
      session = server.accept
      while 'quit' != (line = session.gets)
        session.puts line 
      end
      session.close
    end
    threads << Thread.new do 
      # require 'trepanning'; debugger
      3.times do 
        begin
          client.open
        rescue IOError
        end
        break
      end
      assert client
      msgs = %w(four five six)
      msgs.each do |mess|
        begin
          break if client.disconnected?
          client.writeline(mess)
          assert_equal mess, client.read_msg.chomp
        rescue EOFError
          puts "Client got EOF"
          break
        rescue Exception => e
          puts "Client got #{e}"
          break
        end
      end
      client.close
    end
    threads.each {|t| t.join }
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
trepanning-2.15.35 test/unit/test-io-tcpclient.rb
trepanning-1.93.35 test/unit/test-io-tcpclient.rb
trepanning-2.15.33 test/unit/test-io-tcpclient.rb
trepanning-1.93.32 test/unit/test-io-tcpclient.rb
trepanning-0.1.6 test/unit/test-io-tcpclient.rb
trepanning-0.1.4 test/unit/test-io-tcpclient.rb
trepanning-0.1.3 test/unit/test-io-tcpclient.rb
trepanning-0.1.2 test/unit/test-io-tcpclient.rb
trepanning-0.1.1 test/unit/test-io-tcpclient.rb