File: test_idle_connection.rb

package info (click to toggle)
ruby-eventmachine 1.0.3-6%2Bdeb8u1
  • links: PTS, VCS
  • area: main
  • in suites: jessie
  • size: 2,000 kB
  • ctags: 3,178
  • sloc: ruby: 8,641; cpp: 5,217; java: 827; makefile: 5
file content (23 lines) | stat: -rw-r--r-- 578 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
require 'em_test_helper'

class TestIdleConnection < Test::Unit::TestCase
  if EM.respond_to?(:get_idle_time)
    def test_idle_time
      EM.run{
        conn = EM.connect 'www.google.com', 80
        EM.add_timer(3){
          $idle_time = conn.get_idle_time
          conn.send_data "GET / HTTP/1.0\r\n\r\n"
          EM.next_tick{
            $idle_time_after_send = conn.get_idle_time
            conn.close_connection
            EM.stop
          }
        }
      }

      assert_in_delta 3, $idle_time, 0.2
      assert_equal 0, $idle_time_after_send
    end
  end
end