fluentd 1.12.1-x86-mingw32 → 1.13.1-x86-mingw32

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.

Files changed (87) hide show
  1. checksums.yaml +4 -4
  2. data/.deepsource.toml +13 -0
  3. data/.github/ISSUE_TEMPLATE/config.yml +2 -2
  4. data/.github/workflows/linux-test.yaml +36 -0
  5. data/.github/workflows/{build.yaml → macos-test.yaml} +8 -7
  6. data/.github/workflows/windows-test.yaml +46 -0
  7. data/.gitlab-ci.yml +19 -19
  8. data/CHANGELOG.md +163 -0
  9. data/CONTRIBUTING.md +2 -2
  10. data/MAINTAINERS.md +5 -2
  11. data/README.md +6 -3
  12. data/example/counter.conf +1 -1
  13. data/fluentd.gemspec +4 -2
  14. data/lib/fluent/command/bundler_injection.rb +1 -1
  15. data/lib/fluent/command/cat.rb +19 -4
  16. data/lib/fluent/command/fluentd.rb +1 -2
  17. data/lib/fluent/command/plugin_config_formatter.rb +2 -1
  18. data/lib/fluent/command/plugin_generator.rb +31 -1
  19. data/lib/fluent/compat/parser.rb +2 -2
  20. data/lib/fluent/config/section.rb +6 -1
  21. data/lib/fluent/config/types.rb +2 -2
  22. data/lib/fluent/event.rb +3 -13
  23. data/lib/fluent/load.rb +0 -1
  24. data/lib/fluent/log.rb +1 -0
  25. data/lib/fluent/plugin/file_wrapper.rb +49 -4
  26. data/lib/fluent/plugin/formatter_ltsv.rb +2 -2
  27. data/lib/fluent/plugin/in_http.rb +11 -1
  28. data/lib/fluent/plugin/in_monitor_agent.rb +1 -1
  29. data/lib/fluent/plugin/in_tail.rb +140 -41
  30. data/lib/fluent/plugin/in_tail/position_file.rb +15 -1
  31. data/lib/fluent/plugin/out_copy.rb +18 -5
  32. data/lib/fluent/plugin/out_exec_filter.rb +3 -3
  33. data/lib/fluent/plugin/out_forward.rb +75 -61
  34. data/lib/fluent/plugin/output.rb +11 -9
  35. data/lib/fluent/plugin/parser_csv.rb +2 -2
  36. data/lib/fluent/plugin/parser_syslog.rb +2 -2
  37. data/lib/fluent/plugin/service_discovery.rb +0 -15
  38. data/lib/fluent/plugin/storage_local.rb +4 -4
  39. data/lib/fluent/plugin_helper/http_server/router.rb +1 -1
  40. data/lib/fluent/plugin_helper/server.rb +4 -2
  41. data/lib/fluent/plugin_helper/service_discovery.rb +39 -1
  42. data/lib/fluent/plugin_helper/service_discovery/manager.rb +11 -5
  43. data/lib/fluent/plugin_helper/socket_option.rb +2 -2
  44. data/lib/fluent/supervisor.rb +16 -1
  45. data/lib/fluent/system_config.rb +14 -0
  46. data/lib/fluent/time.rb +57 -1
  47. data/lib/fluent/version.rb +1 -1
  48. data/templates/new_gem/fluent-plugin.gemspec.erb +3 -3
  49. data/test/command/test_cat.rb +99 -0
  50. data/test/command/test_fluentd.rb +8 -0
  51. data/test/config/test_configurable.rb +1 -1
  52. data/test/config/test_section.rb +9 -0
  53. data/test/config/test_system_config.rb +46 -0
  54. data/test/plugin/in_tail/test_io_handler.rb +4 -4
  55. data/test/plugin/in_tail/test_position_file.rb +58 -4
  56. data/test/plugin/test_file_wrapper.rb +115 -0
  57. data/test/plugin/test_in_exec.rb +1 -1
  58. data/test/plugin/test_in_forward.rb +59 -83
  59. data/test/plugin/test_in_http.rb +58 -40
  60. data/test/plugin/test_in_syslog.rb +66 -56
  61. data/test/plugin/test_in_tail.rb +298 -26
  62. data/test/plugin/test_in_tcp.rb +45 -32
  63. data/test/plugin/test_in_udp.rb +47 -33
  64. data/test/plugin/test_out_copy.rb +87 -0
  65. data/test/plugin/test_out_forward.rb +198 -91
  66. data/test/plugin/test_out_http.rb +1 -1
  67. data/test/plugin/test_out_stream.rb +18 -8
  68. data/test/plugin/test_output.rb +15 -3
  69. data/test/plugin/test_output_as_buffered_backup.rb +2 -0
  70. data/test/plugin/test_parser_csv.rb +14 -0
  71. data/test/plugin/test_parser_syslog.rb +14 -0
  72. data/test/plugin_helper/http_server/test_route.rb +1 -1
  73. data/test/plugin_helper/service_discovery/test_manager.rb +1 -1
  74. data/test/plugin_helper/test_child_process.rb +6 -3
  75. data/test/plugin_helper/test_http_server_helper.rb +34 -27
  76. data/test/plugin_helper/test_server.rb +144 -139
  77. data/test/plugin_helper/test_service_discovery.rb +74 -14
  78. data/test/plugin_helper/test_socket.rb +16 -9
  79. data/test/test_config.rb +2 -1
  80. data/test/test_event.rb +16 -0
  81. data/test/test_formatter.rb +30 -0
  82. data/test/test_output.rb +2 -2
  83. data/test/test_supervisor.rb +35 -0
  84. data/test/test_time_parser.rb +109 -0
  85. metadata +55 -11
  86. data/.travis.yml +0 -77
  87. data/appveyor.yml +0 -31
@@ -127,7 +127,7 @@ class HTTPOutputTest < Test::Unit::TestCase
127
127
  now = Time.now
128
128
  started = false
129
129
  until started
130
- raise "Server not started" if (now - Time.now > 10.0)
130
+ raise "Server not started" if (Time.now - now > 10.0)
131
131
  begin
132
132
  http_client { |c| c.request_get('/') }
133
133
  started = true
@@ -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
@@ -390,6 +390,18 @@ class OutputTest < Test::Unit::TestCase
390
390
  assert { logs.none? { |log| log.include?("${chunk_id}") } }
391
391
  end
392
392
 
