5
5
class SyslogInputTest < Test ::Unit ::TestCase
6
6
def setup
7
7
Fluent ::Test . setup
8
- @port = unused_port
8
+ @port = unused_port ( protocol : :udp )
9
9
end
10
10
11
11
def teardown
12
12
@port = nil
13
13
end
14
14
15
- def ipv4_config
15
+ def ipv4_config ( port = @port )
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
23
+ def ipv6_config ( port = @port )
24
24
%[
25
- port #{ @ port}
25
+ port #{ port }
26
26
bind ::1
27
27
tag syslog
28
28
]
@@ -69,7 +69,8 @@ def test_configure_resolve_hostname(param)
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
- d = create_driver ( [ ipv4_config , conf ] . join ( "\n " ) )
72
+ port = unused_port ( protocol : proto_type ? proto_type : transport_proto_type )
73
+ d = create_driver ( [ ipv4_config ( port ) , conf ] . join ( "\n " ) )
73
74
74
75
assert_equal ( d . instance . protocol_type , proto_type )
75
76
assert_equal ( d . instance . transport_config . protocol , transport_proto_type )
@@ -158,12 +159,13 @@ def test_msg_size_udp_for_large_msg
158
159
end
159
160
160
161
def test_msg_size_with_tcp
161
- d = create_driver ( [ ipv4_config , "<transport tcp> \n </transport>" ] . join ( "\n " ) )
162
+ port = unused_port ( protocol : :tcp )
163
+ d = create_driver ( [ ipv4_config ( port ) , "<transport tcp> \n </transport>" ] . join ( "\n " ) )
162
164
tests = create_test_case
163
165
164
166
d . run ( expect_emits : 2 ) do
165
167
tests . each { |test |
166
- TCPSocket . open ( '127.0.0.1' , @ port) do |s |
168
+ TCPSocket . open ( '127.0.0.1' , port ) do |s |
167
169
s . send ( test [ 'msg' ] , 0 )
168
170
end
169
171
}
@@ -189,11 +191,12 @@ def test_emit_rfc5452
189
191
end
190
192
191
193
def test_msg_size_with_same_tcp_connection
192
- d = create_driver ( [ ipv4_config , "<transport tcp> \n </transport>" ] . join ( "\n " ) )
194
+ port = unused_port ( protocol : :tcp )
195
+ d = create_driver ( [ ipv4_config ( port ) , "<transport tcp> \n </transport>" ] . join ( "\n " ) )
193
196
tests = create_test_case
194
197
195
198
d . run ( expect_emits : 2 ) do
196
- TCPSocket . open ( '127.0.0.1' , @ port) do |s |
199
+ TCPSocket . open ( '127.0.0.1' , port ) do |s |
197
200
tests . each { |test |
198
201
s . send ( test [ 'msg' ] , 0 )
199
202
}
@@ -347,12 +350,13 @@ def compare_test_result(events, tests, options = {})
347
350
348
351
sub_test_case 'octet counting frame' do
349
352
def test_msg_size_with_tcp
350
- d = create_driver ( [ ipv4_config , "<transport tcp> \n </transport>" , 'frame_type octet_count' ] . join ( "\n " ) )
353
+ port = unused_port ( protocol : :tcp )
354
+ d = create_driver ( [ ipv4_config ( port ) , "<transport tcp> \n </transport>" , 'frame_type octet_count' ] . join ( "\n " ) )
351
355
tests = create_test_case
352
356
353
357
d . run ( expect_emits : 2 ) do
354
358
tests . each { |test |
355
- TCPSocket . open ( '127.0.0.1' , @ port) do |s |
359
+ TCPSocket . open ( '127.0.0.1' , port ) do |s |
356
360
s . send ( test [ 'msg' ] , 0 )
357
361
end
358
362
}
@@ -363,11 +367,12 @@ def test_msg_size_with_tcp
363
367
end
364
368
365
369
def test_msg_size_with_same_tcp_connection
366
- d = create_driver ( [ ipv4_config , "<transport tcp> \n </transport>" , 'frame_type octet_count' ] . join ( "\n " ) )
370
+ port = unused_port ( protocol : :tcp )
371
+ d = create_driver ( [ ipv4_config ( port ) , "<transport tcp> \n </transport>" , 'frame_type octet_count' ] . join ( "\n " ) )
367
372
tests = create_test_case
368
373
369
374
d . run ( expect_emits : 2 ) do
370
- TCPSocket . open ( '127.0.0.1' , @ port) do |s |
375
+ TCPSocket . open ( '127.0.0.1' , port ) do |s |
371
376
tests . each { |test |
372
377
s . send ( test [ 'msg' ] , 0 )
373
378
}
@@ -469,7 +474,8 @@ def test_emit_unmatched_lines_with_address
469
474
end
470
475
471
476
def test_send_keepalive_packet_is_disabled_by_default
472
- d = create_driver ( ipv4_config + %[
477
+ port = unused_port ( protocol : :tcp )
478
+ d = create_driver ( ipv4_config ( port ) + %[
473
479
<transport tcp>
474
480
</transport>
475
481
protocol tcp
@@ -479,19 +485,20 @@ def test_send_keepalive_packet_is_disabled_by_default
479
485
480
486
def test_send_keepalive_packet_can_be_enabled
481
487
addr = "127.0.0.1"
482
- d = create_driver ( ipv4_config + %[
488
+ port = unused_port ( protocol : :tcp )
489
+ d = create_driver ( ipv4_config ( port ) + %[
483
490
<transport tcp>
484
491
</transport>
485
492
send_keepalive_packet true
486
493
] )
487
494
assert_true d . instance . send_keepalive_packet
488
495
mock . proxy ( d . instance ) . server_create_connection (
489
- :in_syslog_tcp_server , @ port,
496
+ :in_syslog_tcp_server , port ,
490
497
bind : addr ,
491
498
resolve_name : nil ,
492
499
send_keepalive_packet : true )
493
500
d . run do
494
- TCPSocket . open ( addr , @ port)
501
+ TCPSocket . open ( addr , port )
495
502
end
496
503
end
497
504
0 commit comments