fluentd 1.13.0 → 1.13.1

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of fluentd might be problematic. Click here for more details.

@@ -52,20 +52,30 @@ end
52
52
  class TcpOutputTest < Test::Unit::TestCase
53
53
  include StreamOutputTest
54
54
 
55
- PORT = unused_port
56
- CONFIG = %[
57
- port #{PORT}
58
- host 127.0.0.1
59
- send_timeout 51
60
- ]
55
+ def setup
56
+ super
57
+ @port = unused_port
58
+ end
61
59
 
62
- def create_driver(conf=CONFIG)
60
+ def teardown
61
+ @port = nil
62
+ end
63
+
64
+ def config
65
+ %[
66
+ port #{@port}
67
+ host 127.0.0.1
68
+ send_timeout 51
69
+ ]
70
+ end
71
+
72
+ def create_driver(conf=config)
63
73
  super(Fluent::TcpOutput, conf)
64
74
  end
65
75
 
66
76
  def test_configure
67
77
  d = create_driver
68
- assert_equal PORT, d.instance.port
78
+ assert_equal @port, d.instance.port
69
79
  assert_equal '127.0.0.1', d.instance.host
70
80
  assert_equal 51, d.instance.send_timeout
71
81
  end
@@ -20,7 +20,7 @@ unless skip
20
20
  test 'use default app if path is not found' do
21
21
  router = Fluent::PluginHelper::HttpServer::Router.new
22
22
  req = flexmock('request', path: 'path/')
23
- assert_equal(router.route!(:get, '/path/', req), [404, { 'Content-Type' => 'text/plain' }, "404 Not Found: #{req.path}\n"])
23
+ assert_equal(router.route!(:get, '/path/', req), [404, { 'Content-Type' => 'text/plain' }, "404 Not Found\n"])
24
24
  end
25
25
 
26
26
  test 'default app is configurable' do
@@ -560,7 +560,7 @@ class ChildProcessTest < Test::Unit::TestCase
560
560
  proc_lines = []
561
561
  Timeout.timeout(TEST_DEADLOCK_TIMEOUT) do
562
562
  ran = false
563
- @d.child_process_execute(:t14, "ruby", arguments:['-e', 'sleep 10; puts "hello"'], subprocess_name: "sleeeeeeeeeper", mode: [:read]) do |readio|
563
+ @d.child_process_execute(:t14, "/bin/sh", arguments:['-c', 'sleep 10; echo "hello"'], subprocess_name: "sleeeeeeeeeper", mode: [:read]) do |readio|
564
564
  m.lock
565
565
  ran = true
566
566
  pids << @d.child_process_id
@@ -9,11 +9,18 @@ require 'openssl'
9
9
  require 'async'
10
10
 
11
11
  class HttpHelperTest < Test::Unit::TestCase
12
- PORT = unused_port
13
12
  NULL_LOGGER = Logger.new(nil)
14
13
  CERT_DIR = File.expand_path(File.dirname(__FILE__) + '/data/cert/without_ca')
15
14
  CERT_CA_DIR = File.expand_path(File.dirname(__FILE__) + '/data/cert/with_ca')
16
15
 
16
+ def setup
17
+ @port = unused_port
18
+ end
19
+
20
+ def teardown
21
+ @port = nil
22
+ end
23
+
17
24
  class Dummy < Fluent::Plugin::TestBase
18
25
  helpers :http_server
19
26
  end
@@ -147,7 +154,7 @@ class HttpHelperTest < Test::Unit::TestCase
147
154
  sub_test_case 'Create a HTTP server' do
148
155
  test 'monunt given path' do
149
156
  on_driver do |driver|
150
- driver.http_server_create_http_server(:http_server_helper_test, addr: '127.0.0.1', port: PORT, logger: NULL_LOGGER) do |s|
157
+ driver.http_server_create_http_server(:http_server_helper_test, addr: '127.0.0.1', port: @port, logger: NULL_LOGGER) do |s|
151
158
  s.get('/example/hello') { [200, { 'Content-Type' => 'text/plain' }, 'hello get'] }
152
159
  s.post('/example/hello') { [200, { 'Content-Type' => 'text/plain' }, 'hello post'] }
153
160
  s.head('/example/hello') { [200, { 'Content-Type' => 'text/plain' }, 'hello head'] }
@@ -158,13 +165,13 @@ class HttpHelperTest < Test::Unit::TestCase
158
165
  s.options('/example/hello') { [200, { 'Content-Type' => 'text/plain' }, 'hello options'] }
159
166
  end
160
167
 
161
- resp = head("http://127.0.0.1:#{PORT}/example/hello")
168
+ resp = head("http://127.0.0.1:#{@port}/example/hello")
162
169
  assert_equal('200', resp.code)
163
170
  assert_equal(nil, resp.body)
164
171
  assert_equal('text/plain', resp['Content-Type'])
165
172
 
166
173
  %w[get put post put delete options trace].each do |n|
167
- resp = send(n, "http://127.0.0.1:#{PORT}/example/hello")
174
+ resp = send(n, "http://127.0.0.1:#{@port}/example/hello")
168
175
  assert_equal('200', resp.code)
169
176
  assert_equal("hello #{n}", resp.body)
170
177
  assert_equal('text/plain', resp['Content-Type'])
@@ -174,44 +181,44 @@ class HttpHelperTest < Test::Unit::TestCase
174
181
 
175
182
  test 'when path does not start with `/` or ends with `/`' do
176
183
  on_driver do |driver|
177
- driver.http_server_create_http_server(:http_server_helper_test, addr: '127.0.0.1', port: PORT, logger: NULL_LOGGER) do |s|
184
+ driver.http_server_create_http_server(:http_server_helper_test, addr: '127.0.0.1', port: @port, logger: NULL_LOGGER) do |s|
178
185
  s.get('example/hello') { [200, { 'Content-Type' => 'text/plain' }, 'hello get'] }
179
186
  s.get('/example/hello2/') { [200, { 'Content-Type' => 'text/plain' }, 'hello get'] }
180
187
  end
181
188
 
182
- resp = get("http://127.0.0.1:#{PORT}/example/hello")
189
+ resp = get("http://127.0.0.1:#{@port}/example/hello")
183
190
  assert_equal('404', resp.code)
184
191
 
185
- resp = get("http://127.0.0.1:#{PORT}/example/hello2")
192
+ resp = get("http://127.0.0.1:#{@port}/example/hello2")
186
193
  assert_equal('200', resp.code)
187
194
  end
188
195
  end
189
196
 
190
197
  test 'when error raised' do
191
198
  on_driver do |driver|
192
- driver.http_server_create_http_server(:http_server_helper_test, addr: '127.0.0.1', port: PORT, logger: NULL_LOGGER) do |s|
199
+ driver.http_server_create_http_server(:http_server_helper_test, addr: '127.0.0.1', port: @port, logger: NULL_LOGGER) do |s|
193
200
  s.get('/example/hello') { raise 'error!' }
194
201
  end
195
202
 
196
- resp = get("http://127.0.0.1:#{PORT}/example/hello")
203
+ resp = get("http://127.0.0.1:#{@port}/example/hello")
197
204
  assert_equal('500', resp.code)
198
205
  end
199
206
  end
200
207
 
201
208
  test 'when path is not found' do
202
209
  on_driver do |driver|
203
- driver.http_server_create_http_server(:http_server_helper_test, addr: '127.0.0.1', port: PORT, logger: NULL_LOGGER) do |s|
210
+ driver.http_server_create_http_server(:http_server_helper_test, addr: '127.0.0.1', port: @port, logger: NULL_LOGGER) do |s|
204
211
  s.get('/example/hello') { [200, { 'Content-Type' => 'text/plain' }, 'hello get'] }
205
212
  end
206
213
 
207
- resp = get("http://127.0.0.1:#{PORT}/example/hello/not_found")
214
+ resp = get("http://127.0.0.1:#{@port}/example/hello/not_found")
208
215
  assert_equal('404', resp.code)
209
216
  end
210
217
  end
211
218
 
212
219
  test 'params and body' do
213
220
  on_driver do |driver|
214
- driver.http_server_create_http_server(:http_server_helper_test, addr: '127.0.0.1', port: PORT, logger: NULL_LOGGER) do |s|
221
+ driver.http_server_create_http_server(:http_server_helper_test, addr: '127.0.0.1', port: @port, logger: NULL_LOGGER) do |s|
215
222
  s.get('/example/hello') do |req|
216
223
  assert_equal(req.query_string, nil)
217
224
  assert_equal(req.body, nil)
@@ -237,16 +244,16 @@ class HttpHelperTest < Test::Unit::TestCase
237
244
  end
238
245
  end
239
246
 
240
- resp = get("http://127.0.0.1:#{PORT}/example/hello")
247
+ resp = get("http://127.0.0.1:#{@port}/example/hello")
241
248
  assert_equal('200', resp.code)
242
249
 
243
- resp = post("http://127.0.0.1:#{PORT}/example/hello", 'this is body')
250
+ resp = post("http://127.0.0.1:#{@port}/example/hello", 'this is body')
244
251
  assert_equal('200', resp.code)
245
252
 