393
+ test '#extract_placeholders does not log for ${chunk_id} placeholder (with @chunk_keys)' do
394
+ @i.configure(config_element('ROOT', '', {}, [config_element('buffer', 'key1')]))
395
+ tmpl = "/mypath/${chunk_id}/${key1}/tail"
396
+ t = event_time('2016-04-11 20:30:00 +0900')
397
+ v = {key1: "value1", key2: "value2"}
398
+ c = create_chunk(timekey: t, tag: 'fluentd.test.output', variables: v)
399
+ @i.log.out.logs.clear
400
+ @i.extract_placeholders(tmpl, c)
401
+ logs = @i.log.out.logs
402
+ assert { logs.none? { |log| log.include?("${chunk_id}") } }
403
+ end
404
+
393
405
  test '#extract_placeholders logs warn message with not replaced key' do
394
406
  @i.configure(config_element('ROOT', '', {}, [config_element('buffer', '')]))
395
407
  tmpl = "/mypath/${key1}/test"
@@ -868,7 +880,7 @@ class OutputTest < Test::Unit::TestCase
868
880
  test "Warn if primary type is different from secondary type and either primary or secondary has custom_format" do
869
881
  o = create_output(:buffered)
870
882
  mock(o.log).warn("Use different plugin for secondary. Check the plugin works with primary like secondary_file",
871
- { primary: o.class.to_s, secondary: "Fluent::Plugin::TestOutput" })
883
+ primary: o.class.to_s, secondary: "Fluent::Plugin::TestOutput")
872
884
 
873
885
  o.configure(config_element('ROOT','',{},[config_element('secondary','',{'@type'=>'test', 'name' => "cool"})]))
874
886
  assert_not_nil o.instance_variable_get(:@secondary)
@@ -877,7 +889,7 @@ class OutputTest < Test::Unit::TestCase
877
889
  test "don't warn if primary type is the same as secondary type" do
878
890
  o = Fluent::Plugin::TestOutput.new
879
891
  mock(o.log).warn("Use different plugin for secondary. Check the plugin works with primary like secondary_file",
880
- { primary: o.class.to_s, secondary: "Fluent::Plugin::TestOutput" }).never
892
+ primary: o.class.to_s, secondary: "Fluent::Plugin::TestOutput" ).never
881
893
 
882
894
  o.configure(config_element('ROOT','',{'name' => "cool2"},
883
895
  [config_element('secondary','',{'@type'=>'test', 'name' => "cool"}),
@@ -889,7 +901,7 @@ class OutputTest < Test::Unit::TestCase
889
901
  test "don't warn if primary type is different from secondary type and both don't have custom_format" do
890
902
  o = create_output(:standard)
891
903
  mock(o.log).warn("Use different plugin for secondary. Check the plugin works with primary like secondary_file",
892
- { primary: o.class.to_s, secondary: "Fluent::Plugin::TestOutput" }).never
904
+ primary: o.class.to_s, secondary: "Fluent::Plugin::TestOutput").never
893
905
 
894
906
  o.configure(config_element('ROOT','',{},[config_element('secondary','',{'@type'=>'test', 'name' => "cool"})]))
895
907
  assert_not_nil o.instance_variable_get(:@secondary)
@@ -173,6 +173,8 @@ class BufferedOutputBackupTest < Test::Unit::TestCase
173
173
  waiting(5) {
174
174
  target_dir = File.join(File.dirname(target_file), "*")
175
175
  while Dir.glob(target_dir).size.zero?
176
+ # Avoid to lose globbed entries on Windows in busy loop
177
+ sleep 0.1 if Fluent.windows?
176
178
  end
177
179
  }
178
180
  end
@@ -183,4 +183,18 @@ class CSVParserTest < ::Test::Unit::TestCase
183
183
  # And more...
184
184
  end
185
185
  end
186
+
187
+ # "parser_type" config shouldn't hide Fluent::Plugin::Parser#plugin_type
188
+ # https://github.com/fluent/fluentd/issues/3296
189
+ data('normal' => :normal, 'fast' => :fast)
190
+ def test_parser_type_method(engine)
191
+ d = create_driver('keys' => '["time"]','time_key' => 'time', 'parser_type' => engine.to_s)
192
+ assert_equal(:text_per_line, d.instance.parser_type)
193
+ end
194
+
195
+ data('normal' => :normal, 'fast' => :fast)
196
+ def test_parser_engine(engine)
197
+ d = create_driver('keys' => '["time"]', 'time_key' => 'time', 'parser_engine' => engine.to_s)
198
+ assert_equal(engine, d.instance.parser_engine)
199
+ end
186
200
  end
@@ -633,4 +633,18 @@ class SyslogParserTest < ::Test::Unit::TestCase
633
633
  end
634
634
  end
635
635
  end
636
+
637
+ # "parser_type" config shouldn't hide Fluent::Plugin::Parser#plugin_type
638
+ # https://github.com/fluent/fluentd/issues/3296
639
+ data('regexp' => :regexp, 'fast' => :string)
640
+ def test_parser_type_method(engine)
641
+ @parser.configure({'parser_type' => engine.to_s})
642
+ assert_equal(:text_per_line, @parser.instance.parser_type)
643
+ end
644
+
645
+ data('regexp' => :regexp, 'string' => :string)
646
+ def test_parser_engine(engine)
647
+ d = @parser.configure({'parser_engine' => engine.to_s})
648
+ assert_equal(engine, @parser.instance.parser_engine)
649
+ end
636
650
  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
@@ -71,7 +71,7 @@ class TestServiceDiscoveryManager < ::Test::Unit::TestCase
71
71
  test 'if new service added and deleted' do
72
72
  sdm = Fluent::PluginHelper::ServiceDiscovery::Manager.new(log: $log)
73
73
  t = TestSdPlugin.new
74
- mock(Fluent::Plugin).new_sd(:sd_test, anything) { t }
74
+ mock(Fluent::Plugin).new_sd(:sd_test, parent: anything) { t }
75
75
  sdm.configure([{ type: :sd_test, conf: config_element('service_discovery', '', {})}])
76
76
  sdm.start
77
77
 
@@ -1,3 +1,4 @@
1
+ # coding: utf-8
1
2
  require_relative '../helper'
2
3
  require 'fluent/plugin_helper/child_process'
3
4
  require 'fluent/plugin/base'
@@ -269,10 +270,12 @@ class ChildProcessTest < Test::Unit::TestCase
269
270
  Timeout.timeout(TEST_DEADLOCK_TIMEOUT) do
270
271
  ran = false
271
272
  @d.child_process_execute(:t4, "ruby -e 'Signal.trap(:TERM, nil); while sleep 0.1; puts 1; STDOUT.flush rescue nil; end'", mode: [:read]) do |io|
272
- m.lock
273
- ran = true
274
273
  begin
275
274
  while line = io.readline
275
+ unless ran
276
+ m.lock
277
+ ran = true
278
+ end
276
279
  ary << line
277
280
  end
278
281
  rescue
@@ -557,7 +560,7 @@ class ChildProcessTest < Test::Unit::TestCase
557
560
  proc_lines = []
558
561
  Timeout.timeout(TEST_DEADLOCK_TIMEOUT) do
559
562
  ran = false
560
- @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|
561
564
  m.lock
562
565
  ran = true
563
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
@@ -354,8 +361,8 @@ class HttpHelperTest < Test::Unit::TestCase
354
361
  watcher.should_receive(:stop).once
355
362
  end
356
363
 
357
- stub(Fluent::PluginHelper::HttpServer::Server).new(anything) { server }
358
- driver.http_server_create_http_server(:http_server_helper_test, addr: '127.0.0.1', port: PORT, logger: NULL_LOGGER) do
364
+ stub(Fluent::PluginHelper::HttpServer::Server).new(addr: anything, port: anything, logger: anything, default_app: anything) { server }
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,10 +231,16 @@ 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
- assert_raise(ArgumentError.new("BUG: send_keepalive_packet is available for tcp")) do
238
- @d.__send__(m, :myserver, PORT, proto: proto, send_keepalive_packet: true){|x| x }
236
+ end
237
+
238
+ data(
239
+ 'server_create udp' => [:server_create, :udp],
240
+ )
241
+ test 'raise error if tcp/tls send_keepalive_packet option is specified for udp' do |(m, proto)|
242
+ assert_raise(ArgumentError.new("BUG: send_keepalive_packet is available for tcp/tls")) do
243
+ @d.__send__(m, :myserver, @port, proto: proto, send_keepalive_packet: true){|x| x }
239
244
  end
240
245
  end
241
246
 
@@ -248,7 +253,7 @@ class ServerPluginHelperTest < Test::Unit::TestCase
248
253
  )
249
254
  test 'raise error if tls options specified for tcp/udp/unix' do |(m, proto, kwargs)|
250
255
  assert_raise(ArgumentError.new("BUG: tls_options is available only for tls")) do
251
- @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 }
252
257
  end
