fluentd 1.16.7-x64-mingw32 → 1.17.0-x64-mingw32

Sign up to get free protection for your applications and to get access to all the features.
Files changed (70) hide show
  1. checksums.yaml +4 -4
  2. data/.github/DISCUSSION_TEMPLATE/q-a-japanese.yml +50 -0
  3. data/.github/DISCUSSION_TEMPLATE/q-a.yml +47 -0
  4. data/.github/workflows/test-ruby-head.yml +31 -0
  5. data/.github/workflows/test.yml +2 -9
  6. data/CHANGELOG.md +34 -42
  7. data/README.md +3 -1
  8. data/Rakefile +1 -1
  9. data/fluentd.gemspec +9 -9
  10. data/lib/fluent/command/binlog_reader.rb +1 -1
  11. data/lib/fluent/command/fluentd.rb +1 -1
  12. data/lib/fluent/config/configure_proxy.rb +2 -2
  13. data/lib/fluent/config/types.rb +1 -1
  14. data/lib/fluent/config/yaml_parser/parser.rb +0 -4
  15. data/lib/fluent/configurable.rb +2 -2
  16. data/lib/fluent/counter/mutex_hash.rb +1 -1
  17. data/lib/fluent/fluent_log_event_router.rb +0 -2
  18. data/lib/fluent/plugin/buf_file.rb +1 -1
  19. data/lib/fluent/plugin/buffer/file_chunk.rb +1 -1
  20. data/lib/fluent/plugin/buffer/file_single_chunk.rb +2 -3
  21. data/lib/fluent/plugin/filter_parser.rb +26 -8
  22. data/lib/fluent/plugin/in_http.rb +18 -53
  23. data/lib/fluent/plugin/in_tail.rb +34 -2
  24. data/lib/fluent/plugin/out_file.rb +0 -8
  25. data/lib/fluent/plugin/out_http.rb +125 -13
  26. data/lib/fluent/plugin/owned_by_mixin.rb +0 -1
  27. data/lib/fluent/plugin/parser_json.rb +34 -9
  28. data/lib/fluent/plugin/parser_msgpack.rb +24 -3
  29. data/lib/fluent/plugin_helper/metrics.rb +2 -2
  30. data/lib/fluent/registry.rb +6 -6
  31. data/lib/fluent/supervisor.rb +1 -1
  32. data/lib/fluent/test/output_test.rb +1 -1
  33. data/lib/fluent/unique_id.rb +1 -1
  34. data/lib/fluent/version.rb +1 -1
  35. data/lib/fluent/winsvc.rb +3 -28
  36. data/test/command/test_cat.rb +2 -2
  37. data/test/command/test_fluentd.rb +10 -57
  38. data/test/helper.rb +7 -27
  39. data/test/log/test_console_adapter.rb +10 -3
  40. data/test/plugin/data/log_numeric/01.log +0 -0
  41. data/test/plugin/data/log_numeric/02.log +0 -0
  42. data/test/plugin/data/log_numeric/12.log +0 -0
  43. data/test/plugin/data/log_numeric/14.log +0 -0
  44. data/test/plugin/in_tail/test_io_handler.rb +14 -13
  45. data/test/plugin/in_tail/test_position_file.rb +7 -6
  46. data/test/plugin/out_forward/test_ack_handler.rb +3 -3
  47. data/test/plugin/out_forward/test_socket_cache.rb +3 -3
  48. data/test/plugin/test_in_forward.rb +1 -2
  49. data/test/plugin/test_in_http.rb +24 -2
  50. data/test/plugin/test_in_monitor_agent.rb +6 -6
  51. data/test/plugin/test_in_syslog.rb +18 -25
  52. data/test/plugin/test_in_tail.rb +153 -4
  53. data/test/plugin/test_in_tcp.rb +1 -1
  54. data/test/plugin/test_in_udp.rb +10 -16
  55. data/test/plugin/test_out_exec_filter.rb +7 -12
  56. data/test/plugin/test_out_file.rb +2 -22
  57. data/test/plugin/test_out_forward.rb +3 -2
  58. data/test/plugin/test_out_http.rb +128 -0
  59. data/test/plugin/test_out_stream.rb +1 -1
  60. data/test/plugin/test_owned_by.rb +0 -1
  61. data/test/plugin/test_parser_json.rb +106 -31
  62. data/test/plugin/test_parser_msgpack.rb +127 -0
  63. data/test/plugin/test_storage.rb +0 -1
  64. data/test/plugin_helper/test_child_process.rb +4 -4
  65. data/test/plugin_helper/test_http_server_helper.rb +1 -1
  66. data/test/plugin_helper/test_server.rb +41 -64
  67. data/test/plugin_helper/test_socket.rb +1 -1
  68. data/test/test_config.rb +0 -6
  69. data/test/test_event_router.rb +2 -2
  70. metadata +90 -21