246
- resp = get("http://127.0.0.1:#{PORT}/example/hello/params?test=true")
253
+ resp = get("http://127.0.0.1:#{@port}/example/hello/params?test=true")
247
254
  assert_equal('200', resp.code)
248
255
 
249
- resp = post("http://127.0.0.1:#{PORT}/example/hello/params?test=true", 'this is body')
256
+ resp = post("http://127.0.0.1:#{@port}/example/hello/params?test=true", 'this is body')
250
257
  assert_equal('200', resp.code)
251
258
  end
252
259
  end
@@ -265,11 +272,11 @@ class HttpHelperTest < Test::Unit::TestCase
265
272
  test 'can overwrite settings by using tls_context' do
266
273
  on_driver_transport({ 'insecure' => 'false' }) do |driver|
267
274
  tls = { 'insecure' => 'true' } # overwrite
268
- driver.http_server_create_https_server(:http_server_helper_test_tls, addr: '127.0.0.1', port: PORT, logger: NULL_LOGGER, tls_opts: tls) do |s|
275
+ driver.http_server_create_https_server(:http_server_helper_test_tls, addr: '127.0.0.1', port: @port, logger: NULL_LOGGER, tls_opts: tls) do |s|
269
276
  s.get('/example/hello') { [200, { 'Content-Type' => 'text/plain' }, 'hello get'] }
270
277
  end
271
278
 
272
- resp = secure_get("https://127.0.0.1:#{PORT}/example/hello", verify: false)
279
+ resp = secure_get("https://127.0.0.1:#{@port}/example/hello", verify: false)
273
280
  assert_equal('200', resp.code)
274
281
  assert_equal('hello get', resp.body)
275
282
  end
@@ -277,17 +284,17 @@ class HttpHelperTest < Test::Unit::TestCase
277
284
 
278
285
  test 'with insecure in transport section' do
279
286
  on_driver_transport({ 'insecure' => 'true' }) do |driver|
280
- driver.http_server_create_https_server(:http_server_helper_test_tls, addr: '127.0.0.1', port: PORT, logger: NULL_LOGGER) do |s|
287
+ driver.http_server_create_https_server(:http_server_helper_test_tls, addr: '127.0.0.1', port: @port, logger: NULL_LOGGER) do |s|
281
288
  s.get('/example/hello') { [200, { 'Content-Type' => 'text/plain' }, 'hello get'] }
282
289
  end
283
290
  omit "TLS connection should be aborted due to `Errno::ECONNABORTED`. Need to debug." if Fluent.windows?
284
291
 
285
- resp = secure_get("https://127.0.0.1:#{PORT}/example/hello", verify: false)
292
+ resp = secure_get("https://127.0.0.1:#{@port}/example/hello", verify: false)
286
293
  assert_equal('200', resp.code)
287
294
  assert_equal('hello get', resp.body)
288
295
 
289
296
  assert_raise OpenSSL::SSL::SSLError do
290
- secure_get("https://127.0.0.1:#{PORT}/example/hello")
297
+ secure_get("https://127.0.0.1:#{@port}/example/hello")
291
298
  end
292
299
  end
293
300
  end
@@ -306,11 +313,11 @@ class HttpHelperTest < Test::Unit::TestCase
306
313
  end
307
314
 
308
315
  on_driver_transport(opt) do |driver|
309
- driver.http_server_create_https_server(:http_server_helper_test_tls, addr: '127.0.0.1', port: PORT, logger: NULL_LOGGER) do |s|
316
+ driver.http_server_create_https_server(:http_server_helper_test_tls, addr: '127.0.0.1', port: @port, logger: NULL_LOGGER) do |s|
310
317
  s.get('/example/hello') { [200, { 'Content-Type' => 'text/plain' }, 'hello get'] }
311
318
  end
312
319
 
313
- resp = secure_get("https://127.0.0.1:#{PORT}/example/hello", cert_path: cert_path)
320
+ resp = secure_get("https://127.0.0.1:#{@port}/example/hello", cert_path: cert_path)
314
321
  assert_equal('200', resp.code)
315
322
  assert_equal('hello get', resp.body)
316
323
  end
@@ -333,11 +340,11 @@ class HttpHelperTest < Test::Unit::TestCase
333
340
  end
334
341
 
335
342
  on_driver_transport(opt) do |driver|
336
- driver.http_server_create_https_server(:http_server_helper_test_tls, addr: '127.0.0.1', port: PORT, logger: NULL_LOGGER) do |s|
343
+ driver.http_server_create_https_server(:http_server_helper_test_tls, addr: '127.0.0.1', port: @port, logger: NULL_LOGGER) do |s|
337
344
  s.get('/example/hello') { [200, { 'Content-Type' => 'text/plain' }, 'hello get'] }
338
345
  end
339
346
 
340
- resp = secure_get("https://127.0.0.1:#{PORT}/example/hello", cert_path: ca_cert_path)
347
+ resp = secure_get("https://127.0.0.1:#{@port}/example/hello", cert_path: ca_cert_path)
341
348
  assert_equal('200', resp.code)
342
349
  assert_equal('hello get', resp.body)
343
350
  end
@@ -355,7 +362,7 @@ class HttpHelperTest < Test::Unit::TestCase
355
362
  end
356
363
 
357
364
  stub(Fluent::PluginHelper::HttpServer::Server).new(addr: anything, port: anything, logger: anything, default_app: anything) { server }
358
- driver.http_server_create_http_server(:http_server_helper_test, addr: '127.0.0.1', port: PORT, logger: NULL_LOGGER) do
365
+ driver.http_server_create_http_server(:http_server_helper_test, addr: '127.0.0.1', port: @port, logger: NULL_LOGGER) do
359
366
  # nothing
360
367
  end
361
368
  driver.stop
@@ -14,9 +14,8 @@ class ServerPluginHelperTest < Test::Unit::TestCase
14
14
 
15
15
  TMP_DIR = File.expand_path(File.dirname(__FILE__) + "/../tmp/plugin_helper_server")
16
16
 
17
- PORT = unused_port
18
-
19
17
  setup do
18
+ @port = unused_port
20
19
  @socket_manager_path = ServerEngine::SocketManager::Server.generate_path
21
20
  if @socket_manager_path.is_a?(String) && File.exist?(@socket_manager_path)
22
21
  FileUtils.rm_f @socket_manager_path
@@ -75,16 +74,16 @@ class ServerPluginHelperTest < Test::Unit::TestCase
75
74
  data(methods)
76
75
  test 'raise error if title is not specified or not a symbol' do |m|
77
76
  assert_raise(ArgumentError.new("BUG: title must be a symbol")) do
78
- @d.__send__(m, nil, PORT){|x| x }
77
+ @d.__send__(m, nil, @port){|x| x }
79
78
  end
80
79
  assert_raise(ArgumentError.new("BUG: title must be a symbol")) do
81
- @d.__send__(m, "", PORT){|x| x }
80
+ @d.__send__(m, "", @port){|x| x }
82
81
  end
83
82
  assert_raise(ArgumentError.new("BUG: title must be a symbol")) do
84
- @d.__send__(m, "title", PORT){|x| x }
83
+ @d.__send__(m, "title", @port){|x| x }
85
84
  end
86
85
  assert_nothing_raised do
87
- @d.__send__(m, :myserver, PORT){|x| x }
86
+ @d.__send__(m, :myserver, @port){|x| x }
88
87
  end
89
88
  end
90
89
 
@@ -100,30 +99,30 @@ class ServerPluginHelperTest < Test::Unit::TestCase
100
99
  @d.__send__(m, :myserver, 1.5){|x| x }
101
100
  end
102
101
  assert_nothing_raised do
103
- @d.__send__(m, :myserver, PORT){|x| x }
102
+ @d.__send__(m, :myserver, @port){|x| x }
104
103
  end
105
104
  end
106
105
 
107
106
  data(methods)
108
107
  test 'raise error if block is not specified' do |m|
109
108
  assert_raise(ArgumentError) do
110
- @d.__send__(m, :myserver, PORT)
109
+ @d.__send__(m, :myserver, @port)
111
110
  end
112
111
  assert_nothing_raised do
113
- @d.__send__(m, :myserver, PORT){|x| x }
112
+ @d.__send__(m, :myserver, @port){|x| x }
114
113
  end
115
114
  end
116
115
 
117
116
  data(methods)
118
117
  test 'creates tcp server, binds 0.0.0.0 in default' do |m|
119
- @d.__send__(m, :myserver, PORT){|x| x }
118
+ @d.__send__(m, :myserver, @port){|x| x }
120
119
 
121
120
  assert_equal 1, @d._servers.size
122
121
 
123
122
  created_server_info = @d._servers.first
124
123
 
125
124
  assert_equal :myserver, created_server_info.title
126
- assert_equal PORT, created_server_info.port
125
+ assert_equal @port, created_server_info.port
127
126
 
128
127
  assert_equal :tcp, created_server_info.proto
129
128
  assert_equal "0.0.0.0", created_server_info.bind
@@ -136,7 +135,7 @@ class ServerPluginHelperTest < Test::Unit::TestCase
136
135
 
137
136
  data(methods)
138
137
  test 'creates tcp server if specified in proto' do |m|