253
258
  end
254
259
 
@@ -260,7 +265,7 @@ class ServerPluginHelperTest < Test::Unit::TestCase
260
265
  'server_create_connection tls' => [:server_create_connection, :tls, {tls_options: {insecure: true}}],
261
266
  )
262
267
  test 'can bind specified IPv4 address' do |(m, proto, kwargs)|
263
- @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 }
264
269
  assert_equal "127.0.0.1", @d._servers.first.bind
265
270
  assert_equal "127.0.0.1", @d._servers.first.server.instance_eval{ instance_variable_defined?(:@listen_socket) ? @listen_socket : @_io }.addr[3]
266
271
  end
@@ -274,7 +279,7 @@ class ServerPluginHelperTest < Test::Unit::TestCase
274
279
  )
275
280
  test 'can bind specified IPv6 address' do |(m, proto, kwargs)| # if available
276
281
  omit "IPv6 unavailable here" unless ipv6_enabled?
277
- @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 }
278
283
  assert_equal "::1", @d._servers.first.bind
279
284
  assert_equal "::1", @d._servers.first.server.instance_eval{ instance_variable_defined?(:@listen_socket) ? @listen_socket : @_io }.addr[3]
280
285
  end
@@ -293,8 +298,8 @@ class ServerPluginHelperTest < Test::Unit::TestCase
293
298
  d2 = Dummy.new; d2.start; d2.after_start
294
299
 
295
300
  assert_nothing_raised do
296
- @d.__send__(m, :myserver, PORT, proto: proto, **kwargs){|x| x }
297
- 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 }
298
303
  end
299
304
  ensure
300
305
  d2.stop; d2.before_shutdown; d2.shutdown; d2.after_shutdown; d2.close; d2.terminate
@@ -317,10 +322,10 @@ class ServerPluginHelperTest < Test::Unit::TestCase
317
322
  d2 = Dummy.new; d2.start; d2.after_start
318
323
 
319
324
  assert_nothing_raised do
320
- @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 }
321
326
  end
322
327
  assert_raise(Errno::EADDRINUSE, Errno::EACCES) do
323
- d2.__send__(m, :myserver, PORT, proto: proto, **kwargs){|x| x }
328
+ d2.__send__(m, :myserver, @port, proto: proto, **kwargs){|x| x }
324
329
  end
325
330
  ensure
326
331
  d2.stop; d2.before_shutdown; d2.shutdown; d2.after_shutdown; d2.close; d2.terminate
@@ -337,15 +342,15 @@ class ServerPluginHelperTest < Test::Unit::TestCase
337
342
  )
338
343
  test 'raise error if block argument is not specified or too many' do |(proto, kwargs)|
339
344
  assert_raise(ArgumentError.new("BUG: block must have 1 or 2 arguments")) do
340
- @d.server_create(:myserver, PORT, proto: proto, **kwargs){ 1 }
345
+ @d.server_create(:myserver, @port, proto: proto, **kwargs){ 1 }
341
346
  end
342
347
  assert_raise(ArgumentError.new("BUG: block must have 1 or 2 arguments")) do
343
- @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 }
344
349
  end
345
350
  end
346
351
 
347
352
  test 'creates udp server if specified in proto' do
348
- @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 }
349
354
 
350
355
  created_server_info = @d._servers.first
351
356
  assert_equal :udp, created_server_info.proto
@@ -357,7 +362,7 @@ class ServerPluginHelperTest < Test::Unit::TestCase
357
362
  sub_test_case '#server_create_tcp' do
358
363
  test 'can accept all keyword arguments valid for tcp server' do
359
364
  assert_nothing_raised do
360
- @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|
361
366
  # ...
362
367
  end
363
368
  end
@@ -365,11 +370,11 @@ class ServerPluginHelperTest < Test::Unit::TestCase
365
370
 
366
371
  test 'creates a tcp server just to read data' do
367
372
  received = ""
368
- @d.server_create_tcp(:s, PORT) do |data|
373
+ @d.server_create_tcp(:s, @port) do |data|
369
374
  received << data
370
375
  end
371
376
  3.times do
372
- sock = TCPSocket.new("127.0.0.1", PORT)
377
+ sock = TCPSocket.new("127.0.0.1", @port)
373
378
  sock.puts "yay"
374
379
  sock.puts "foo"
375
380
  sock.close
@@ -381,12 +386,12 @@ class ServerPluginHelperTest < Test::Unit::TestCase
381
386
  test 'creates a tcp server to read and write data' do