@@ -128,14 +128,11 @@ class TestFluentdCommand < ::Test::Unit::TestCase
128
128
 
129
129
  # ATTENTION: This stops taking logs when all `pattern_list` match or timeout,
130
130
  # so `patterns_not_match` can test only logs up to that point.
131
- # You can pass a block to assert something after log matching.
132
131
  def assert_log_matches(cmdline, *pattern_list, patterns_not_match: [], timeout: 20, env: {})
133
132
  matched = false
134
133
  matched_wrongly = false
135
- error_msg_match = ""
134
+ assert_error_msg = ""
136
135
  stdio_buf = ""
137
- succeeded_block = true
138
- error_msg_block = ""
139
136
  begin
140
137
  execute_command(cmdline, @tmp_dir, env) do |pid, stdout|
141
138
  begin
@@ -166,13 +163,6 @@ class TestFluentdCommand < ::Test::Unit::TestCase
166
163
  end
167
164
  end
168
165
  end
169
-
170
- begin
171
- yield if block_given?
172
- rescue => e
173
- succeeded_block = false
174
- error_msg_block = "failed block execution after matching: #{e}"
175
- end
176
166
  ensure
177
167
  if SUPERVISOR_PID_PATTERN =~ stdio_buf
178
168
  @supervisor_pid = $1.to_i
@@ -183,19 +173,19 @@ class TestFluentdCommand < ::Test::Unit::TestCase
183
173
  end
184
174
  end
185
175
  rescue Timeout::Error
186
- error_msg_match = "execution timeout"
176
+ assert_error_msg = "execution timeout"
187
177
  # https://github.com/fluent/fluentd/issues/4095
188
178
  # On Windows, timeout without `@supervisor_pid` means that the test is invalid,
189
179
  # since the supervisor process will survive without being killed correctly.
190
180
  flunk("Invalid test: The pid of supervisor could not be taken, which is necessary on Windows.") if Fluent.windows? && @supervisor_pid.nil?
191
181
  rescue => e
192
- error_msg_match = "unexpected error in launching fluentd: #{e.inspect}"
182
+ assert_error_msg = "unexpected error in launching fluentd: #{e.inspect}"
193
183
  else
194
- error_msg_match = "log doesn't match" unless matched
184
+ assert_error_msg = "log doesn't match" unless matched
195
185
  end
196
186
 
197
187
  if patterns_not_match.empty?