139
- @d.__send__(m, :myserver, PORT, proto: :tcp){|x| x }
138
+ @d.__send__(m, :myserver, @port, proto: :tcp){|x| x }
140
139
 
141
140
  created_server_info = @d._servers.first
142
141
  assert_equal :tcp, created_server_info.proto
@@ -152,7 +151,7 @@ class ServerPluginHelperTest < Test::Unit::TestCase
152
151
  d.start
153
152
  d.after_start
154
153
 
155
- d.__send__(m, :myserver, PORT){|x| x }
154
+ d.__send__(m, :myserver, @port){|x| x }
156
155
 
157
156
  created_server_info = @d._servers.first
158
157
  assert_equal :tcp, created_server_info.proto
@@ -163,9 +162,9 @@ class ServerPluginHelperTest < Test::Unit::TestCase
163
162
  data(methods)
164
163
  test 'creates tls server if specified in proto' do |m|
165
164
  assert_raise(ArgumentError.new("BUG: TLS transport specified, but certification options are not specified")) do
166
- @d.__send__(m, :myserver, PORT, proto: :tls){|x| x }
165
+ @d.__send__(m, :myserver, @port, proto: :tls){|x| x }
167
166
  end
168
- @d.__send__(m, :myserver, PORT, proto: :tls, tls_options: {insecure: true}){|x| x }
167
+ @d.__send__(m, :myserver, @port, proto: :tls, tls_options: {insecure: true}){|x| x }
169
168
 
170
169
  created_server_info = @d._servers.first
171
170
  assert_equal :tls, created_server_info.proto
@@ -181,7 +180,7 @@ class ServerPluginHelperTest < Test::Unit::TestCase
181
180
  d.start
182
181
  d.after_start
183
182
 
184
- d.__send__(m, :myserver, PORT){|x| x }
183
+ d.__send__(m, :myserver, @port){|x| x }
185
184
 
186
185
  created_server_info = @d._servers.first
187
186
  assert_equal :tls, created_server_info.proto
@@ -197,7 +196,7 @@ class ServerPluginHelperTest < Test::Unit::TestCase
197
196
  data(methods)
198
197
  test 'raise error if unknown protocol specified' do |m|
199
198
  assert_raise(ArgumentError.new("BUG: invalid protocol name")) do
200
- @d.__send__(m, :myserver, PORT, proto: :quic){|x| x }
199
+ @d.__send__(m, :myserver, @port, proto: :quic){|x| x }
201
200
  end
202
201
  end
203
202
 
@@ -211,10 +210,10 @@ class ServerPluginHelperTest < Test::Unit::TestCase
211
210
  )
212
211
  test 'raise error if udp options specified for tcp/tls/unix' do |(m, proto)|
213
212
  assert_raise ArgumentError do
214
- @d.__send__(m, :myserver, PORT, proto: proto, max_bytes: 128){|x| x }
213
+ @d.__send__(m, :myserver, @port, proto: proto, max_bytes: 128){|x| x }
215
214
  end
216
215
  assert_raise ArgumentError do
217
- @d.__send__(m, :myserver, PORT, proto: proto, flags: 1){|x| x }
216
+ @d.__send__(m, :myserver, @port, proto: proto, flags: 1){|x| x }
218
217
  end
219
218
  end
220
219
 
@@ -223,7 +222,7 @@ class ServerPluginHelperTest < Test::Unit::TestCase
223
222
  )
224
223
  test 'raise error if tcp/tls options specified for udp' do |(m, proto)|
225
224
  assert_raise(ArgumentError.new("BUG: linger_timeout is available for tcp/tls")) do
226
- @d.__send__(m, :myserver, PORT, proto: proto, linger_timeout: 1, max_bytes: 128){|x| x }
225
+ @d.__send__(m, :myserver, @port, proto: proto, linger_timeout: 1, max_bytes: 128){|x| x }
227
226
  end
228
227
  end
229
228
 
@@ -232,7 +231,7 @@ class ServerPluginHelperTest < Test::Unit::TestCase
232
231
  )
233
232
  test 'raise error if tcp/tls/unix backlog options specified for udp' do |(m, proto)|
234
233
  assert_raise(ArgumentError.new("BUG: backlog is available for tcp/tls")) do
235
- @d.__send__(m, :myserver, PORT, proto: proto, backlog: 500){|x| x }
234
+ @d.__send__(m, :myserver, @port, proto: proto, backlog: 500){|x| x }
236
235
  end
237
236
  end
238
237
 
@@ -241,7 +240,7 @@ class ServerPluginHelperTest < Test::Unit::TestCase
241
240
  )
242
241
  test 'raise error if tcp/tls send_keepalive_packet option is specified for udp' do |(m, proto)|
243
242
  assert_raise(ArgumentError.new("BUG: send_keepalive_packet is available for tcp/tls")) do
244
- @d.__send__(m, :myserver, PORT, proto: proto, send_keepalive_packet: true){|x| x }
243
+ @d.__send__(m, :myserver, @port, proto: proto, send_keepalive_packet: true){|x| x }
245
244
  end
246
245
  end
247
246
 
@@ -254,7 +253,7 @@ class ServerPluginHelperTest < Test::Unit::TestCase
254
253
  )
255
254
  test 'raise error if tls options specified for tcp/udp/unix' do |(m, proto, kwargs)|
256
255
  assert_raise(ArgumentError.new("BUG: tls_options is available only for tls")) do
257
- @d.__send__(m, :myserver, PORT, proto: proto, tls_options: {}, **kwargs){|x| x }
256
+ @d.__send__(m, :myserver, @port, proto: proto, tls_options: {}, **kwargs){|x| x }
258
257
  end
259
258
  end
260
259
 
@@ -266,7 +265,7 @@ class ServerPluginHelperTest < Test::Unit::TestCase
266
265
  'server_create_connection tls' => [:server_create_connection, :tls, {tls_options: {insecure: true}}],
267
266
  )
268
267
  test 'can bind specified IPv4 address' do |(m, proto, kwargs)|
269
- @d.__send__(m, :myserver, PORT, proto: proto, bind: "127.0.0.1", **kwargs){|x| x }
268
+ @d.__send__(m, :myserver, @port, proto: proto, bind: "127.0.0.1", **kwargs){|x| x }
270
269
  assert_equal "127.0.0.1", @d._servers.first.bind
271
270
  assert_equal "127.0.0.1", @d._servers.first.server.instance_eval{ instance_variable_defined?(:@listen_socket) ? @listen_socket : @_io }.addr[3]
272
271
  end
@@ -280,7 +279,7 @@ class ServerPluginHelperTest < Test::Unit::TestCase
280
279
  )
281
280
  test 'can bind specified IPv6 address' do |(m, proto, kwargs)| # if available
282
281
  omit "IPv6 unavailable here" unless ipv6_enabled?
283
- @d.__send__(m, :myserver, PORT, proto: proto, bind: "::1", **kwargs){|x| x }
282
+ @d.__send__(m, :myserver, @port, proto: proto, bind: "::1", **kwargs){|x| x }
284
283
  assert_equal "::1", @d._servers.first.bind
285
284
  assert_equal "::1", @d._servers.first.server.instance_eval{ instance_variable_defined?(:@listen_socket) ? @listen_socket : @_io }.addr[3]
286
285
  end
@@ -299,8 +298,8 @@ class ServerPluginHelperTest < Test::Unit::TestCase
299
298
  d2 = Dummy.new; d2.start; d2.after_start
300
299
 
301
300
  assert_nothing_raised do
302
- @d.__send__(m, :myserver, PORT, proto: proto, **kwargs){|x| x }
303
- d2.__send__(m, :myserver, PORT, proto: proto, **kwargs){|x| x }
301
+ @d.__send__(m, :myserver, @port, proto: proto, **kwargs){|x| x }
302
+ d2.__send__(m, :myserver, @port, proto: proto, **kwargs){|x| x }
304
303
  end
305
304
  ensure
306
305
  d2.stop; d2.before_shutdown; d2.shutdown; d2.after_shutdown; d2.close; d2.terminate
@@ -323,10 +322,10 @@ class ServerPluginHelperTest < Test::Unit::TestCase
323
322
  d2 = Dummy.new; d2.start; d2.after_start
324
323
 
325
324
  assert_nothing_raised do
326
- @d.__send__(m, :myserver, PORT, proto: proto, shared: false, **kwargs){|x| x }
325
+ @d.__send__(m, :myserver, @port, proto: proto, shared: false, **kwargs){|x| x }
327
326
  end
328
327
  assert_raise(Errno::EADDRINUSE, Errno::EACCES) do
329
- d2.__send__(m, :myserver, PORT, proto: proto, **kwargs){|x| x }
328
+ d2.__send__(m, :myserver, @port, proto: proto, **kwargs){|x| x }
330
329
  end
331
330
  ensure
332
331
  d2.stop; d2.before_shutdown; d2.shutdown; d2.after_shutdown; d2.close; d2.terminate
@@ -343,15 +342,15 @@ class ServerPluginHelperTest < Test::Unit::TestCase
343
342
  )
344
343
  test 'raise error if block argument is not specified or too many' do |(proto, kwargs)|
345
344
  assert_raise(ArgumentError.new("BUG: block must have 1 or 2 arguments")) do