382
387
  received = ""
383
388
  responses = []
384
- @d.server_create_tcp(:s, PORT) do |data, conn|
389
+ @d.server_create_tcp(:s, @port) do |data, conn|
385
390
  received << data
386
391
  conn.write "ack\n"
387
392
  end
388
393
  3.times do
389
- TCPSocket.open("127.0.0.1", PORT) do |sock|
394
+ TCPSocket.open("127.0.0.1", @port) do |sock|
390
395
  sock.puts "yay"
391
396
  sock.puts "foo"
392
397
  responses << sock.readline
@@ -402,12 +407,12 @@ class ServerPluginHelperTest < Test::Unit::TestCase
402
407
 
403
408
  received = ""
404
409
  responses = []
405
- @d.server_create_tcp(:s, PORT, bind: "::1") do |data, conn|
410
+ @d.server_create_tcp(:s, @port, bind: "::1") do |data, conn|
406
411
  received << data
407
412
  conn.write "ack\n"
408
413
  end
409
414
  3.times do
410
- TCPSocket.open("::1", PORT) do |sock|
415
+ TCPSocket.open("::1", @port) do |sock|
411
416
  sock.puts "yay"
412
417
  sock.puts "foo"
413
418
  responses << sock.readline
@@ -421,12 +426,12 @@ class ServerPluginHelperTest < Test::Unit::TestCase
421
426
  test 'does not resolve name of client address in default' do
422
427
  received = ""
423
428
  sources = []
424
- @d.server_create_tcp(:s, PORT) do |data, conn|
429
+ @d.server_create_tcp(:s, @port) do |data, conn|
425
430
  received << data
426
431
  sources << conn.remote_host
427
432
  end
428
433
  3.times do
429
- TCPSocket.open("127.0.0.1", PORT) do |sock|
434
+ TCPSocket.open("127.0.0.1", @port) do |sock|
430
435
  sock.puts "yay"
431
436
  end
432
437
  end
@@ -440,12 +445,12 @@ class ServerPluginHelperTest < Test::Unit::TestCase
440
445
 
441
446
  received = ""
442
447
  sources = []
443
- @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|
444
449
  received << data
445
450
  sources << conn.remote_host
446
451
  end
447
452
  3.times do
448
- TCPSocket.open("127.0.0.1", PORT) do |sock|
453
+ TCPSocket.open("127.0.0.1", @port) do |sock|
449
454
  sock.puts "yay"
450
455
  end
451
456
  end
@@ -461,7 +466,7 @@ class ServerPluginHelperTest < Test::Unit::TestCase
461
466
  test 'raises error if plugin registers data callback for connection object from #server_create' do
462
467
  received = ""
463
468
  errors = []
464
- @d.server_create_tcp(:s, PORT) do |data, conn|
469
+ @d.server_create_tcp(:s, @port) do |data, conn|
465
470
  received << data
466
471
  begin
467
472
  conn.data{|d| received << d.upcase }
@@ -469,7 +474,7 @@ class ServerPluginHelperTest < Test::Unit::TestCase
469
474
  errors << e
470
475
  end
471
476
  end
472
- TCPSocket.open("127.0.0.1", PORT) do |sock|
477
+ TCPSocket.open("127.0.0.1", @port) do |sock|
473
478
  sock.puts "foo"
474
479
  end
475
480
  waiting(10){ sleep 0.1 until received.bytesize == 4 || errors.size == 1 }
@@ -483,7 +488,7 @@ class ServerPluginHelperTest < Test::Unit::TestCase
483
488
  lines = []
484
489
  responses = []
485
490
  response_completes = []
486
- @d.server_create_tcp(:s, PORT) do |data, conn|
491
+ @d.server_create_tcp(:s, @port) do |data, conn|
487
492
  conn.on(:write_complete){|c| response_completes << true }
488
493
  buffer << data
489
494
  if idx = buffer.index("\n")
@@ -492,7 +497,7 @@ class ServerPluginHelperTest < Test::Unit::TestCase
492
497
  end
493
498
  end
494
499
  3.times do
495
- TCPSocket.open("127.0.0.1", PORT) do |sock|
500
+ TCPSocket.open("127.0.0.1", @port) do |sock|
496
501
  sock.write "yay"
497
502
  sock.write "foo\n"
498
503
  begin
@@ -513,7 +518,7 @@ class ServerPluginHelperTest < Test::Unit::TestCase
513
518
  buffer = ""
514
519
  lines = []
515
520
  callback_results = []
516
- @d.server_create_tcp(:s, PORT) do |data, conn|
521
+ @d.server_create_tcp(:s, @port) do |data, conn|
517
522
  conn.on(:close){|c| callback_results << "closed" }
518
523
  buffer << data
519
524
  if idx = buffer.index("\n")
@@ -522,7 +527,7 @@ class ServerPluginHelperTest < Test::Unit::TestCase
522
527
  end
523
528
  end
524
529
  3.times do
525
- TCPSocket.open("127.0.0.1", PORT) do |sock|
530
+ TCPSocket.open("127.0.0.1", @port) do |sock|
526
531
  sock.write "yay"
527
532
  sock.write "foo\n"
528
533
  begin
@@ -545,10 +550,10 @@ class ServerPluginHelperTest < Test::Unit::TestCase
545
550
  omit "IPv6 unavailable here" unless ipv6_enabled?
546
551
 
547
552
  assert_nothing_raised do
548
- @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|
549
554
  # ...
550
555
  end
551
- @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|
552
557
  # ...
553
558
  end
554
559
  end
@@ -558,7 +563,7 @@ class ServerPluginHelperTest < Test::Unit::TestCase
558
563
  sub_test_case '#server_create_udp' do
559
564
  test 'can accept all keyword arguments valid for udp server' do
560
565
  assert_nothing_raised do
561
- @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|
562
567
  # ...
563
568
  end
564
569
  end
@@ -566,14 +571,14 @@ class ServerPluginHelperTest < Test::Unit::TestCase
566
571
 
567
572
  test 'creates a udp server just to read data' do
568
573
  received = ""
569
- @d.server_create_udp(:s, PORT, max_bytes: 128) do |data|
574
+ @d.server_create_udp(:s, @port, max_bytes: 128) do |data|
570
575
  received << data
571
576
  end
572
577
  bind_port = unused_port(protocol: :udp, bind: "127.0.0.1")
573
578
  3.times do
574
579
  sock = UDPSocket.new(Socket::AF_INET)
575
580
  sock.bind("127.0.0.1", bind_port)
