OSDN Git Service

Replaced mongrel with thin
[redminele/redminele.git] / ruby / lib / ruby / gems / 1.8 / gems / eventmachine-0.12.10-x86-mswin32-60 / tests / test_inactivity_timeout.rb
1 $:.unshift "../lib"
2 require 'eventmachine'
3 require 'test/unit'
4
5 class TestInactivityTimeout < Test::Unit::TestCase
6
7   def test_default
8     $timeout = nil
9     EM.run {
10       c = EM.connect("127.0.0.1", 54321)
11       $timeout = c.comm_inactivity_timeout
12       EM.stop
13     }
14
15     assert_equal(0.0, $timeout)
16   end
17
18   def test_set_and_get
19     $timeout = nil
20     EM.run {
21       c = EM.connect("127.0.0.1", 54321)
22       c.comm_inactivity_timeout = 2.5
23       $timeout = c.comm_inactivity_timeout
24       EM.stop
25     }
26
27     assert_equal(2.5, $timeout)
28   end
29
30   module TimeoutHandler
31     def unbind
32       EM.stop
33     end
34   end
35
36   def test_for_real
37     EM.run {
38       EM.heartbeat_interval = 0.1
39       EM.start_server("127.0.0.1", 12345)
40       EM.add_timer(0.2) {
41         $start = Time.now
42         c = EM.connect("127.0.0.1", 12345, TimeoutHandler)
43         c.comm_inactivity_timeout = 2.5
44       }
45     }
46
47     assert_in_delta(2.5, (Time.now - $start), 0.3)
48   end
49
50 end