346
- @d.server_create(:myserver, PORT, proto: proto, **kwargs){ 1 }
345
+ @d.server_create(:myserver, @port, proto: proto, **kwargs){ 1 }
347
346
  end
348
347
  assert_raise(ArgumentError.new("BUG: block must have 1 or 2 arguments")) do
349
- @d.server_create(:myserver, PORT, proto: proto, **kwargs){|sock, conn, what_is_this| 1 }
348
+ @d.server_create(:myserver, @port, proto: proto, **kwargs){|sock, conn, what_is_this| 1 }
350
349
  end
351
350
  end
352
351
 
353
352
  test 'creates udp server if specified in proto' do
354
- @d.server_create(:myserver, PORT, proto: :udp, max_bytes: 512){|x| x }
353
+ @d.server_create(:myserver, @port, proto: :udp, max_bytes: 512){|x| x }
355
354
 
356
355
  created_server_info = @d._servers.first
357
356
  assert_equal :udp, created_server_info.proto
@@ -363,7 +362,7 @@ class ServerPluginHelperTest < Test::Unit::TestCase
363
362
  sub_test_case '#server_create_tcp' do
364
363
  test 'can accept all keyword arguments valid for tcp server' do
365
364
  assert_nothing_raised do
366
- @d.server_create_tcp(:s, PORT, bind: '127.0.0.1', shared: false, resolve_name: true, linger_timeout: 10, backlog: 500, send_keepalive_packet: true) do |data, conn|
365
+ @d.server_create_tcp(:s, @port, bind: '127.0.0.1', shared: false, resolve_name: true, linger_timeout: 10, backlog: 500, send_keepalive_packet: true) do |data, conn|
367
366
  # ...
368
367
  end
369
368
  end
@@ -371,11 +370,11 @@ class ServerPluginHelperTest < Test::Unit::TestCase
371
370
 
372
371
  test 'creates a tcp server just to read data' do
373
372
  received = ""
374
- @d.server_create_tcp(:s, PORT) do |data|
373
+ @d.server_create_tcp(:s, @port) do |data|
375
374
  received << data
376
375
  end
377
376
  3.times do
378
- sock = TCPSocket.new("127.0.0.1", PORT)
377
+ sock = TCPSocket.new("127.0.0.1", @port)
379
378
  sock.puts "yay"
380
379
  sock.puts "foo"
381
380
  sock.close
@@ -387,12 +386,12 @@ class ServerPluginHelperTest < Test::Unit::TestCase
387
386
  test 'creates a tcp server to read and write data' do
388
387
  received = ""
389
388
  responses = []
390
- @d.server_create_tcp(:s, PORT) do |data, conn|
389
+ @d.server_create_tcp(:s, @port) do |data, conn|
391
390
  received << data
392
391
  conn.write "ack\n"
393
392
  end
394
393
  3.times do
395
- TCPSocket.open("127.0.0.1", PORT) do |sock|
394
+ TCPSocket.open("127.0.0.1", @port) do |sock|
396
395
  sock.puts "yay"
397
396
  sock.puts "foo"
398
397
  responses << sock.readline
@@ -408,12 +407,12 @@ class ServerPluginHelperTest < Test::Unit::TestCase
408
407
 
409
408
  received = ""
410
409
  responses = []
411
- @d.server_create_tcp(:s, PORT, bind: "::1") do |data, conn|
410
+ @d.server_create_tcp(:s, @port, bind: "::1") do |data, conn|
412
411
  received << data
413
412
  conn.write "ack\n"
414
413
  end
415
414
  3.times do
416
- TCPSocket.open("::1", PORT) do |sock|
415
+ TCPSocket.open("::1", @port) do |sock|
417
416
  sock.puts "yay"
418
417
  sock.puts "foo"
419
418
  responses << sock.readline
@@ -427,12 +426,12 @@ class ServerPluginHelperTest < Test::Unit::TestCase
427
426
  test 'does not resolve name of client address in default' do
428
427
  received = ""
429
428
  sources = []
430
- @d.server_create_tcp(:s, PORT) do |data, conn|
429
+ @d.server_create_tcp(:s, @port) do |data, conn|
431
430
  received << data
432
431
  sources << conn.remote_host
433
432
  end
434
433
  3.times do
435
- TCPSocket.open("127.0.0.1", PORT) do |sock|
434
+ TCPSocket.open("127.0.0.1", @port) do |sock|
436
435
  sock.puts "yay"
437
436
  end
438
437
  end
@@ -446,12 +445,12 @@ class ServerPluginHelperTest < Test::Unit::TestCase
446
445
 
447
446
  received = ""
448
447
  sources = []
449
- @d.server_create_tcp(:s, PORT, resolve_name: true) do |data, conn|
448
+ @d.server_create_tcp(:s, @port, resolve_name: true) do |data, conn|
450
449
  received << data
451
450
  sources << conn.remote_host
452
451
  end
453
452
  3.times do
454
- TCPSocket.open("127.0.0.1", PORT) do |sock|
453
+ TCPSocket.open("127.0.0.1", @port) do |sock|
455
454
  sock.puts "yay"
456
455
  end
457
456
  end
@@ -467,7 +466,7 @@ class ServerPluginHelperTest < Test::Unit::TestCase
467
466
  test 'raises error if plugin registers data callback for connection object from #server_create' do
468
467
  received = ""
469
468
  errors = []
470
- @d.server_create_tcp(:s, PORT) do |data, conn|
469
+ @d.server_create_tcp(:s, @port) do |data, conn|
471
470
  received << data
472
471
  begin
473
472
  conn.data{|d| received << d.upcase }
@@ -475,7 +474,7 @@ class ServerPluginHelperTest < Test::Unit::TestCase
475
474
  errors << e
476
475
  end
477
476
  end
478
- TCPSocket.open("127.0.0.1", PORT) do |sock|
477
+ TCPSocket.open("127.0.0.1", @port) do |sock|
479
478
  sock.puts "foo"
480
479
  end
481
480
  waiting(10){ sleep 0.1 until received.bytesize == 4 || errors.size == 1 }
@@ -489,7 +488,7 @@ class ServerPluginHelperTest < Test::Unit::TestCase
489
488
  lines = []
490
489
  responses = []
491
490
  response_completes = []
492
- @d.server_create_tcp(:s, PORT) do |data, conn|
491
+ @d.server_create_tcp(:s, @port) do |data, conn|
493
492
  conn.on(:write_complete){|c| response_completes << true }
494
493
  buffer << data
495
494
  if idx = buffer.index("\n")
@@ -498,7 +497,7 @@ class ServerPluginHelperTest < Test::Unit::TestCase
498
497
  end
499
498
  end
500
499
  3.times do
501
- TCPSocket.open("127.0.0.1", PORT) do |sock|
500
+ TCPSocket.open("127.0.0.1", @port) do |sock|
502
501
  sock.write "yay"
503
502
  sock.write "foo\n"
504
503
  begin
@@ -519,7 +518,7 @@ class ServerPluginHelperTest < Test::Unit::TestCase
519
518
  buffer = ""
520
519
  lines = []
521
520
  callback_results = []
522
- @d.server_create_tcp(:s, PORT) do |data, conn|
521
+ @d.server_create_tcp(:s, @port) do |data, conn|
523
522
  conn.on(:close){|c| callback_results << "closed" }
524
523
  buffer << data
525
524
  if idx = buffer.index("\n")
@@ -528,7 +527,7 @@ class ServerPluginHelperTest < Test::Unit::TestCase
528
527
  end
529
528
  end
530
529
  3.times do
531
- TCPSocket.open("127.0.0.1", PORT) do |sock|
530
+ TCPSocket.open("127.0.0.1", @port) do |sock|
532
531
  sock.write "yay"
533
532
  sock.write "foo\n"
534
533
  begin
@@ -551,10 +550,10 @@ class ServerPluginHelperTest < Test::Unit::TestCase
551
550
  omit "IPv6 unavailable here" unless ipv6_enabled?
552
551
 
553
552
  assert_nothing_raised do
554
- @d.server_create_tcp(:s_ipv4, PORT, bind: '0.0.0.0', shared: false) do |data, conn|
553
+ @d.server_create_tcp(:s_ipv4, @port, bind: '0.0.0.0', shared: false) do |data, conn|
555
554
  # ...
556
555
  end
557
- @d.server_create_tcp(:s_ipv6, PORT, bind: '::', shared: false) do |data, conn|
556
+ @d.server_create_tcp(:s_ipv6, @port, bind: '::', shared: false) do |data, conn|
558
557
  # ...
559
558
  end
560
559
  end
@@ -564,7 +563,7 @@ class ServerPluginHelperTest < Test::Unit::TestCase
564
563
  sub_test_case '#server_create_udp' do
565
564
  test 'can accept all keyword arguments valid for udp server' do
566
565
  assert_nothing_raised do
567
- @d.server_create_udp(:s, PORT, bind: '127.0.0.1', shared: false, resolve_name: true, max_bytes: 100, flags: 1) do |data, conn|
566
+ @d.server_create_udp(:s, @port, bind: '127.0.0.1', shared: false, resolve_name: true, max_bytes: 100, flags: 1) do |data, conn|
568
567
  # ...
569
568
  end
570
569
  end