198
- error_msg_match = build_message(error_msg_match,
188
+ assert_error_msg = build_message(assert_error_msg,
199
189
  "<?>\nwas expected to include:\n<?>",
200
190
  stdio_buf, pattern_list)
201
191
  else
@@ -207,17 +197,16 @@ class TestFluentdCommand < ::Test::Unit::TestCase
207
197
  lines.any?{|line| line.include?(ptn) }
208
198
  end
209
199
  if matched_wrongly
210
- error_msg_match << "\n" unless error_msg_match.empty?
211
- error_msg_match << "pattern exists in logs wrongly: #{ptn}"
200
+ assert_error_msg << "\n" unless assert_error_msg.empty?
201
+ assert_error_msg << "pattern exists in logs wrongly: #{ptn}"
212
202
  end
213
203
  end
214
- error_msg_match = build_message(error_msg_match,
204
+ assert_error_msg = build_message(assert_error_msg,
215
205
  "<?>\nwas expected to include:\n<?>\nand not include:\n<?>",
216
206
  stdio_buf, pattern_list, patterns_not_match)
217
207
  end
218
208
 
219
- assert matched && !matched_wrongly, error_msg_match
220
- assert succeeded_block, error_msg_block if block_given?
209
+ assert matched && !matched_wrongly, assert_error_msg
221
210
  end
222
211
 
223
212
  def assert_fluentd_fails_to_start(cmdline, *pattern_list, timeout: 20)
@@ -1175,7 +1164,7 @@ CONF
1175
1164
  end
1176
1165
  end
1177
1166
 
1178
- sub_test_case 'shared socket options' do
1167
+ sub_test_case 'sahred socket options' do
1179
1168
  test 'enable shared socket by default' do
1180
1169
  conf = ""
1181
1170
  conf_path = create_conf_file('empty.conf', conf)
@@ -1299,40 +1288,4 @@ CONF
1299
1288
  "[debug]")
1300
1289
  end
1301
1290
  end
1302
-
1303
- sub_test_case "plugin option" do
1304
- test "should be the default value when not specifying" do
1305
- conf_path = create_conf_file('test.conf', <<~CONF)
1306
- <source>
1307
- @type monitor_agent
1308
- </source>
1309
- CONF
1310
- assert File.exist?(conf_path)
1311
- cmdline = create_cmdline(conf_path)
1312
-
1313
- assert_log_matches(cmdline, "fluentd worker is now running") do
1314
- response = Net::HTTP.get(URI.parse("http://localhost:24220/api/config.json"))
1315
- actual_conf = JSON.parse(response)
1316
- assert_equal Fluent::Supervisor.default_options[:plugin_dirs], actual_conf["plugin_dirs"]
1317
- end
1318
- end
1319
-
1320
- data(short: "-p")
1321
- data(long: "--plugin")
1322
- test "can be added by specifying the option" do |option_name|
1323
- conf_path = create_conf_file('test.conf', <<~CONF)
1324
- <source>
1325
- @type monitor_agent
1326
- </source>
1327
- CONF
1328
- assert File.exist?(conf_path)
1329
- cmdline = create_cmdline(conf_path, option_name, @tmp_dir, option_name, @tmp_dir)
1330
-
1331
- assert_log_matches(cmdline, "fluentd worker is now running") do
1332
- response = Net::HTTP.get(URI.parse("http://localhost:24220/api/config.json"))
1333
- actual_conf = JSON.parse(response)
1334
- assert_equal Fluent::Supervisor.default_options[:plugin_dirs] + [@tmp_dir, @tmp_dir], actual_conf["plugin_dirs"]
1335
- end
1336
- end
1337
- end
1338
1291
  end
data/test/helper.rb CHANGED
@@ -71,31 +71,17 @@ end
71
71
 
72
72
  include Fluent::Test::Helpers
73
73
 
74
- def unused_port(num = 1, protocol:, bind: "0.0.0.0")
74
+ def unused_port(num = 1, protocol: :tcp, bind: "0.0.0.0")
75
75
  case protocol
76
- when :tcp, :tls
76
+ when :tcp
77
77
  unused_port_tcp(num)
78
78
  when :udp
79
79
  unused_port_udp(num, bind: bind)
80
- when :all
81
- unused_port_tcp_udp(num)
82
80
  else
83
81
  raise ArgumentError, "unknown protocol: #{protocol}"
84
82
  end
85
83
  end
86
84
 
87
- def unused_port_tcp_udp(num = 1)
88
- raise "not support num > 1" if num > 1
89
-
90
- # The default maximum number of file descriptors in macOS is 256.
91
- # It might need to set num to a smaller value than that.
92
- tcp_ports = unused_port_tcp(200)
93
- port = unused_port_udp(1, port_list: tcp_ports)
94
- raise "can't find unused port" unless port
95
-
96
- port
97
- end
98
-
99
85
  def unused_port_tcp(num = 1)
100
86
  ports = []
101
87
  sockets = []
@@ -104,7 +90,7 @@ def unused_port_tcp(num = 1)
104
90
  sockets << s
105
91
  ports << s.addr[1]
106
92
  end
107
- sockets.each(&:close)
93
+ sockets.each{|s| s.close }
108
94
  if num == 1
109
95
  return ports.first
110
96
  else
@@ -114,15 +100,12 @@ end
114
100
 
115
101
  PORT_RANGE_AVAILABLE = (1024...65535)
116
102
 
117
- def unused_port_udp(num = 1, port_list: [], bind: "0.0.0.0")
103
+ def unused_port_udp(num = 1, bind: "0.0.0.0")
118
104
  family = IPAddr.new(IPSocket.getaddress(bind)).ipv4? ? ::Socket::AF_INET : ::Socket::AF_INET6
119
105
  ports = []
120
106
  sockets = []
121
-
122
- use_random_port = port_list.empty?
123
- i = 0
124
- loop do
125
- port = use_random_port ? rand(PORT_RANGE_AVAILABLE) : port_list[i]
107
+ while ports.size < num
108
+ port = rand(PORT_RANGE_AVAILABLE)
126
109
  u = UDPSocket.new(family)
127
110
  if (u.bind(bind, port) rescue nil)
128
111
  ports << port
@@ -130,11 +113,8 @@ def unused_port_udp(num = 1, port_list: [], bind: "0.0.0.0")
130
113
  else
131
114
  u.close
132
115
  end
133
- i += 1
134
- break if ports.size >= num
135
- break if !use_random_port && i >= port_list.size
136
116
  end
137
- sockets.each(&:close)
117
+ sockets.each{|s| s.close }
138
118
  if num == 1
139
119
  return ports.first
140
120
  else
@@ -72,11 +72,18 @@ class ConsoleAdapterTest < Test::Unit::TestCase
72
72
  fatal: :fatal)
