The data contained in this repository can be downloaded to your computer using one of several clients.
Please see the documentation of your version control software client for more information.

Please select the desired protocol below to get the URL.

This URL has Read-Only access.

Statistics
| Branch: | Revision:

main_repo / deps / libebb / test_examples.rb @ 40c0f755

History | View | Annotate | Download (1.07 KB)

1
require 'test/unit'
2
require 'socket'
3

    
4
REQ = "GET /hello/%d HTTP/1.1\r\n\r\n"
5
HOST = '0.0.0.0'
6
PORT = 5000
7

    
8
class TCPSocket
9
  def full_send(string)
10
    written = 0
11
    while(written < string.length) 
12
      sent = write(string)
13
      string = string.slice(sent, 10000)
14
    end
15
    written
16
  end
17

    
18
  def full_read
19
    response = ""
20
    while chunk = read(10000)
21
      response += chunk
22
    end
23
    response
24
  end
25

    
26
end
27

    
28
class EbbTest < Test::Unit::TestCase
29

    
30
  def setup
31
    @socket = TCPSocket.new(HOST, PORT)
32
  end
33

    
34
  def test_bad_req
35
    @socket.full_send("hello")
36
    assert_equal "", @socket.full_read
37
    #assert @socket.closed?
38
  end
39
  
40
  def test_single
41
    written = 0
42
    req = REQ % 1
43
    @socket.full_send(req)
44
    response = @socket.full_read()
45
    count = 0
46
    response.scan("hello world") { count += 1 }
47

    
48
    assert_equal 1, count
49
  end
50

    
51
  def test_pipeline
52
    written = 0
53
    req = (REQ % 1) + (REQ % 2) + (REQ % 3) + (REQ % 4)
54
    @socket.full_send(req)
55
    response = @socket.full_read()
56
    count = 0
57
    response.scan("hello world") { count += 1 }
58
    assert_equal 4, count
59
  end
60
end