@@ -572,14 +571,14 @@ class ServerPluginHelperTest < Test::Unit::TestCase
572
571
 
573
572
  test 'creates a udp server just to read data' do
574
573
  received = ""
575
- @d.server_create_udp(:s, PORT, max_bytes: 128) do |data|
574
+ @d.server_create_udp(:s, @port, max_bytes: 128) do |data|
576
575
  received << data
577
576
  end
578
577
  bind_port = unused_port(protocol: :udp, bind: "127.0.0.1")
579
578
  3.times do
580
579
  sock = UDPSocket.new(Socket::AF_INET)
581
580
  sock.bind("127.0.0.1", bind_port)
582
- sock.connect("127.0.0.1", PORT)
581
+ sock.connect("127.0.0.1", @port)
583
582
  sock.puts "yay"
584
583
  sock.puts "foo"
585
584
  sock.close
@@ -591,7 +590,7 @@ class ServerPluginHelperTest < Test::Unit::TestCase
591
590
  test 'creates a udp server to read and write data' do
592
591
  received = ""
593
592
  responses = []
594
- @d.server_create_udp(:s, PORT, max_bytes: 128) do |data, sock|
593
+ @d.server_create_udp(:s, @port, max_bytes: 128) do |data, sock|
595
594
  received << data
596
595
  sock.write "ack\n"
597
596
  end
@@ -600,7 +599,7 @@ class ServerPluginHelperTest < Test::Unit::TestCase
600
599
  begin
601
600
  sock = UDPSocket.new(Socket::AF_INET)
602
601
  sock.bind("127.0.0.1", bind_port)
603
- sock.connect("127.0.0.1", PORT)
602
+ sock.connect("127.0.0.1", @port)
604
603
  th = Thread.new do
605
604
  while true
606
605
  begin
@@ -631,7 +630,7 @@ class ServerPluginHelperTest < Test::Unit::TestCase
631
630
 
632
631
  received = ""
633
632
  responses = []
634
- @d.server_create_udp(:s, PORT, bind: "::1", max_bytes: 128) do |data, sock|
633
+ @d.server_create_udp(:s, @port, bind: "::1", max_bytes: 128) do |data, sock|
635
634
  received << data
636
635
  sock.write "ack\n"
637
636
  end
@@ -644,7 +643,7 @@ class ServerPluginHelperTest < Test::Unit::TestCase
644
643
  responses << sock.recv(16)
645
644
  true
646
645
  end
647
- sock.connect("::1", PORT)
646
+ sock.connect("::1", @port)
648
647
  sock.write "yay\nfoo\n"
649
648
  th.join(5)
650
649
  ensure
@@ -659,13 +658,13 @@ class ServerPluginHelperTest < Test::Unit::TestCase
659
658
  test 'does not resolve name of client address in default' do
660
659
  received = ""
661
660
  sources = []
662
- @d.server_create_udp(:s, PORT, max_bytes: 128) do |data, sock|
661
+ @d.server_create_udp(:s, @port, max_bytes: 128) do |data, sock|
663
662
  received << data
664
663
  sources << sock.remote_host
665
664
  end
666
665
  3.times do
667
666
  sock = UDPSocket.new(Socket::AF_INET)
668
- sock.connect("127.0.0.1", PORT)
667
+ sock.connect("127.0.0.1", @port)
669
668
  sock.puts "yay"
670
669
  sock.close
671
670
  end
@@ -679,13 +678,13 @@ class ServerPluginHelperTest < Test::Unit::TestCase
679
678
 
680
679
  received = ""
681
680
  sources = []
682
- @d.server_create_udp(:s, PORT, resolve_name: true, max_bytes: 128) do |data, sock|
681
+ @d.server_create_udp(:s, @port, resolve_name: true, max_bytes: 128) do |data, sock|
683
682
  received << data
684
683
  sources << sock.remote_host
685
684
  end
686
685
  3.times do
687
686
  sock = UDPSocket.new(Socket::AF_INET)
688
- sock.connect("127.0.0.1", PORT)
687
+ sock.connect("127.0.0.1", @port)
689
688
  sock.puts "yay"
690
689
  sock.close
691
690
  end
@@ -697,7 +696,7 @@ class ServerPluginHelperTest < Test::Unit::TestCase
697
696
  test 'raises error if plugin registers data callback for connection object from #server_create' do
698
697
  received = ""
699
698
  errors = []
700
- @d.server_create_udp(:s, PORT, max_bytes: 128) do |data, sock|
699
+ @d.server_create_udp(:s, @port, max_bytes: 128) do |data, sock|
701
700
  received << data
702
701
  begin
703
702
  sock.data{|d| received << d.upcase }
@@ -706,7 +705,7 @@ class ServerPluginHelperTest < Test::Unit::TestCase
706
705
  end
707
706
  end
708
707
  sock = UDPSocket.new(Socket::AF_INET)
709
- sock.connect("127.0.0.1", PORT)
708
+ sock.connect("127.0.0.1", @port)
710
709
  sock.write "foo\n"
711
710
  sock.close
712
711
 
@@ -719,7 +718,7 @@ class ServerPluginHelperTest < Test::Unit::TestCase
719
718
  test 'raise error if plugin registers write_complete callback for udp' do
720
719
  received = ""
721
720
  errors = []
722
- @d.server_create_udp(:s, PORT, max_bytes: 128) do |data, sock|
721
+ @d.server_create_udp(:s, @port, max_bytes: 128) do |data, sock|
723
722
  received << data
724
723
  begin
725
724
  sock.on(:write_complete){|conn| "" }
@@ -728,7 +727,7 @@ class ServerPluginHelperTest < Test::Unit::TestCase
728
727
  end
729
728
  end
730
729
  sock = UDPSocket.new(Socket::AF_INET)
731
- sock.connect("127.0.0.1", PORT)
730
+ sock.connect("127.0.0.1", @port)
732
731
  sock.write "foo\n"
733
732
  sock.close
734
733
 
@@ -741,7 +740,7 @@ class ServerPluginHelperTest < Test::Unit::TestCase
741
740
  test 'raises error if plugin registers close callback for udp' do
742
741
  received = ""
743
742
  errors = []
744
- @d.server_create_udp(:s, PORT, max_bytes: 128) do |data, sock|
743
+ @d.server_create_udp(:s, @port, max_bytes: 128) do |data, sock|
745
744
  received << data
746
745
  begin
747
746
  sock.on(:close){|d| "" }
@@ -750,7 +749,7 @@ class ServerPluginHelperTest < Test::Unit::TestCase
750
749
  end
751
750
  end
752
751
  sock = UDPSocket.new(Socket::AF_INET)
753
- sock.connect("127.0.0.1", PORT)
752
+ sock.connect("127.0.0.1", @port)
754
753
  sock.write "foo\n"
755
754
  sock.close
756
755
 
@@ -764,10 +763,10 @@ class ServerPluginHelperTest < Test::Unit::TestCase
764
763
  omit "IPv6 unavailable here" unless ipv6_enabled?
765
764
 
766
765
  assert_nothing_raised do
767
- @d.server_create_udp(:s_ipv4_udp, PORT, bind: '0.0.0.0', shared: false, max_bytes: 128) do |data, sock|
766
+ @d.server_create_udp(:s_ipv4_udp, @port, bind: '0.0.0.0', shared: false, max_bytes: 128) do |data, sock|
768
767
  # ...
769
768
  end
770
- @d.server_create_udp(:s_ipv6_udp, PORT, bind: '::', shared: false, max_bytes: 128) do |data, sock|
769
+ @d.server_create_udp(:s_ipv6_udp, @port, bind: '::', shared: false, max_bytes: 128) do |data, sock|
771
770
  # ...
772
771
  end
773
772
  end
@@ -929,16 +928,16 @@ class ServerPluginHelperTest < Test::Unit::TestCase
929
928
  }
930
929
 
931
930
  received = ""
932
- @d.server_create_tls(:s, PORT, tls_options: tls_options) do |data, conn|
931
+ @d.server_create_tls(:s, @port, tls_options: tls_options) do |data, conn|
933
932
  received << data
934
933
  end
935
934
  assert_raise "" do
936
- open_tls_session('127.0.0.1', PORT) do |sock|
935
+ open_tls_session('127.0.0.1', @port) do |sock|
937
936
  sock.post_connection_check('myserver.testing.fluentd.org')
938
937
  # cannot connect ....
939
938
  end
940
939
  end
941
- open_tls_session('127.0.0.1', PORT, verify: false) do |sock|
940
+ open_tls_session('127.0.0.1', @port, verify: false) do |sock|
942
941
  sock.puts "yay"
943
942
  sock.puts "foo"
944
943
  end
@@ -968,16 +967,16 @@ class ServerPluginHelperTest < Test::Unit::TestCase
968
967
  }
969
968
  tls_options[:private_key_passphrase] = private_key_passphrase if private_key_passphrase
970
969
  received = ""
971
- @d.server_create_tls(:s, PORT, tls_options: tls_options) do |data, conn|
970
+ @d.server_create_tls(:s, @port, tls_options: tls_options) do |data, conn|
972
971
  received << data
973
972
  end
974
973
  assert_raise "" do
