cool.io 1.9.3 → 1.9.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,5 @@
1
1
  require File.expand_path('../spec_helper', __FILE__)
2
+ require 'timeout'
2
3
 
3
4
  TIMEOUT = 0.010
4
5
  HOST = '127.0.0.1'
@@ -39,13 +40,31 @@ def on_message(data)
39
40
  @data = data
40
41
  end
41
42
 
43
+ # The reactor can be an order of magnitude slower under valgrind, so sleeping a
44
+ # fixed interval and assuming the event was processed by then makes these specs
45
+ # fail intermittently. Wait for the result instead. The timeout is generous
46
+ # enough that a slow machine still passes, and a genuine hang raises
47
+ # Timeout::Error here instead of blocking the suite forever.
48
+ WAIT_TIMEOUT = 5.0
49
+
50
+ def wait_until(timeout = WAIT_TIMEOUT)
51
+ Timeout.timeout(timeout) do
52
+ sleep 0.001 until yield
53
+ end
54
+ end
55
+
42
56
  def test_run(data = nil)
57
+ @data = ""
43
58
  reactor = Coolio::Loop.new
44
59
  server = Cool.io::TCPServer.new(HOST, PORT, MyConnection, method(:on_message))
45
60
  reactor.attach(server)
46
61
  thread = Thread.new { reactor.run }
47
- send_data(data) if data
48
- sleep TIMEOUT
62
+ if data
63
+ send_data(data)
64
+ wait_until { @data == data }
65
+ else
66
+ sleep TIMEOUT
67
+ end
49
68
  reactor.stop
50
69
  server.detach
51
70
  send_data('') # to leave from blocking loop
@@ -86,6 +105,7 @@ ensure
86
105
  end
87
106
 
88
107
  def test_run_timeout(data = nil, timeout = TIMEOUT)
108
+ @data = ""
89
109
  reactor = Coolio::Loop.new
90
110
  server = Cool.io::TCPServer.new(HOST, PORT, MyConnection, method(:on_message))
91
111
  reactor.attach(server)
@@ -95,8 +115,12 @@ def test_run_timeout(data = nil, timeout = TIMEOUT)
95
115
  reactor.run_once(timeout)
96
116
  end
97
117
  end
98
- send_data(data) if data
99
- sleep timeout
118
+ if data
119
+ send_data(data)
120
+ wait_until { @data == data }
121
+ else
122
+ sleep timeout
123
+ end
100
124
  server.detach
101
125
  running = false # another send is not required
102
126
  thread.join
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cool.io
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.9.3
4
+ version: 1.9.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tony Arcieri
@@ -77,6 +77,7 @@ extensions:
77
77
  extra_rdoc_files: []
78
78
  files:
79
79
  - ".github/workflows/test.yaml"
80
+ - ".github/workflows/valgrind.yaml"
80
81
  - ".gitignore"
81
82
  - ".rspec"
82
83
  - CHANGES.md
@@ -169,7 +170,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
169
170
  - !ruby/object:Gem::Version
170
171
  version: '0'
171
172
  requirements: []
172
- rubygems_version: 4.0.3
173
+ rubygems_version: 4.0.16
173
174
  specification_version: 4
174
175
  summary: A cool framework for doing high performance I/O in Ruby
175
176
  test_files: