summaryrefslogtreecommitdiff
path: root/vendor/bundle/ruby/3.4.0/gems/eventmachine-1.2.7/tests/test_idle_connection.rb
blob: bfc57cd99fb12118257d99e401c5b9f3432d9f81 (plain)
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
require 'em_test_helper'

class TestIdleConnection < Test::Unit::TestCase
  def setup
    @port = next_port
  end

  def test_idle_time
    omit_if(!EM.respond_to?(:get_idle_time))

    a, b = nil, nil
    EM.run do
      EM.start_server '127.0.0.1', @port, Module.new
      conn = EM.connect '127.0.0.1', @port
      EM.add_timer(0.3) do
        a = conn.get_idle_time
        conn.send_data 'a'
        EM.next_tick do
          EM.next_tick do
            b = conn.get_idle_time
            conn.close_connection
            EM.stop
          end
        end
      end
    end

    assert_in_delta 0.3, a, 0.1
    assert_in_delta 0, b, 0.1
  end
end