975
- open_tls_session('127.0.0.1', PORT) do |sock|
974
+ open_tls_session('127.0.0.1', @port) do |sock|
976
975
  sock.post_connection_check('server.testing.fluentd.org')
977
976
  # cannot connect by failing verification without server cert
978
977
  end
979
978
  end
980
- open_tls_session('127.0.0.1', PORT, cert_path: cert_path) do |sock|
979
+ open_tls_session('127.0.0.1', @port, cert_path: cert_path) do |sock|
981
980
  sock.puts "yay"
982
981
  sock.puts "foo"
983
982
  end
@@ -1003,10 +1002,10 @@ class ServerPluginHelperTest < Test::Unit::TestCase
1003
1002
  }
1004
1003
  tls_options[:ca_private_key_passphrase] = ca_key_passphrase if ca_key_passphrase
1005
1004
  received = ""
1006
- @d.server_create_tls(:s, PORT, tls_options: tls_options) do |data, conn|
1005
+ @d.server_create_tls(:s, @port, tls_options: tls_options) do |data, conn|
1007
1006
  received << data
1008
1007
  end
1009
- open_tls_session('127.0.0.1', PORT, cert_path: ca_cert_path) do |sock|
1008
+ open_tls_session('127.0.0.1', @port, cert_path: ca_cert_path) do |sock|
1010
1009
  sock.puts "yay"
1011
1010
  sock.puts "foo"
1012
1011
  end
@@ -1042,10 +1041,10 @@ class ServerPluginHelperTest < Test::Unit::TestCase
1042
1041
  }
1043
1042
  tls_options[:private_key_passphrase] = private_key_passphrase if private_key_passphrase
1044
1043
  received = ""
1045
- @d.server_create_tls(:s, PORT, tls_options: tls_options) do |data, conn|
1044
+ @d.server_create_tls(:s, @port, tls_options: tls_options) do |data, conn|
1046
1045
  received << data
1047
1046
  end
1048
- open_tls_session('127.0.0.1', PORT, cert_path: ca_cert_path) do |sock|
1047
+ open_tls_session('127.0.0.1', @port, cert_path: ca_cert_path) do |sock|
1049
1048
  sock.puts "yay"
1050
1049
  sock.puts "foo"
1051
1050
  end
@@ -1072,10 +1071,10 @@ class ServerPluginHelperTest < Test::Unit::TestCase
1072
1071
  }
1073
1072
  tls_options[:private_key_passphrase] = private_key_passphrase if private_key_passphrase
1074
1073
  received = ""
1075
- @d.server_create_tls(:s, PORT, tls_options: tls_options) do |data, conn|
1074
+ @d.server_create_tls(:s, @port, tls_options: tls_options) do |data, conn|
1076
1075
  received << data
1077
1076
  end
1078
- open_tls_session('127.0.0.1', PORT, cert_path: ca_cert_path) do |sock|
1077
+ open_tls_session('127.0.0.1', @port, cert_path: ca_cert_path) do |sock|
1079
1078
  sock.puts "yay"
1080
1079
  sock.puts "foo"
1081
1080
  end
@@ -1096,16 +1095,16 @@ class ServerPluginHelperTest < Test::Unit::TestCase
1096
1095
  @d.configure(conf); @d.start; @d.after_start
1097
1096
 
1098
1097
  received = ""
1099
- @d.server_create_tls(:s, PORT) do |data, conn|
1098
+ @d.server_create_tls(:s, @port) do |data, conn|
1100
1099
  received << data
1101
1100
  end
1102
1101
  assert_raise "" do
1103
- open_tls_session('127.0.0.1', PORT) do |sock|
1102
+ open_tls_session('127.0.0.1', @port) do |sock|
1104
1103
  sock.post_connection_check('myserver.testing.fluentd.org')
1105
1104
  # cannot connect ....
1106
1105
  end
1107
1106
  end
1108
- open_tls_session('127.0.0.1', PORT, verify: false) do |sock|
1107
+ open_tls_session('127.0.0.1', @port, verify: false) do |sock|
1109
1108
  sock.puts "yay"
1110
1109
  sock.puts "foo"
1111
1110
  end
@@ -1131,16 +1130,16 @@ class ServerPluginHelperTest < Test::Unit::TestCase
1131
1130
  @d.configure(conf); @d.start; @d.after_start
1132
1131
 
1133
1132
  received = ""
1134
- @d.server_create_tls(:s, PORT) do |data, conn|
1133
+ @d.server_create_tls(:s, @port) do |data, conn|
1135
1134
  received << data
1136
1135
  end
1137
1136
  assert_raise "" do
1138
- open_tls_session('127.0.0.1', PORT) do |sock|
1137
+ open_tls_session('127.0.0.1', @port) do |sock|
1139
1138
  sock.post_connection_check('server.testing.fluentd.org')
1140
1139
  # cannot connect by failing verification without server cert
1141
1140
  end
1142
1141
  end
1143
- open_tls_session('127.0.0.1', PORT, cert_path: cert_path) do |sock|
1142
+ open_tls_session('127.0.0.1', @port, cert_path: cert_path) do |sock|
1144
1143
  sock.puts "yay"
1145
1144
  sock.puts "foo"
1146
1145
  end
@@ -1166,10 +1165,10 @@ class ServerPluginHelperTest < Test::Unit::TestCase
1166
1165
  @d.configure(conf); @d.start; @d.after_start
1167
1166
 
1168
1167
  received = ""
1169
- @d.server_create_tls(:s, PORT) do |data, conn|
1168
+ @d.server_create_tls(:s, @port) do |data, conn|
1170
1169
  received << data
1171
1170
  end
1172
- open_tls_session('127.0.0.1', PORT, cert_path: ca_cert_path) do |sock|
1171
+ open_tls_session('127.0.0.1', @port, cert_path: ca_cert_path) do |sock|
1173
1172
  sock.puts "yay"
1174
1173
  sock.puts "foo"
1175
1174
  end
@@ -1199,10 +1198,10 @@ class ServerPluginHelperTest < Test::Unit::TestCase
1199
1198
  @d.configure(conf); @d.start; @d.after_start
1200
1199
 
1201
1200
  received = ""
1202
- @d.server_create_tls(:s, PORT) do |data, conn|
1201
+ @d.server_create_tls(:s, @port) do |data, conn|
1203
1202
  received << data
1204
1203
  end
1205
- open_tls_session('127.0.0.1', PORT, cert_path: ca_cert_path) do |sock|
1204
+ open_tls_session('127.0.0.1', @port, cert_path: ca_cert_path) do |sock|
1206
1205
  sock.puts "yay"
1207
1206
  sock.puts "foo"
1208
1207
  end
@@ -1230,10 +1229,10 @@ class ServerPluginHelperTest < Test::Unit::TestCase
1230
1229
  @d.configure(conf); @d.start; @d.after_start
1231
1230
 
1232
1231
  received = ""
1233
- @d.server_create_tls(:s, PORT) do |data, conn|
1232
+ @d.server_create_tls(:s, @port) do |data, conn|
1234
1233
  received << data
1235
1234
  end
1236
- open_tls_session('127.0.0.1', PORT, cert_path: ca_cert_path) do |sock|
1235
+ open_tls_session('127.0.0.1', @port, cert_path: ca_cert_path) do |sock|
1237
1236
  sock.puts "yay"
1238
1237
  sock.puts "foo"
1239
1238
  end
@@ -1306,7 +1305,7 @@ class ServerPluginHelperTest < Test::Unit::TestCase
1306
1305
 
1307
1306
  test 'can accept all keyword arguments valid for tcp/tls server' do
1308
1307
  assert_nothing_raised do
1309
- @d.server_create_tls(:s, PORT, bind: '127.0.0.1', shared: false, resolve_name: true, linger_timeout: 10, backlog: 500, tls_options: @tls_options, send_keepalive_packet: true) do |data, conn|
1308
+ @d.server_create_tls(:s, @port, bind: '127.0.0.1', shared: false, resolve_name: true, linger_timeout: 10, backlog: 500, tls_options: @tls_options, send_keepalive_packet: true) do |data, conn|
1310
1309
  # ...
1311
1310
  end
1312
1311
  end
@@ -1314,11 +1313,11 @@ class ServerPluginHelperTest < Test::Unit::TestCase
1314
1313
 
1315
1314
  test 'creates a tls server just to read data' do
1316
1315
  received = ""
1317
- @d.server_create_tls(:s, PORT, tls_options: @tls_options) do |data, conn|
1316
+ @d.server_create_tls(:s, @port, tls_options: @tls_options) do |data, conn|
1318
1317
  received << data
1319
1318
  end
1320
1319
  3.times do
1321
- open_tls_session('127.0.0.1', PORT, cert_path: @cert_path) do |sock|
1320
+ open_tls_session('127.0.0.1', @port, cert_path: @cert_path) do |sock|
1322
1321
  sock.puts "yay"
1323
1322
  sock.puts "foo"
1324
1323
  end
@@ -1331,13 +1330,13 @@ class ServerPluginHelperTest < Test::Unit::TestCase
1331
1330
  test 'creates a tls server to read and write data' do
1332
1331
  received = ""
1333
1332
  responses = []