576
- sock.connect("127.0.0.1", PORT)
581
+ sock.connect("127.0.0.1", @port)
577
582
  sock.puts "yay"
578
583
  sock.puts "foo"
579
584
  sock.close
@@ -585,7 +590,7 @@ class ServerPluginHelperTest < Test::Unit::TestCase
585
590
  test 'creates a udp server to read and write data' do
586
591
  received = ""
587
592
  responses = []
588
- @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|
589
594
  received << data
590
595
  sock.write "ack\n"
591
596
  end
@@ -594,7 +599,7 @@ class ServerPluginHelperTest < Test::Unit::TestCase
594
599
  begin
595
600
  sock = UDPSocket.new(Socket::AF_INET)
596
601
  sock.bind("127.0.0.1", bind_port)
597
- sock.connect("127.0.0.1", PORT)
602
+ sock.connect("127.0.0.1", @port)
598
603
  th = Thread.new do
599
604
  while true
600
605
  begin
@@ -625,7 +630,7 @@ class ServerPluginHelperTest < Test::Unit::TestCase
625
630
 
626
631
  received = ""
627
632
  responses = []
628
- @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|
629
634
  received << data
630
635
  sock.write "ack\n"
631
636
  end
@@ -638,7 +643,7 @@ class ServerPluginHelperTest < Test::Unit::TestCase
638
643
  responses << sock.recv(16)
639
644
  true
640
645
  end
641
- sock.connect("::1", PORT)
646
+ sock.connect("::1", @port)
642
647
  sock.write "yay\nfoo\n"
643
648
  th.join(5)
644
649
  ensure
@@ -653,13 +658,13 @@ class ServerPluginHelperTest < Test::Unit::TestCase
653
658
  test 'does not resolve name of client address in default' do
654
659
  received = ""
655
660
  sources = []
656
- @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|
657
662
  received << data
658
663
  sources << sock.remote_host
659
664
  end
660
665
  3.times do
661
666
  sock = UDPSocket.new(Socket::AF_INET)
662
- sock.connect("127.0.0.1", PORT)
667
+ sock.connect("127.0.0.1", @port)
663
668
  sock.puts "yay"
664
669
  sock.close
665
670
  end
@@ -673,13 +678,13 @@ class ServerPluginHelperTest < Test::Unit::TestCase
673
678
 
674
679
  received = ""
675
680
  sources = []
676
- @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|
677
682
  received << data
678
683
  sources << sock.remote_host
679
684
  end
680
685
  3.times do
681
686
  sock = UDPSocket.new(Socket::AF_INET)
682
- sock.connect("127.0.0.1", PORT)
687
+ sock.connect("127.0.0.1", @port)
683
688
  sock.puts "yay"
684
689
  sock.close
685
690
  end
@@ -691,7 +696,7 @@ class ServerPluginHelperTest < Test::Unit::TestCase
691
696
  test 'raises error if plugin registers data callback for connection object from #server_create' do
692
697
  received = ""
693
698
  errors = []
694
- @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|
695
700
  received << data
696
701
  begin
697
702
  sock.data{|d| received << d.upcase }
@@ -700,7 +705,7 @@ class ServerPluginHelperTest < Test::Unit::TestCase
700
705
  end
701
706
  end
702
707
  sock = UDPSocket.new(Socket::AF_INET)
703
- sock.connect("127.0.0.1", PORT)
708
+ sock.connect("127.0.0.1", @port)
704
709
  sock.write "foo\n"
705
710
  sock.close
706
711
 
@@ -713,7 +718,7 @@ class ServerPluginHelperTest < Test::Unit::TestCase
713
718
  test 'raise error if plugin registers write_complete callback for udp' do
714
719
  received = ""
715
720
  errors = []
716
- @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|
717
722
  received << data
718
723
  begin
719
724
  sock.on(:write_complete){|conn| "" }
@@ -722,7 +727,7 @@ class ServerPluginHelperTest < Test::Unit::TestCase
722
727
  end
723
728
  end
724
729
  sock = UDPSocket.new(Socket::AF_INET)
725
- sock.connect("127.0.0.1", PORT)
730
+ sock.connect("127.0.0.1", @port)
726
731
  sock.write "foo\n"
727
732
  sock.close
728
733
 
@@ -735,7 +740,7 @@ class ServerPluginHelperTest < Test::Unit::TestCase
735
740
  test 'raises error if plugin registers close callback for udp' do
736
741
  received = ""
737
742
  errors = []
738
- @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|
739
744
  received << data
740
745
  begin
741
746
  sock.on(:close){|d| "" }
@@ -744,7 +749,7 @@ class ServerPluginHelperTest < Test::Unit::TestCase
744
749
  end
745
750
  end
746
751
  sock = UDPSocket.new(Socket::AF_INET)
747
- sock.connect("127.0.0.1", PORT)
752
+ sock.connect("127.0.0.1", @port)
748
753
  sock.write "foo\n"
749
754
  sock.close
750
755
 
@@ -758,10 +763,10 @@ class ServerPluginHelperTest < Test::Unit::TestCase
758
763
  omit "IPv6 unavailable here" unless ipv6_enabled?
759
764
 
760
765
  assert_nothing_raised do
761
- @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|
762
767
  # ...
763
768
  end
764
- @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|
765
770
  # ...
766
771
  end
767
772
  end
@@ -923,16 +928,16 @@ class ServerPluginHelperTest < Test::Unit::TestCase
923
928
  }
924
929
 
925
930
  received = ""
926
- @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|
927
932
  received << data
928
933
  end
929
934
  assert_raise "" do
930
- open_tls_session('127.0.0.1', PORT) do |sock|
935
+ open_tls_session('127.0.0.1', @port) do |sock|
931
936
  sock.post_connection_check('myserver.testing.fluentd.org')
932
937
  # cannot connect ....
933
938
  end
934
939
  end
935
- 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|
936
941
  sock.puts "yay"
937
942
  sock.puts "foo"
938
943
  end
@@ -962,16 +967,16 @@ class ServerPluginHelperTest < Test::Unit::TestCase
962
967
  }
963
968
  tls_options[:private_key_passphrase] = private_key_passphrase if private_key_passphrase
964
969
  received = ""
965
- @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|
966
971
  received << data
967
972
  end
968
973
  assert_raise "" do
969
- open_tls_session('127.0.0.1', PORT) do |sock|
974
+ open_tls_session('127.0.0.1', @port) do |sock|
970
975
  sock.post_connection_check('server.testing.fluentd.org')
971
976
  # cannot connect by failing verification without server cert
972
977
  end
973
978
  end
974
- 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|
975
980
  sock.puts "yay"
976
981
  sock.puts "foo"