73
73
  def test_options(level)
74
74
  @console_logger.send(level, "subject", kwarg1: "opt1", kwarg2: "opt2")
75
+ lines = @logdev.logs[0].split("\n")
76
+ args = JSON.load(lines[1..].collect { |str| str.sub(/\s+\|/, "") }.join("\n"));
75
77
  assert_equal([
76
- "#{@timestamp_str} [#{level}]: 0.0s: subject\n" +
77
- " | {\"kwarg1\":\"opt1\",\"kwarg2\":\"opt2\"}\n"
78
+ 1,
79
+ "#{@timestamp_str} [#{level}]: 0.0s: subject",
80
+ { "kwarg1" => "opt1", "kwarg2" => "opt2" }
78
81
  ],
79
- @logdev.logs)
82
+ [
83
+ @logdev.logs.size,
84
+ lines[0],
85
+ args
86
+ ])
80
87
  end
81
88
 
82
89
  data(debug: :debug,
File without changes
File without changes
File without changes
File without changes
@@ -5,19 +5,20 @@ require 'fluent/plugin/metrics_local'
5
5
  require 'tempfile'
6
6
 
7
7
  class IntailIOHandlerTest < Test::Unit::TestCase
8
- def setup
9
- Tempfile.create('intail_io_handler') do |file|
10
- file.binmode
11
- @file = file
12
- opened_file_metrics = Fluent::Plugin::LocalMetrics.new
13
- opened_file_metrics.configure(config_element('metrics', '', {}))
14
- closed_file_metrics = Fluent::Plugin::LocalMetrics.new
15
- closed_file_metrics.configure(config_element('metrics', '', {}))
16
- rotated_file_metrics = Fluent::Plugin::LocalMetrics.new
17
- rotated_file_metrics.configure(config_element('metrics', '', {}))
18
- @metrics = Fluent::Plugin::TailInput::MetricsInfo.new(opened_file_metrics, closed_file_metrics, rotated_file_metrics)
19
- yield
20
- end
8
+ setup do
9
+ @file = Tempfile.new('intail_io_handler').binmode
10
+ opened_file_metrics = Fluent::Plugin::LocalMetrics.new
11
+ opened_file_metrics.configure(config_element('metrics', '', {}))
12
+ closed_file_metrics = Fluent::Plugin::LocalMetrics.new
13
+ closed_file_metrics.configure(config_element('metrics', '', {}))
14
+ rotated_file_metrics = Fluent::Plugin::LocalMetrics.new
15
+ rotated_file_metrics.configure(config_element('metrics', '', {}))
16
+ @metrics = Fluent::Plugin::TailInput::MetricsInfo.new(opened_file_metrics, closed_file_metrics, rotated_file_metrics)
17
+ end
18
+
19
+ teardown do
20
+ @file.close rescue nil
21
+ @file.unlink rescue nil
21
22
  end
22
23
 
23
24
  def create_target_info
@@ -6,12 +6,13 @@ require 'fileutils'
6
6
  require 'tempfile'
7
7
 
8
8
  class IntailPositionFileTest < Test::Unit::TestCase
9
- def setup
10
- Tempfile.create('intail_position_file_test') do |file|
11
- file.binmode
12
- @file = file
13
- yield
14
- end
9
+ setup do
10
+ @file = Tempfile.new('intail_position_file_test').binmode
11
+ end
12
+
13
+ teardown do
14
+ @file.close rescue nil
15
+ @file.unlink rescue nil
15
16
  end
16
17
 
17
18
  UNWATCHED_STR = '%016x' % Fluent::Plugin::TailInput::PositionFile::UNWATCHED_POSITION
@@ -111,11 +111,11 @@ class AckHandlerTest < Test::Unit::TestCase
111
111
  r, w = IO.pipe
112
112
  begin
113
113
  w.write(chunk_id)
114
- def r.recv(arg)
114
+ stub(r).recv { |_|
115
115
  sleep(1) # To ensure that multiple threads select the socket before closing.
116
- raise IOError, 'stream closed in another thread' if self.closed?
116
+ raise IOError, 'stream closed in another thread' if r.closed?
117
117
  MessagePack.pack({ 'ack' => Base64.encode64('chunk_id 111') })
118
- end
118
+ }
119
119
  ack.enqueue(r)
120
120
 
121
121
  threads = []
@@ -17,7 +17,7 @@ class SocketCacheTest < Test::Unit::TestCase
17
17
  assert_equal(socket, c.checkout_or('key') { socket })
18
18
  c.checkin(socket)
19
19
 
20
- sock = mock!.open.never.subject
20
+ sock = dont_allow(mock!).open
21
21
  assert_equal(socket, c.checkout_or('key') { sock.open })
22
22
  end
23
23
 
@@ -130,7 +130,7 @@ class SocketCacheTest < Test::Unit::TestCase
130
130
 
131
131
  c = Fluent::Plugin::ForwardOutput::SocketCache.new(10, $log)
132
132
  sock = mock!.close { 'closed' }.subject
133
- sock2 = mock!.close.never.subject
133
+ sock2 = dont_allow(mock!).close
134
134
  stub(sock).inspect
135
135
  stub(sock2).inspect
136
136
 
@@ -154,7 +154,7 @@ class SocketCacheTest < Test::Unit::TestCase
154
154
  Timecop.freeze(Time.parse('2016-04-13 14:00:00 +0900'))
155
155
 
156
156
  c = Fluent::Plugin::ForwardOutput::SocketCache.new(10, $log)
157
- sock = mock!.close.never.subject
157
+ sock = dont_allow(mock!).close
158
158
  stub(sock).inspect
159
159
  c.checkout_or('key') { sock }
160
160
 
@@ -18,8 +18,7 @@ class ForwardInputTest < Test::Unit::TestCase
18
18
  Fluent::Test.setup
19
19
  @responses = [] # for testing responses after sending data
20
20
  @d = nil
21
- # forward plugin uses TCP and UDP sockets on the same port number
22
- @port = unused_port(protocol: :all)
21
+ @port = unused_port
23
22
  end
24
23
 
25
24
  def teardown
@@ -18,7 +18,7 @@ class HttpInputTest < Test::Unit::TestCase
18
18
 
19
19
  def setup
20
20
  Fluent::Test.setup
21
- @port = unused_port(protocol: :tcp)
21
+ @port = unused_port
22
22
  end
23
23
 
24
24
  def teardown
@@ -517,6 +517,28 @@ class HttpInputTest < Test::Unit::TestCase
517
517
  assert_equal_event_time time, d.events[1][1]
518
518
  end
519
519
 
520
+ def test_csp_report
521
+ d = create_driver
522
+ time = event_time("2011-01-02 13:14:15 UTC")
523
+ time_i = time.to_i
524
+ events = [
525
+ ["tag1", time, {"a"=>1}],
526
+ ["tag2", time, {"a"=>2}],
527
+ ]
528
+ res_codes = []
529
+
530
+ d.run(expect_records: 2) do
531
+ events.each do |tag, t, record|
532
+ res = post("/#{tag}?time=#{time_i.to_s}", record.to_json, {"Content-Type"=>"application/csp-report; charset=utf-8"})
533
+ res_codes << res.code
534
+ end
535
+ end
536
+ assert_equal ["200", "200"], res_codes
537
+ assert_equal events, d.events
538
+ assert_equal_event_time time, d.events[0][1]
539
+ assert_equal_event_time time, d.events[1][1]
540
+ end
541
+
520
542
  def test_application_msgpack
521
543
  d = create_driver
522
544
  time = event_time("2011-01-02 13:14:15 UTC")
@@ -982,7 +1004,7 @@ class HttpInputTest < Test::Unit::TestCase
982
1004
  assert_equal ["403", "403"], res_codes
983
1005
  end
984
1006
 
985
- def test_add_query_params
1007
+ def test_add_query_params
986
1008
  d = create_driver(config + "add_query_params true")
987
1009
  assert_equal true, d.instance.add_query_params
988
1010
 
@@ -392,7 +392,7 @@ EOC
392
392
  end
393
393
 
394
394
  test "emit" do
395
- port = unused_port(protocol: :tcp)
395
+ port = unused_port
396
396
  d = create_driver("
397
397
  @type monitor_agent
398
398
  bind '127.0.0.1'
@@ -451,7 +451,7 @@ EOC
451
451
 
452
452
  sub_test_case "servlets" do
453
453
  setup do
454
- @port = unused_port(protocol: :tcp)
454
+ @port = unused_port
455
455
  # check @type and type in one configuration
456
456
  conf = <<-EOC
457
457
  <source>
@@ -759,7 +759,7 @@ plugin_id:test_filter\tplugin_category:filter\ttype:test_filter\toutput_plugin:f
759
759
  end
760
760
 
761
761
  setup do
762
- @port = unused_port(protocol: :tcp)
762
+ @port = unused_port
763
763
  # check @type and type in one configuration
764
764
  conf = <<-EOC
765
765
  <source>
@@ -840,7 +840,7 @@ plugin_id:test_filter\tplugin_category:filter\ttype:test_filter\toutput_plugin:f
840
840
 
841
841
  sub_test_case "check the port number of http server" do
842
842
  test "on single worker environment" do
843
- port = unused_port(protocol: :tcp)
843
+ port = unused_port
844
844
  d = create_driver("
845
845
  @type monitor_agent
846
846
  bind '127.0.0.1'
@@ -851,7 +851,7 @@ plugin_id:test_filter\tplugin_category:filter\ttype:test_filter\toutput_plugin:f
851
851
  end
852
852
 
853
853
  test "worker_id = 2 on multi worker environment" do
854
- port = unused_port(protocol: :tcp)
854
+ port = unused_port
855
855
  Fluent::SystemConfig.overwrite_system_config('workers' => 4) do
856
856
  d = Fluent::Test::Driver::Input.new(Fluent::Plugin::MonitorAgentInput)
857
857
  d.instance.instance_eval{ @_fluentd_worker_id = 2 }
@@ -905,7 +905,7 @@ EOC
905
905
  end
906
906
 
907
907
  test "plugins have a variable named buffer does not throws NoMethodError" do
908
- port = unused_port(protocol: :tcp)
908
+ port = unused_port
909
909
  d = create_driver("
910
910
  @type monitor_agent
911
911
  bind '127.0.0.1'
@@ -5,24 +5,24 @@ require 'fluent/plugin/in_syslog'
5
5
  class SyslogInputTest < Test::Unit::TestCase
6
6
  def setup
7
7
  Fluent::Test.setup
8
- @port = unused_port(protocol: :udp)
8
+ @port = unused_port
9
9
  end
10
10
 
11
11
  def teardown
12
12
  @port = nil
13
13
  end
14
14
 
15
- def ipv4_config(port = @port)
15
+ def ipv4_config
16
16
  %[
17
- port #{port}
17
+ port #{@port}
18
18
  bind 127.0.0.1
19
19
  tag syslog
20
20
  ]
21
21
  end
22
22
 
23
- def ipv6_config(port = @port)
23
+ def ipv6_config
24
24
  %[
25
- port #{port}
25
+ port #{@port}
26
26
  bind ::1
27
27
  tag syslog
28
28
  ]
@@ -69,8 +69,7 @@ EOS
69
69
  'Use transport and protocol' => ["protocol_type udp\n<transport tcp>\n </transport>", :udp, :tcp])
70
70
  def test_configure_protocol(param)
71
71
  conf, proto_type, transport_proto_type = *param
72
- port = unused_port(protocol: proto_type ? proto_type : transport_proto_type)
73
- d = create_driver([ipv4_config(port), conf].join("\n"))
72
+ d = create_driver([ipv4_config, conf].join("\n"))
74
73
 
75
74
  assert_equal(d.instance.protocol_type, proto_type)
76
75
  assert_equal(d.instance.transport_config.protocol, transport_proto_type)
@@ -159,13 +158,12 @@ EOS
159
158
  end
160
159
 
161
160
  def test_msg_size_with_tcp
162
- port = unused_port(protocol: :tcp)
163
- d = create_driver([ipv4_config(port), "<transport tcp> \n</transport>"].join("\n"))
161
+ d = create_driver([ipv4_config, "<transport tcp> \n</transport>"].join("\n"))
164
162
  tests = create_test_case
165
163
 
166
164
  d.run(expect_emits: 2) do
167
165
  tests.each {|test|
168
- TCPSocket.open('127.0.0.1', port) do |s|
166
+ TCPSocket.open('127.0.0.1', @port) do |s|
169
167
  s.send(test['msg'], 0)
170
168
  end
171
169
  }
@@ -191,12 +189,11 @@ EOS
191
189
  end
192
190
 
193
191
  def test_msg_size_with_same_tcp_connection
194
- port = unused_port(protocol: :tcp)
195
- d = create_driver([ipv4_config(port), "<transport tcp> \n</transport>"].join("\n"))
192
+ d = create_driver([ipv4_config, "<transport tcp> \n</transport>"].join("\n"))
196
193
  tests = create_test_case
197
194
 
198
195
  d.run(expect_emits: 2) do
199
- TCPSocket.open('127.0.0.1', port) do |s|
196
+ TCPSocket.open('127.0.0.1', @port) do |s|
200
197
  tests.each {|test|
201
198
  s.send(test['msg'], 0)
202
199
  }
@@ -350,13 +347,12 @@ EOS
350
347
 
351
348
  sub_test_case 'octet counting frame' do
352
349
  def test_msg_size_with_tcp
353
- port = unused_port(protocol: :tcp)
354
- d = create_driver([ipv4_config(port), "<transport tcp> \n</transport>", 'frame_type octet_count'].join("\n"))
350
+ d = create_driver([ipv4_config, "<transport tcp> \n</transport>", 'frame_type octet_count'].join("\n"))
355
351
  tests = create_test_case
356
352
 
357
353
  d.run(expect_emits: 2) do
358
354
  tests.each {|test|
359
- TCPSocket.open('127.0.0.1', port) do |s|
355
+ TCPSocket.open('127.0.0.1', @port) do |s|
360
356
  s.send(test['msg'], 0)
361
357
  end
362
358
  }
@@ -367,12 +363,11 @@ EOS
367
363
  end
368
364
 
369
365
  def test_msg_size_with_same_tcp_connection
370
- port = unused_port(protocol: :tcp)
371
- d = create_driver([ipv4_config(port), "<transport tcp> \n</transport>", 'frame_type octet_count'].join("\n"))
366
+ d = create_driver([ipv4_config, "<transport tcp> \n</transport>", 'frame_type octet_count'].join("\n"))
372
367
  tests = create_test_case
373
368
 
374
369
  d.run(expect_emits: 2) do
375
- TCPSocket.open('127.0.0.1', port) do |s|
370
+ TCPSocket.open('127.0.0.1', @port) do |s|
376
371
  tests.each {|test|
377
372
  s.send(test['msg'], 0)
378
373
  }
@@ -474,8 +469,7 @@ EOS
474
469
  end
475
470
 
476
471
  def test_send_keepalive_packet_is_disabled_by_default
477
- port = unused_port(protocol: :tcp)
478
- d = create_driver(ipv4_config(port) + %[
472
+ d = create_driver(ipv4_config + %[
479
473
  <transport tcp>
480
474
  </transport>
481
475
  protocol tcp
@@ -485,20 +479,19 @@ EOS
485
479
 
486
480
  def test_send_keepalive_packet_can_be_enabled
487
481
  addr = "127.0.0.1"
488
- port = unused_port(protocol: :tcp)
489
- d = create_driver(ipv4_config(port) + %[
482
+ d = create_driver(ipv4_config + %[
490
483
  <transport tcp>
491
484
  </transport>
492
485
  send_keepalive_packet true
493
486
  ])
494
487
  assert_true d.instance.send_keepalive_packet
495
488
  mock.proxy(d.instance).server_create_connection(
496
- :in_syslog_tcp_server, port,
489
+ :in_syslog_tcp_server, @port,
497
490
  bind: addr,
498
491
  resolve_name: nil,
499
492
  send_keepalive_packet: true)
500
493
  d.run do
501
- TCPSocket.open(addr, port)
494
+ TCPSocket.open(addr, @port)
502
495
  end
503
496
  end
504
497