1334
- @d.server_create_tls(:s, PORT, tls_options: @tls_options) do |data, conn|
1333
+ @d.server_create_tls(:s, @port, tls_options: @tls_options) do |data, conn|
1335
1334
  received << data
1336
1335
  conn.write "ack\n"
1337
1336
  end
1338
1337
  3.times do
1339
- # open_tls_session('127.0.0.1', PORT, cert_path: @cert_path, hostname: @default_hostname) do |sock|
1340
- open_tls_session('127.0.0.1', PORT, cert_path: @cert_path) do |sock|
1338
+ # open_tls_session('127.0.0.1', @port, cert_path: @cert_path, hostname: @default_hostname) do |sock|
1339
+ open_tls_session('127.0.0.1', @port, cert_path: @cert_path) do |sock|
1341
1340
  sock.puts "yay"
1342
1341
  sock.puts "foo"
1343
1342
  responses << sock.readline
@@ -1354,13 +1353,13 @@ class ServerPluginHelperTest < Test::Unit::TestCase
1354
1353
 
1355
1354
  received = ""
1356
1355
  responses = []
1357
- @d.server_create_tls(:s, PORT, bind: "::1", tls_options: @tls_options) do |data, conn|
1356
+ @d.server_create_tls(:s, @port, bind: "::1", tls_options: @tls_options) do |data, conn|
1358
1357
  received << data
1359
1358
  conn.write "ack\n"
1360
1359
  end
1361
1360
  3.times do
1362
- # open_tls_session('::1', PORT, cert_path: @cert_path, hostname: @default_hostname) do |sock|
1363
- open_tls_session('::1', PORT, cert_path: @cert_path) do |sock|
1361
+ # open_tls_session('::1', @port, cert_path: @cert_path, hostname: @default_hostname) do |sock|
1362
+ open_tls_session('::1', @port, cert_path: @cert_path) do |sock|
1364
1363
  sock.puts "yay"
1365
1364
  sock.puts "foo"
1366
1365
  responses << sock.readline
@@ -1375,13 +1374,13 @@ class ServerPluginHelperTest < Test::Unit::TestCase
1375
1374
  test 'does not resolve name of client address in default' do
1376
1375
  received = ""
1377
1376
  sources = []
1378
- @d.server_create_tls(:s, PORT, tls_options: @tls_options) do |data, conn|
1377
+ @d.server_create_tls(:s, @port, tls_options: @tls_options) do |data, conn|
1379
1378
  received << data
1380
1379
  sources << conn.remote_host
1381
1380
  end
1382
1381
  3.times do
1383
- # open_tls_session('127.0.0.1', PORT, cert_path: @cert_path, hostname: @default_hostname) do |sock|
1384
- open_tls_session('127.0.0.1', PORT, cert_path: @cert_path) do |sock|
1382
+ # open_tls_session('127.0.0.1', @port, cert_path: @cert_path, hostname: @default_hostname) do |sock|
1383
+ open_tls_session('127.0.0.1', @port, cert_path: @cert_path) do |sock|
1385
1384
  sock.puts "yay"
1386
1385
  end
1387
1386
  end
@@ -1395,13 +1394,13 @@ class ServerPluginHelperTest < Test::Unit::TestCase
1395
1394
 
1396
1395
  received = ""
1397
1396
  sources = []
1398
- @d.server_create_tls(:s, PORT, resolve_name: true, tls_options: @tls_options) do |data, conn|
1397
+ @d.server_create_tls(:s, @port, resolve_name: true, tls_options: @tls_options) do |data, conn|
1399
1398
  received << data
1400
1399
  sources << conn.remote_host
1401
1400
  end
1402
1401
  3.times do
1403
- # open_tls_session('127.0.0.1', PORT, cert_path: @cert_path, hostname: @default_hostname) do |sock|
1404
- open_tls_session('127.0.0.1', PORT, cert_path: @cert_path) do |sock|
1402
+ # open_tls_session('127.0.0.1', @port, cert_path: @cert_path, hostname: @default_hostname) do |sock|
1403
+ open_tls_session('127.0.0.1', @port, cert_path: @cert_path) do |sock|
1405
1404
  sock.puts "yay"
1406
1405
  end
1407
1406
  end
@@ -1417,7 +1416,7 @@ class ServerPluginHelperTest < Test::Unit::TestCase
1417
1416
  test 'raises error if plugin registers data callback for connection object from #server_create' do
1418
1417
  received = ""
1419
1418
  errors = []
1420
- @d.server_create_tls(:s, PORT, tls_options: @tls_options) do |data, conn|
1419
+ @d.server_create_tls(:s, @port, tls_options: @tls_options) do |data, conn|
1421
1420
  received << data
1422
1421
  begin
1423
1422
  conn.data{|d| received << d.upcase }
@@ -1425,7 +1424,7 @@ class ServerPluginHelperTest < Test::Unit::TestCase
1425
1424
  errors << e
1426
1425
  end
1427
1426
  end
1428
- open_tls_session('127.0.0.1', PORT, cert_path: @cert_path) do |sock|
1427
+ open_tls_session('127.0.0.1', @port, cert_path: @cert_path) do |sock|
1429
1428
  sock.puts "foo"
1430
1429
  end
1431
1430
  waiting(10){ sleep 0.1 until received.bytesize == 4 || errors.size == 1 }
@@ -1439,7 +1438,7 @@ class ServerPluginHelperTest < Test::Unit::TestCase
1439
1438
  lines = []
1440
1439
  responses = []
1441
1440
  response_completes = []
1442
- @d.server_create_tls(:s, PORT, tls_options: @tls_options) do |data, conn|
1441
+ @d.server_create_tls(:s, @port, tls_options: @tls_options) do |data, conn|
1443
1442
  conn.on(:write_complete){|c| response_completes << true }
1444
1443
  buffer << data
1445
1444
  if idx = buffer.index("\n")
@@ -1448,7 +1447,7 @@ class ServerPluginHelperTest < Test::Unit::TestCase
1448
1447
  end
1449
1448
  end
1450
1449
  3.times do
1451
- open_tls_session('127.0.0.1', PORT, cert_path: @cert_path) do |sock|
1450
+ open_tls_session('127.0.0.1', @port, cert_path: @cert_path) do |sock|
1452
1451
  sock.write "yay"
1453
1452
  sock.write "foo\n"
1454
1453
  begin
@@ -1469,7 +1468,7 @@ class ServerPluginHelperTest < Test::Unit::TestCase
1469
1468
  buffer = ""
1470
1469
  lines = []
1471
1470
  callback_results = []
1472
- @d.server_create_tls(:s, PORT, tls_options: @tls_options) do |data, conn|
1471
+ @d.server_create_tls(:s, @port, tls_options: @tls_options) do |data, conn|
1473
1472
  conn.on(:close){|c| callback_results << "closed" }
1474
1473
  buffer << data
1475
1474
  if idx = buffer.index("\n")
@@ -1478,7 +1477,7 @@ class ServerPluginHelperTest < Test::Unit::TestCase
1478
1477
  end
1479
1478
  end
1480
1479
  3.times do
1481
- open_tls_session('127.0.0.1', PORT, cert_path: @cert_path) do |sock|
1480
+ open_tls_session('127.0.0.1', @port, cert_path: @cert_path) do |sock|
1482
1481
  sock.write "yay"
1483
1482
  sock.write "foo\n"
1484
1483
  begin
@@ -1499,7 +1498,7 @@ class ServerPluginHelperTest < Test::Unit::TestCase
1499
1498
 
1500
1499
  sub_test_case 'TLS version connection check' do
1501
1500
  test "can't connect with different TLS version" do
1502
- @d.server_create_tls(:s, PORT, tls_options: @tls_options) do |data, conn|
1501
+ @d.server_create_tls(:s, @port, tls_options: @tls_options) do |data, conn|
1503
1502
  end
1504
1503
  if defined?(OpenSSL::SSL::TLS1_3_VERSION)
1505
1504
  version = :'TLS1_3'
@@ -1507,7 +1506,7 @@ class ServerPluginHelperTest < Test::Unit::TestCase
1507
1506
  version = :'TLS1_1'
1508
1507
  end
1509
1508
  assert_raise(OpenSSL::SSL::SSLError, Errno::ECONNRESET) {
1510
- open_tls_session('127.0.0.1', PORT, cert_path: @cert_path, version: version) do |sock|
1509
+ open_tls_session('127.0.0.1', @port, cert_path: @cert_path, version: version) do |sock|
1511
1510
  end
1512
1511
  }
1513
1512
  end
@@ -1523,15 +1522,15 @@ class ServerPluginHelperTest < Test::Unit::TestCase
1523
1522
  end
1524
1523
 
1525
1524
  opts = @tls_options.merge(min_version: min_version, max_version: max_version)
1526
- @d.server_create_tls(:s, PORT, tls_options: opts) do |data, conn|
1525
+ @d.server_create_tls(:s, @port, tls_options: opts) do |data, conn|
1527
1526
  end
1528
1527
  assert_raise(OpenSSL::SSL::SSLError, Errno::ECONNRESET) {
1529
- open_tls_session('127.0.0.1', PORT, cert_path: @cert_path, version: :'TLS1') do |sock|
1528
+ open_tls_session('127.0.0.1', @port, cert_path: @cert_path, version: :'TLS1') do |sock|
1530
1529
  end
1531
1530
  }