977
982
  end
@@ -997,10 +1002,10 @@ class ServerPluginHelperTest < Test::Unit::TestCase
997
1002
  }
998
1003
  tls_options[:ca_private_key_passphrase] = ca_key_passphrase if ca_key_passphrase
999
1004
  received = ""
1000
- @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|
1001
1006
  received << data
1002
1007
  end
1003
- 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|
1004
1009
  sock.puts "yay"
1005
1010
  sock.puts "foo"
1006
1011
  end
@@ -1036,10 +1041,10 @@ class ServerPluginHelperTest < Test::Unit::TestCase
1036
1041
  }
1037
1042
  tls_options[:private_key_passphrase] = private_key_passphrase if private_key_passphrase
1038
1043
  received = ""
1039
- @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|
1040
1045
  received << data
1041
1046
  end
1042
- 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|
1043
1048
  sock.puts "yay"
1044
1049
  sock.puts "foo"
1045
1050
  end
@@ -1066,10 +1071,10 @@ class ServerPluginHelperTest < Test::Unit::TestCase
1066
1071
  }
1067
1072
  tls_options[:private_key_passphrase] = private_key_passphrase if private_key_passphrase
1068
1073
  received = ""
1069
- @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|
1070
1075
  received << data
1071
1076
  end
1072
- 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|
1073
1078
  sock.puts "yay"
1074
1079
  sock.puts "foo"
1075
1080
  end
@@ -1090,16 +1095,16 @@ class ServerPluginHelperTest < Test::Unit::TestCase
1090
1095
  @d.configure(conf); @d.start; @d.after_start
1091
1096
 
1092
1097
  received = ""
1093
- @d.server_create_tls(:s, PORT) do |data, conn|
1098
+ @d.server_create_tls(:s, @port) do |data, conn|
1094
1099
  received << data
1095
1100
  end
1096
1101
  assert_raise "" do
1097
- open_tls_session('127.0.0.1', PORT) do |sock|
1102
+ open_tls_session('127.0.0.1', @port) do |sock|
1098
1103
  sock.post_connection_check('myserver.testing.fluentd.org')
1099
1104
  # cannot connect ....
1100
1105
  end
1101
1106
  end
1102
- 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|
1103
1108
  sock.puts "yay"
1104
1109
  sock.puts "foo"
1105
1110
  end
@@ -1125,16 +1130,16 @@ class ServerPluginHelperTest < Test::Unit::TestCase
1125
1130
  @d.configure(conf); @d.start; @d.after_start
1126
1131
 
1127
1132
  received = ""
1128
- @d.server_create_tls(:s, PORT) do |data, conn|
1133
+ @d.server_create_tls(:s, @port) do |data, conn|
1129
1134
  received << data
1130
1135
  end
1131
1136
  assert_raise "" do
1132
- open_tls_session('127.0.0.1', PORT) do |sock|
1137
+ open_tls_session('127.0.0.1', @port) do |sock|
1133
1138
  sock.post_connection_check('server.testing.fluentd.org')
1134
1139
  # cannot connect by failing verification without server cert
1135
1140
  end
1136
1141
  end
1137
- 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|
1138
1143
  sock.puts "yay"
1139
1144
  sock.puts "foo"
1140
1145
  end
@@ -1160,10 +1165,10 @@ class ServerPluginHelperTest < Test::Unit::TestCase
1160
1165
  @d.configure(conf); @d.start; @d.after_start
1161
1166
 
1162
1167
  received = ""
1163
- @d.server_create_tls(:s, PORT) do |data, conn|
1168
+ @d.server_create_tls(:s, @port) do |data, conn|
1164
1169
  received << data
1165
1170
  end
1166
- 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|
1167
1172
  sock.puts "yay"
1168
1173
  sock.puts "foo"
1169
1174
  end
@@ -1193,10 +1198,10 @@ class ServerPluginHelperTest < Test::Unit::TestCase
1193
1198
  @d.configure(conf); @d.start; @d.after_start
1194
1199
 
1195
1200
  received = ""
1196
- @d.server_create_tls(:s, PORT) do |data, conn|
1201
+ @d.server_create_tls(:s, @port) do |data, conn|
1197
1202
  received << data
1198
1203
  end
1199
- 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|
1200
1205
  sock.puts "yay"
1201
1206
  sock.puts "foo"
1202
1207
  end
@@ -1224,10 +1229,10 @@ class ServerPluginHelperTest < Test::Unit::TestCase
1224
1229
  @d.configure(conf); @d.start; @d.after_start
1225
1230
 
1226
1231
  received = ""
1227
- @d.server_create_tls(:s, PORT) do |data, conn|
1232
+ @d.server_create_tls(:s, @port) do |data, conn|
1228
1233
  received << data
1229
1234
  end
1230
- 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|
1231
1236
  sock.puts "yay"
1232
1237
  sock.puts "foo"
1233
1238
  end
@@ -1300,7 +1305,7 @@ class ServerPluginHelperTest < Test::Unit::TestCase
1300
1305
 
1301
1306
  test 'can accept all keyword arguments valid for tcp/tls server' do
1302
1307
  assert_nothing_raised do
1303
- @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) 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|
1304
1309
  # ...
1305
1310
  end
1306
1311
  end
@@ -1308,11 +1313,11 @@ class ServerPluginHelperTest < Test::Unit::TestCase
1308
1313
 
1309
1314
  test 'creates a tls server just to read data' do
1310
1315
  received = ""
1311
- @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|
1312
1317
  received << data
1313
1318
  end
1314
1319
  3.times do
1315
- 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|
1316
1321
  sock.puts "yay"
1317
1322
  sock.puts "foo"
1318
1323
  end
@@ -1325,13 +1330,13 @@ class ServerPluginHelperTest < Test::Unit::TestCase
1325
1330
  test 'creates a tls server to read and write data' do
1326
1331
  received = ""
1327
1332
  responses = []
1328
- @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|
1329
1334
  received << data
1330
1335
  conn.write "ack\n"
1331
1336
  end
1332
1337
  3.times do
1333
- # open_tls_session('127.0.0.1', PORT, cert_path: @cert_path, hostname: @default_hostname) do |sock|
1334
- 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|
1335
1340
  sock.puts "yay"
1336
1341
  sock.puts "foo"
1337
1342
  responses << sock.readline
@@ -1348,13 +1353,13 @@ class ServerPluginHelperTest < Test::Unit::TestCase
1348
1353
 
1349
1354
  received = ""
1350
1355
  responses = []
1351
- @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|
1352
1357
  received << data
1353
1358
  conn.write "ack\n"