1532
1531
  [min_version, max_version].each { |ver|
1533
1532
  assert_nothing_raised {
1534
- open_tls_session('127.0.0.1', PORT, cert_path: @cert_path, version: ver) do |sock|
1533
+ open_tls_session('127.0.0.1', @port, cert_path: @cert_path, version: ver) do |sock|
1535
1534
  end
1536
1535
  }
1537
1536
  }
@@ -1571,7 +1570,7 @@ class ServerPluginHelperTest < Test::Unit::TestCase
1571
1570
  sub_test_case '#server_create_connection' do
1572
1571
  test 'raise error if udp is specified in proto' do
1573
1572
  assert_raise(ArgumentError.new("BUG: cannot create connection for UDP")) do
1574
- @d.server_create_connection(:myserver, PORT, proto: :udp){|c| c }
1573
+ @d.server_create_connection(:myserver, @port, proto: :udp){|c| c }
1575
1574
  end
1576
1575
  end
1577
1576
 
@@ -1586,10 +1585,10 @@ class ServerPluginHelperTest < Test::Unit::TestCase
1586
1585
  test 'raise error if block argument is not specified or too many' do |(proto, kwargs)|
1587
1586
  empty_block = ->(){}
1588
1587
  assert_raise(ArgumentError.new("BUG: block must have just one argument")) do
1589
- @d.server_create_connection(:myserver, PORT, proto: proto, **kwargs, &empty_block)
1588
+ @d.server_create_connection(:myserver, @port, proto: proto, **kwargs, &empty_block)
1590
1589
  end
1591
1590
  assert_raise(ArgumentError.new("BUG: block must have just one argument")) do
1592
- @d.server_create_connection(:myserver, PORT, proto: proto, **kwargs){|conn, what_is_this| [conn, what_is_this] }
1591
+ @d.server_create_connection(:myserver, @port, proto: proto, **kwargs){|conn, what_is_this| [conn, what_is_this] }
1593
1592
  end
1594
1593
  end
1595
1594
 
@@ -1597,14 +1596,14 @@ class ServerPluginHelperTest < Test::Unit::TestCase
1597
1596
  test 'does not resolve name of client address in default' do |(proto, kwargs)|
1598
1597
  received = ""
1599
1598
  sources = []
1600
- @d.server_create_connection(:s, PORT, proto: proto, **kwargs) do |conn|
1599
+ @d.server_create_connection(:s, @port, proto: proto, **kwargs) do |conn|
1601
1600
  sources << conn.remote_host
1602
1601
  conn.data do |d|
1603
1602
  received << d
1604
1603
  end
1605
1604
  end
1606
1605
  3.times do
1607
- open_client(proto, "127.0.0.1", PORT) do |sock|
1606
+ open_client(proto, "127.0.0.1", @port) do |sock|
1608
1607
  sock.puts "yay"
1609
1608
  end
1610
1609
  end
@@ -1619,14 +1618,14 @@ class ServerPluginHelperTest < Test::Unit::TestCase
1619
1618
 
1620
1619
  received = ""
1621
1620
  sources = []
1622
- @d.server_create_connection(:s, PORT, proto: proto, resolve_name: true, **kwargs) do |conn|
1621
+ @d.server_create_connection(:s, @port, proto: proto, resolve_name: true, **kwargs) do |conn|
1623
1622
  sources << conn.remote_host
1624
1623
  conn.data do |d|
1625
1624
  received << d
1626
1625
  end
1627
1626
  end
1628
1627
  3.times do
1629
- open_client(proto, "127.0.0.1", PORT) do |sock|
1628
+ open_client(proto, "127.0.0.1", @port) do |sock|
1630
1629
  sock.puts "yay"
1631
1630
  end
1632
1631
  end
@@ -1639,7 +1638,7 @@ class ServerPluginHelperTest < Test::Unit::TestCase
1639
1638
  test 'creates a server to provide connection, which can read, write and close' do |(proto, kwargs)|
1640
1639
  lines = []
1641
1640
  buffer = ""
1642
- @d.server_create_connection(:s, PORT, proto: proto, **kwargs) do |conn|
1641
+ @d.server_create_connection(:s, @port, proto: proto, **kwargs) do |conn|
1643
1642
  conn.data do |d|
1644
1643
  buffer << d
1645
1644
  if buffer == "x"
@@ -1655,7 +1654,7 @@ class ServerPluginHelperTest < Test::Unit::TestCase
1655
1654
  replied = []
1656
1655
  disconnecteds = []
1657
1656
  3.times do |i|
1658
- open_client(proto, "127.0.0.1", PORT) do |sock|
1657
+ open_client(proto, "127.0.0.1", @port) do |sock|
1659
1658
  sock.puts "yay"
1660
1659
  while line = sock.readline
1661
1660
  replied << line
@@ -1691,7 +1690,7 @@ class ServerPluginHelperTest < Test::Unit::TestCase
1691
1690
  buffer = ""
1692
1691
  written = 0
1693
1692
  closed = 0
1694
- @d.server_create_connection(:s, PORT, proto: proto, **kwargs) do |conn|
1693
+ @d.server_create_connection(:s, @port, proto: proto, **kwargs) do |conn|
1695
1694
  conn.on(:write_complete){|_conn| written += 1 }
1696
1695
  conn.on(:close){|_conn| closed += 1 }
1697
1696
  conn.on(:data) do |d|
@@ -1704,7 +1703,7 @@ class ServerPluginHelperTest < Test::Unit::TestCase
1704
1703
  end
1705
1704
  replied = []
1706
1705
  3.times do
1707
- open_client(proto, "127.0.0.1", PORT) do |sock|
1706
+ open_client(proto, "127.0.0.1", @port) do |sock|
1708
1707
  sock.puts "yay"
1709
1708
  while line = sock.readline
1710
1709
  replied << line
@@ -1725,14 +1724,14 @@ class ServerPluginHelperTest < Test::Unit::TestCase
1725
1724
  test 'creates a server, and does not leak connections' do |(proto, kwargs)|
1726
1725
  buffer = ""
1727
1726
  closed = 0
1728
- @d.server_create_connection(:s, PORT, proto: proto, **kwargs) do |conn|
1727
+ @d.server_create_connection(:s, @port, proto: proto, **kwargs) do |conn|
1729
1728
  conn.on(:close){|_c| closed += 1 }
1730
1729
  conn.on(:data) do |d|
1731
1730
  buffer << d
1732
1731
  end
1733
1732
  end
1734
1733
  3.times do
1735
- open_client(proto, "127.0.0.1", PORT) do |sock|
1734
+ open_client(proto, "127.0.0.1", @port) do |sock|
1736
1735
  sock.puts "yay"
1737
1736
  end
1738
1737
  end
@@ -1745,7 +1744,7 @@ class ServerPluginHelperTest < Test::Unit::TestCase
1745
1744
  test 'will refuse more connect requests after stop, but read data from sockets already connected, in non-shared server' do |(proto, kwargs)|
1746
1745
  connected = false
1747
1746
  begin
1748
- open_client(proto, "127.0.0.1", PORT) do |sock|
1747
+ open_client(proto, "127.0.0.1", @port) do |sock|
1749
1748
  # expected behavior is connection refused...
1750
1749
  connected = true
1751
1750
  end
@@ -1755,7 +1754,7 @@ class ServerPluginHelperTest < Test::Unit::TestCase
1755
1754
  assert_false connected
1756
1755
 
1757
1756
  received = ""
1758
- @d.server_create_connection(:s, PORT, proto: proto, shared: false, **kwargs) do |conn|
1757
+ @d.server_create_connection(:s, @port, proto: proto, shared: false, **kwargs) do |conn|
1759
1758
  conn.on(:data) do |data|
1760
1759
  received << data
1761
1760
  conn.write "ack\n"
@@ -1763,7 +1762,7 @@ class ServerPluginHelperTest < Test::Unit::TestCase
1763
1762
  end
1764
1763
 
1765
1764
  th0 = Thread.new do
1766
- open_client(proto, "127.0.0.1", PORT) do |sock|
1765
+ open_client(proto, "127.0.0.1", @port) do |sock|
1767
1766
  sock.puts "yay"
1768
1767
  sock.readline
1769
1768
  end
@@ -1777,7 +1776,7 @@ class ServerPluginHelperTest < Test::Unit::TestCase
1777
1776
  ending = false
1778
1777
 
1779
1778
  th1 = Thread.new do
1780
- open_client(proto, "127.0.0.1", PORT) do |sock|
1779
+ open_client(proto, "127.0.0.1", @port) do |sock|
1781
1780
  sleeping = true
1782
1781
  sleep 0.1 until stopped
1783
1782
  sock.puts "yay"
@@ -1800,7 +1799,7 @@ class ServerPluginHelperTest < Test::Unit::TestCase
1800
1799
 
1801
1800
  th2 = Thread.new do
1802
1801
  begin
1803
- open_client(proto, "127.0.0.1", PORT) do |sock|
1802
+ open_client(proto, "127.0.0.1", @port) do |sock|
1804
1803
  sock.puts "foo"
1805
1804
  end
1806
1805
  false # failed