1354
1359
  end
1355
1360
  3.times do
1356
- # open_tls_session('::1', PORT, cert_path: @cert_path, hostname: @default_hostname) do |sock|
1357
- 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|
1358
1363
  sock.puts "yay"
1359
1364
  sock.puts "foo"
1360
1365
  responses << sock.readline
@@ -1369,13 +1374,13 @@ class ServerPluginHelperTest < Test::Unit::TestCase
1369
1374
  test 'does not resolve name of client address in default' do
1370
1375
  received = ""
1371
1376
  sources = []
1372
- @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|
1373
1378
  received << data
1374
1379
  sources << conn.remote_host
1375
1380
  end
1376
1381
  3.times do
1377
- # open_tls_session('127.0.0.1', PORT, cert_path: @cert_path, hostname: @default_hostname) do |sock|
1378
- 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|
1379
1384
  sock.puts "yay"
1380
1385
  end
1381
1386
  end
@@ -1389,13 +1394,13 @@ class ServerPluginHelperTest < Test::Unit::TestCase
1389
1394
 
1390
1395
  received = ""
1391
1396
  sources = []
1392
- @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|
1393
1398
  received << data
1394
1399
  sources << conn.remote_host
1395
1400
  end
1396
1401
  3.times do
1397
- # open_tls_session('127.0.0.1', PORT, cert_path: @cert_path, hostname: @default_hostname) do |sock|
1398
- 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|
1399
1404
  sock.puts "yay"
1400
1405
  end
1401
1406
  end
@@ -1411,7 +1416,7 @@ class ServerPluginHelperTest < Test::Unit::TestCase
1411
1416
  test 'raises error if plugin registers data callback for connection object from #server_create' do
1412
1417
  received = ""
1413
1418
  errors = []
1414
- @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|
1415
1420
  received << data
1416
1421
  begin
1417
1422
  conn.data{|d| received << d.upcase }
@@ -1419,7 +1424,7 @@ class ServerPluginHelperTest < Test::Unit::TestCase
1419
1424
  errors << e
1420
1425
  end
1421
1426
  end
1422
- 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|
1423
1428
  sock.puts "foo"
1424
1429
  end
1425
1430
  waiting(10){ sleep 0.1 until received.bytesize == 4 || errors.size == 1 }
@@ -1433,7 +1438,7 @@ class ServerPluginHelperTest < Test::Unit::TestCase
1433
1438
  lines = []
1434
1439
  responses = []
1435
1440
  response_completes = []
1436
- @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|
1437
1442
  conn.on(:write_complete){|c| response_completes << true }
1438
1443
  buffer << data
1439
1444
  if idx = buffer.index("\n")
@@ -1442,7 +1447,7 @@ class ServerPluginHelperTest < Test::Unit::TestCase
1442
1447
  end
1443
1448
  end
1444
1449
  3.times do
1445
- 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|
1446
1451
  sock.write "yay"
1447
1452
  sock.write "foo\n"
1448
1453
  begin
@@ -1463,7 +1468,7 @@ class ServerPluginHelperTest < Test::Unit::TestCase
1463
1468
  buffer = ""
1464
1469
  lines = []
1465
1470
  callback_results = []
1466
- @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|
1467
1472
  conn.on(:close){|c| callback_results << "closed" }
1468
1473
  buffer << data
1469
1474
  if idx = buffer.index("\n")
@@ -1472,7 +1477,7 @@ class ServerPluginHelperTest < Test::Unit::TestCase
1472
1477
  end
1473
1478
  end
1474
1479
  3.times do
1475
- 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|
1476
1481
  sock.write "yay"
1477
1482
  sock.write "foo\n"
1478
1483
  begin
@@ -1493,7 +1498,7 @@ class ServerPluginHelperTest < Test::Unit::TestCase
1493
1498
 
1494
1499
  sub_test_case 'TLS version connection check' do
1495
1500
  test "can't connect with different TLS version" do
1496
- @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|
1497
1502
  end
1498
1503
  if defined?(OpenSSL::SSL::TLS1_3_VERSION)
1499
1504
  version = :'TLS1_3'
@@ -1501,7 +1506,7 @@ class ServerPluginHelperTest < Test::Unit::TestCase
1501
1506
  version = :'TLS1_1'
1502
1507
  end
1503
1508
  assert_raise(OpenSSL::SSL::SSLError, Errno::ECONNRESET) {
1504
- 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|
1505
1510
  end
1506
1511
  }
1507
1512
  end
@@ -1517,15 +1522,15 @@ class ServerPluginHelperTest < Test::Unit::TestCase
1517
1522
  end
1518
1523
 
1519
1524
  opts = @tls_options.merge(min_version: min_version, max_version: max_version)
1520
- @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|
1521
1526
  end
1522
1527
  assert_raise(OpenSSL::SSL::SSLError, Errno::ECONNRESET) {
1523
- 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|
1524
1529
  end
1525
1530
  }
1526
1531
  [min_version, max_version].each { |ver|
1527
1532
  assert_nothing_raised {
1528
- 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|
1529
1534
  end
1530
1535
  }
1531
1536
  }
@@ -1565,7 +1570,7 @@ class ServerPluginHelperTest < Test::Unit::TestCase
1565
1570
  sub_test_case '#server_create_connection' do
1566
1571
  test 'raise error if udp is specified in proto' do
1567
1572
  assert_raise(ArgumentError.new("BUG: cannot create connection for UDP")) do
1568
- @d.server_create_connection(:myserver, PORT, proto: :udp){|c| c }
1573
+ @d.server_create_connection(:myserver, @port, proto: :udp){|c| c }
1569
1574
  end
1570
1575
  end
1571
1576
 
@@ -1580,10 +1585,10 @@ class ServerPluginHelperTest < Test::Unit::TestCase
1580
1585
  test 'raise error if block argument is not specified or too many' do |(proto, kwargs)|
1581
1586
  empty_block = ->(){}
1582
1587
  assert_raise(ArgumentError.new("BUG: block must have just one argument")) do
1583
- @d.server_create_connection(:myserver, PORT, proto: proto, **kwargs, &empty_block)
1588
+ @d.server_create_connection(:myserver, @port, proto: proto, **kwargs, &empty_block)
1584
1589
  end
1585
1590
  assert_raise(ArgumentError.new("BUG: block must have just one argument")) do
1586
- @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] }
1587
1592
  end
1588
1593
  end
1589
1594
 
@@ -1591,14 +1596,14 @@ class ServerPluginHelperTest < Test::Unit::TestCase
1591
1596
  test 'does not resolve name of client address in default' do |(proto, kwargs)|
1592
1597
  received = ""
1593
1598
  sources = []
1594
- @d.server_create_connection(:s, PORT, proto: proto, **kwargs) do |conn|
1599
+ @d.server_create_connection(:s, @port, proto: proto, **kwargs) do |conn|
1595
1600
  sources << conn.remote_host
1596
1601
  conn.data do |d|
1597
1602
  received << d
1598
1603
  end
1599
1604
  end
1600
1605
  3.times do
1601
- open_client(proto, "127.0.0.1", PORT) do |sock|
1606
+ open_client(proto, "127.0.0.1", @port) do |sock|
1602
1607
  sock.puts "yay"
1603
1608
  end
1604
1609
  end
@@ -1613,14 +1618,14 @@ class ServerPluginHelperTest < Test::Unit::TestCase
1613
1618
 
1614
1619
  received = ""
1615
1620
  sources = []
1616
- @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|
1617
1622
  sources << conn.remote_host
1618
1623
  conn.data do |d|
1619
1624
  received << d
1620
1625
  end
1621
1626
  end
1622
1627
  3.times do
1623
- open_client(proto, "127.0.0.1", PORT) do |sock|
1628
+ open_client(proto, "127.0.0.1", @port) do |sock|
1624
1629
  sock.puts "yay"
1625
1630
  end
1626
1631
  end
@@ -1633,7 +1638,7 @@ class ServerPluginHelperTest < Test::Unit::TestCase
1633
1638
  test 'creates a server to provide connection, which can read, write and close' do |(proto, kwargs)|
1634
1639
  lines = []
1635
1640
  buffer = ""
1636
- @d.server_create_connection(:s, PORT, proto: proto, **kwargs) do |conn|
1641
+ @d.server_create_connection(:s, @port, proto: proto, **kwargs) do |conn|
1637
1642
  conn.data do |d|
1638
1643
  buffer << d
1639
1644
  if buffer == "x"
@@ -1649,7 +1654,7 @@ class ServerPluginHelperTest < Test::Unit::TestCase
1649
1654
  replied = []
1650
1655
  disconnecteds = []
1651
1656
  3.times do |i|
1652
- open_client(proto, "127.0.0.1", PORT) do |sock|
1657
+ open_client(proto, "127.0.0.1", @port) do |sock|
1653
1658
  sock.puts "yay"
1654
1659
  while line = sock.readline
1655
1660
  replied << line
@@ -1685,7 +1690,7 @@ class ServerPluginHelperTest < Test::Unit::TestCase
1685
1690
  buffer = ""
1686
1691
  written = 0
1687
1692
  closed = 0
1688
- @d.server_create_connection(:s, PORT, proto: proto, **kwargs) do |conn|
1693
+ @d.server_create_connection(:s, @port, proto: proto, **kwargs) do |conn|
1689
1694
  conn.on(:write_complete){|_conn| written += 1 }
1690
1695
  conn.on(:close){|_conn| closed += 1 }
1691
1696
  conn.on(:data) do |d|
@@ -1698,7 +1703,7 @@ class ServerPluginHelperTest < Test::Unit::TestCase
1698
1703
  end
1699
1704
  replied = []
1700
1705
  3.times do
1701
- open_client(proto, "127.0.0.1", PORT) do |sock|
1706
+ open_client(proto, "127.0.0.1", @port) do |sock|
1702
1707
  sock.puts "yay"
1703
1708
  while line = sock.readline
1704
1709
  replied << line
@@ -1719,14 +1724,14 @@ class ServerPluginHelperTest < Test::Unit::TestCase
1719
1724
  test 'creates a server, and does not leak connections' do |(proto, kwargs)|
1720
1725
  buffer = ""
1721
1726
  closed = 0
1722
- @d.server_create_connection(:s, PORT, proto: proto, **kwargs) do |conn|
1727
+ @d.server_create_connection(:s, @port, proto: proto, **kwargs) do |conn|
1723
1728
  conn.on(:close){|_c| closed += 1 }
1724
1729
  conn.on(:data) do |d|
1725
1730
  buffer << d
1726
1731
  end
1727
1732
  end
1728
1733
  3.times do
1729
- open_client(proto, "127.0.0.1", PORT) do |sock|
1734
+ open_client(proto, "127.0.0.1", @port) do |sock|
1730
1735
  sock.puts "yay"
1731
1736
  end
1732
1737
  end
@@ -1739,7 +1744,7 @@ class ServerPluginHelperTest < Test::Unit::TestCase
1739
1744
  test 'will refuse more connect requests after stop, but read data from sockets already connected, in non-shared server' do |(proto, kwargs)|
1740
1745
  connected = false
1741
1746
  begin
1742
- open_client(proto, "127.0.0.1", PORT) do |sock|
1747
+ open_client(proto, "127.0.0.1", @port) do |sock|
1743
1748
  # expected behavior is connection refused...
1744
1749
  connected = true
1745
1750
  end
@@ -1749,7 +1754,7 @@ class ServerPluginHelperTest < Test::Unit::TestCase
1749
1754
  assert_false connected
1750
1755
 
1751
1756
  received = ""
1752
- @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|
1753
1758
  conn.on(:data) do |data|
1754
1759
  received << data
1755
1760
  conn.write "ack\n"
@@ -1757,7 +1762,7 @@ class ServerPluginHelperTest < Test::Unit::TestCase
1757
1762
  end
1758
1763
 
1759
1764
  th0 = Thread.new do
1760
- open_client(proto, "127.0.0.1", PORT) do |sock|
1765
+ open_client(proto, "127.0.0.1", @port) do |sock|
1761
1766
  sock.puts "yay"
1762
1767
  sock.readline
1763
1768
  end
@@ -1771,7 +1776,7 @@ class ServerPluginHelperTest < Test::Unit::TestCase
1771
1776
  ending = false
1772
1777
 
1773
1778
  th1 = Thread.new do
1774
- open_client(proto, "127.0.0.1", PORT) do |sock|
1779
+ open_client(proto, "127.0.0.1", @port) do |sock|
1775
1780
  sleeping = true
1776
1781
  sleep 0.1 until stopped
1777
1782
  sock.puts "yay"
@@ -1794,7 +1799,7 @@ class ServerPluginHelperTest < Test::Unit::TestCase
1794
1799
 
1795
1800
  th2 = Thread.new do
1796
1801
  begin
1797
- open_client(proto, "127.0.0.1", PORT) do |sock|
1802
+ open_client(proto, "127.0.0.1", @port) do |sock|
1798
1803
  sock.puts "foo"
1799
1804
  end
1800
1805
  false # failed