fluentd 1.16.7-x86-mingw32 → 1.17.0-x86-mingw32
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.github/DISCUSSION_TEMPLATE/q-a-japanese.yml +50 -0
- data/.github/DISCUSSION_TEMPLATE/q-a.yml +47 -0
- data/.github/workflows/test-ruby-head.yml +31 -0
- data/.github/workflows/test.yml +2 -9
- data/CHANGELOG.md +34 -42
- data/README.md +3 -1
- data/Rakefile +1 -1
- data/fluentd.gemspec +9 -9
- data/lib/fluent/command/binlog_reader.rb +1 -1
- data/lib/fluent/command/fluentd.rb +1 -1
- data/lib/fluent/config/configure_proxy.rb +2 -2
- data/lib/fluent/config/types.rb +1 -1
- data/lib/fluent/config/yaml_parser/parser.rb +0 -4
- data/lib/fluent/configurable.rb +2 -2
- data/lib/fluent/counter/mutex_hash.rb +1 -1
- data/lib/fluent/fluent_log_event_router.rb +0 -2
- data/lib/fluent/plugin/buf_file.rb +1 -1
- data/lib/fluent/plugin/buffer/file_chunk.rb +1 -1
- data/lib/fluent/plugin/buffer/file_single_chunk.rb +2 -3
- data/lib/fluent/plugin/filter_parser.rb +26 -8
- data/lib/fluent/plugin/in_http.rb +18 -53
- data/lib/fluent/plugin/in_tail.rb +34 -2
- data/lib/fluent/plugin/out_file.rb +0 -8
- data/lib/fluent/plugin/out_http.rb +125 -13
- data/lib/fluent/plugin/owned_by_mixin.rb +0 -1
- data/lib/fluent/plugin/parser_json.rb +34 -9
- data/lib/fluent/plugin/parser_msgpack.rb +24 -3
- data/lib/fluent/plugin_helper/metrics.rb +2 -2
- data/lib/fluent/registry.rb +6 -6
- data/lib/fluent/supervisor.rb +1 -1
- data/lib/fluent/test/output_test.rb +1 -1
- data/lib/fluent/unique_id.rb +1 -1
- data/lib/fluent/version.rb +1 -1
- data/lib/fluent/winsvc.rb +3 -28
- data/test/command/test_cat.rb +2 -2
- data/test/command/test_fluentd.rb +10 -57
- data/test/helper.rb +7 -27
- data/test/log/test_console_adapter.rb +10 -3
- data/test/plugin/data/log_numeric/01.log +0 -0
- data/test/plugin/data/log_numeric/02.log +0 -0
- data/test/plugin/data/log_numeric/12.log +0 -0
- data/test/plugin/data/log_numeric/14.log +0 -0
- data/test/plugin/in_tail/test_io_handler.rb +14 -13
- data/test/plugin/in_tail/test_position_file.rb +7 -6
- data/test/plugin/out_forward/test_ack_handler.rb +3 -3
- data/test/plugin/out_forward/test_socket_cache.rb +3 -3
- data/test/plugin/test_in_forward.rb +1 -2
- data/test/plugin/test_in_http.rb +24 -2
- data/test/plugin/test_in_monitor_agent.rb +6 -6
- data/test/plugin/test_in_syslog.rb +18 -25
- data/test/plugin/test_in_tail.rb +153 -4
- data/test/plugin/test_in_tcp.rb +1 -1
- data/test/plugin/test_in_udp.rb +10 -16
- data/test/plugin/test_out_exec_filter.rb +7 -12
- data/test/plugin/test_out_file.rb +2 -22
- data/test/plugin/test_out_forward.rb +3 -2
- data/test/plugin/test_out_http.rb +128 -0
- data/test/plugin/test_out_stream.rb +1 -1
- data/test/plugin/test_owned_by.rb +0 -1
- data/test/plugin/test_parser_json.rb +106 -31
- data/test/plugin/test_parser_msgpack.rb +127 -0
- data/test/plugin/test_storage.rb +0 -1
- data/test/plugin_helper/test_child_process.rb +4 -4
- data/test/plugin_helper/test_http_server_helper.rb +1 -1
- data/test/plugin_helper/test_server.rb +41 -64
- data/test/plugin_helper/test_socket.rb +1 -1
- data/test/test_config.rb +0 -6
- data/test/test_event_router.rb +2 -2
- metadata +90 -21
@@ -8,37 +8,6 @@ class JsonParserTest < ::Test::Unit::TestCase
|
|
8
8
|
@parser = Fluent::Test::Driver::Parser.new(Fluent::Plugin::JSONParser)
|
9
9
|
end
|
10
10
|
|
11
|
-
sub_test_case "configure_json_parser" do
|
12
|
-
data("oj", [:oj, [Oj.method(:load), Oj::ParseError]])
|
13
|
-
data("json", [:json, [JSON.method(:load), JSON::ParserError]])
|
14
|
-
data("yajl", [:yajl, [Yajl.method(:load), Yajl::ParseError]])
|
15
|
-
def test_return_each_loader((input, expected_return))
|
16
|
-
result = @parser.instance.configure_json_parser(input)
|
17
|
-
assert_equal expected_return, result
|
18
|
-
end
|
19
|
-
|
20
|
-
def test_raise_exception_for_unknown_input
|
21
|
-
assert_raise RuntimeError do
|
22
|
-
@parser.instance.configure_json_parser(:unknown)
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
def test_fall_back_oj_to_yajl_if_oj_not_available
|
27
|
-
stub(Fluent::OjOptions).available? { false }
|
28
|
-
|
29
|
-
result = @parser.instance.configure_json_parser(:oj)
|
30
|
-
|
31
|
-
assert_equal [Yajl.method(:load), Yajl::ParseError], result
|
32
|
-
logs = @parser.logs.collect do |log|
|
33
|
-
log.gsub(/\A\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2} [-+]\d{4} /, "")
|
34
|
-
end
|
35
|
-
assert_equal(
|
36
|
-
["[info]: Oj is not installed, and failing back to Yajl for json parser\n"],
|
37
|
-
logs
|
38
|
-
)
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
11
|
data('oj' => 'oj', 'yajl' => 'yajl')
|
43
12
|
def test_parse(data)
|
44
13
|
@parser.configure('json_parser' => data)
|
@@ -166,4 +135,110 @@ class JsonParserTest < ::Test::Unit::TestCase
|
|
166
135
|
end
|
167
136
|
end
|
168
137
|
end
|
138
|
+
|
139
|
+
sub_test_case "various record pattern" do
|
140
|
+
data("Only string", { record: '"message"', expected: [nil] }, keep: true)
|
141
|
+
data("Only string without quotation", { record: "message", expected: [nil] }, keep: true)
|
142
|
+
data("Only number", { record: "0", expected: [nil] }, keep: true)
|
143
|
+
data(
|
144
|
+
"Array of Hash",
|
145
|
+
{
|
146
|
+
record: '[{"k1": 1}, {"k2": 2}]',
|
147
|
+
expected: [{"k1" => 1}, {"k2" => 2}]
|
148
|
+
},
|
149
|
+
keep: true,
|
150
|
+
)
|
151
|
+
data(
|
152
|
+
"Array of both Hash and invalid",
|
153
|
+
{
|
154
|
+
record: '[{"k1": 1}, "string", {"k2": 2}, 0]',
|
155
|
+
expected: [{"k1" => 1}, nil, {"k2" => 2}, nil]
|
156
|
+
},
|
157
|
+
keep: true,
|
158
|
+
)
|
159
|
+
data(
|
160
|
+
"Array of all invalid",
|
161
|
+
{
|
162
|
+
record: '["string", 0, [{"k": 0}]]',
|
163
|
+
expected: [nil, nil, nil]
|
164
|
+
},
|
165
|
+
keep: true,
|
166
|
+
)
|
167
|
+
|
168
|
+
def test_oj(data)
|
169
|
+
parsed_records = []
|
170
|
+
@parser.configure("json_parser" => "oj")
|
171
|
+
@parser.instance.parse(data[:record]) { |time, record|
|
172
|
+
parsed_records.append(record)
|
173
|
+
}
|
174
|
+
assert_equal(data[:expected], parsed_records)
|
175
|
+
end
|
176
|
+
|
177
|
+
def test_yajl(data)
|
178
|
+
parsed_records = []
|
179
|
+
@parser.configure("json_parser" => "yajl")
|
180
|
+
@parser.instance.parse(data[:record]) { |time, record|
|
181
|
+
parsed_records.append(record)
|
182
|
+
}
|
183
|
+
assert_equal(data[:expected], parsed_records)
|
184
|
+
end
|
185
|
+
|
186
|
+
def test_json(json)
|
187
|
+
parsed_records = []
|
188
|
+
@parser.configure("json_parser" => "json")
|
189
|
+
@parser.instance.parse(data[:record]) { |time, record|
|
190
|
+
parsed_records.append(record)
|
191
|
+
}
|
192
|
+
assert_equal(data[:expected], parsed_records)
|
193
|
+
end
|
194
|
+
end
|
195
|
+
|
196
|
+
# This becomes NoMethodError if a non-Hash object is passed to convert_values.
|
197
|
+
# https://github.com/fluent/fluentd/issues/4100
|
198
|
+
sub_test_case "execute_convert_values with null_empty_string" do
|
199
|
+
data("Only string", { record: '"message"', expected: [nil] }, keep: true)
|
200
|
+
data(
|
201
|
+
"Hash",
|
202
|
+
{
|
203
|
+
record: '{"k1": 1, "k2": ""}',
|
204
|
+
expected: [{"k1" => 1, "k2" => nil}]
|
205
|
+
},
|
206
|
+
keep: true,
|
207
|
+
)
|
208
|
+
data(
|
209
|
+
"Array of Hash",
|
210
|
+
{
|
211
|
+
record: '[{"k1": 1}, {"k2": ""}]',
|
212
|
+
expected: [{"k1" => 1}, {"k2" => nil}]
|
213
|
+
},
|
214
|
+
keep: true,
|
215
|
+
)
|
216
|
+
|
217
|
+
def test_oj(data)
|
218
|
+
parsed_records = []
|
219
|
+
@parser.configure("json_parser" => "oj", "null_empty_string" => true)
|
220
|
+
@parser.instance.parse(data[:record]) { |time, record|
|
221
|
+
parsed_records.append(record)
|
222
|
+
}
|
223
|
+
assert_equal(data[:expected], parsed_records)
|
224
|
+
end
|
225
|
+
|
226
|
+
def test_yajl(data)
|
227
|
+
parsed_records = []
|
228
|
+
@parser.configure("json_parser" => "yajl", "null_empty_string" => true)
|
229
|
+
@parser.instance.parse(data[:record]) { |time, record|
|
230
|
+
parsed_records.append(record)
|
231
|
+
}
|
232
|
+
assert_equal(data[:expected], parsed_records)
|
233
|
+
end
|
234
|
+
|
235
|
+
def test_json(json)
|
236
|
+
parsed_records = []
|
237
|
+
@parser.configure("json_parser" => "json", "null_empty_string" => true)
|
238
|
+
@parser.instance.parse(data[:record]) { |time, record|
|
239
|
+
parsed_records.append(record)
|
240
|
+
}
|
241
|
+
assert_equal(data[:expected], parsed_records)
|
242
|
+
end
|
243
|
+
end
|
169
244
|
end
|
@@ -0,0 +1,127 @@
|
|
1
|
+
require_relative '../helper'
|
2
|
+
require 'fluent/test/driver/parser'
|
3
|
+
require 'fluent/plugin/parser_msgpack'
|
4
|
+
|
5
|
+
class MessagePackParserTest < ::Test::Unit::TestCase
|
6
|
+
def setup
|
7
|
+
Fluent::Test.setup
|
8
|
+
end
|
9
|
+
|
10
|
+
def create_driver(conf)
|
11
|
+
Fluent::Test::Driver::Parser.new(Fluent::Plugin::MessagePackParser).configure(conf)
|
12
|
+
end
|
13
|
+
|
14
|
+
sub_test_case "simple setting" do
|
15
|
+
data(
|
16
|
+
"Normal Hash",
|
17
|
+
{
|
18
|
+
input: "\x82\xA7message\xADHello msgpack\xA3numd",
|
19
|
+
expected: [{"message" => "Hello msgpack", "num" => 100}]
|
20
|
+
},
|
21
|
+
keep: true
|
22
|
+
)
|
23
|
+
data(
|
24
|
+
"Array of multiple Hash",
|
25
|
+
{
|
26
|
+
input: "\x92\x81\xA7message\xA3foo\x81\xA7message\xA3bar",
|
27
|
+
expected: [{"message"=>"foo"}, {"message"=>"bar"}]
|
28
|
+
},
|
29
|
+
keep: true
|
30
|
+
)
|
31
|
+
data(
|
32
|
+
"String",
|
33
|
+
{
|
34
|
+
# "Hello msgpack".to_msgpack
|
35
|
+
input: "\xADHello msgpack",
|
36
|
+
expected: [nil]
|
37
|
+
},
|
38
|
+
keep: true
|
39
|
+
)
|
40
|
+
data(
|
41
|
+
"Array of String",
|
42
|
+
{
|
43
|
+
# ["foo", "bar"].to_msgpack
|
44
|
+
input: "\x92\xA3foo\xA3bar",
|
45
|
+
expected: [nil, nil]
|
46
|
+
},
|
47
|
+
keep: true
|
48
|
+
)
|
49
|
+
data(
|
50
|
+
"Array of String and Hash",
|
51
|
+
{
|
52
|
+
# ["foo", {message: "bar"}].to_msgpack
|
53
|
+
input: "\x92\xA3foo\x81\xA7message\xA3bar",
|
54
|
+
expected: [nil, {"message"=>"bar"}]
|
55
|
+
},
|
56
|
+
keep: true
|
57
|
+
)
|
58
|
+
|
59
|
+
def test_parse(data)
|
60
|
+
parsed_records = []
|
61
|
+
create_driver("").instance.parse(data[:input]) do |time, record|
|
62
|
+
parsed_records.append(record)
|
63
|
+
end
|
64
|
+
assert_equal(data[:expected], parsed_records)
|
65
|
+
end
|
66
|
+
|
67
|
+
def test_parse_io(data)
|
68
|
+
parsed_records = []
|
69
|
+
StringIO.open(data[:input]) do |io|
|
70
|
+
create_driver("").instance.parse_io(io) do |time, record|
|
71
|
+
parsed_records.append(record)
|
72
|
+
end
|
73
|
+
end
|
74
|
+
assert_equal(data[:expected], parsed_records)
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
# This becomes NoMethodError if a non-Hash object is passed to convert_values.
|
79
|
+
# https://github.com/fluent/fluentd/issues/4100
|
80
|
+
sub_test_case "execute_convert_values with null_empty_string" do
|
81
|
+
data(
|
82
|
+
"Normal hash",
|
83
|
+
{
|
84
|
+
# {message: "foo", empty: ""}.to_msgpack
|
85
|
+
input: "\x82\xA7message\xA3foo\xA5empty\xA0",
|
86
|
+
expected: [{"message" => "foo", "empty" => nil}]
|
87
|
+
},
|
88
|
+
keep: true
|
89
|
+
)
|
90
|
+
data(
|
91
|
+
"Array of multiple Hash",
|
92
|
+
{
|
93
|
+
# [{message: "foo", empty: ""}, {message: "bar", empty: ""}].to_msgpack
|
94
|
+
input: "\x92\x82\xA7message\xA3foo\xA5empty\xA0\x82\xA7message\xA3bar\xA5empty\xA0",
|
95
|
+
expected: [{"message"=>"foo", "empty" => nil}, {"message"=>"bar", "empty" => nil}]
|
96
|
+
},
|
97
|
+
keep: true
|
98
|
+
)
|
99
|
+
data(
|
100
|
+
"String",
|
101
|
+
{
|
102
|
+
# "Hello msgpack".to_msgpack
|
103
|
+
input: "\xADHello msgpack",
|
104
|
+
expected: [nil]
|
105
|
+
},
|
106
|
+
keep: true
|
107
|
+
)
|
108
|
+
|
109
|
+
def test_parse(data)
|
110
|
+
parsed_records = []
|
111
|
+
create_driver("null_empty_string").instance.parse(data[:input]) do |time, record|
|
112
|
+
parsed_records.append(record)
|
113
|
+
end
|
114
|
+
assert_equal(data[:expected], parsed_records)
|
115
|
+
end
|
116
|
+
|
117
|
+
def test_parse_io(data)
|
118
|
+
parsed_records = []
|
119
|
+
StringIO.open(data[:input]) do |io|
|
120
|
+
create_driver("null_empty_string").instance.parse_io(io) do |time, record|
|
121
|
+
parsed_records.append(record)
|
122
|
+
end
|
123
|
+
end
|
124
|
+
assert_equal(data[:expected], parsed_records)
|
125
|
+
end
|
126
|
+
end
|
127
|
+
end
|
data/test/plugin/test_storage.rb
CHANGED
@@ -68,7 +68,6 @@ class StorageTest < Test::Unit::TestCase
|
|
68
68
|
|
69
69
|
assert_equal 'mytest', s.owner.system_config.process_name
|
70
70
|
assert_equal '1', s.instance_eval{ @_plugin_id }
|
71
|
-
assert_equal true, s.instance_eval{ @_plugin_id_configured }
|
72
71
|
end
|
73
72
|
|
74
73
|
test 'does NOT have features for high-performance/high-consistent storages' do
|
@@ -569,7 +569,7 @@ class ChildProcessTest < Test::Unit::TestCase
|
|
569
569
|
unless Fluent.windows?
|
570
570
|
test 'can specify subprocess name' do
|
571
571
|
io = IO.popen([["cat", "caaaaaaaaaaat"], '-'])
|
572
|
-
process_naming_enabled = (
|
572
|
+
process_naming_enabled = (IO.popen(["ps", "opid,cmd"]){|_io| _io.readlines }.count{|line| line.include?("caaaaaaaaaaat") } > 0)
|
573
573
|
Process.kill(:TERM, io.pid) rescue nil
|
574
574
|
io.close rescue nil
|
575
575
|
|
@@ -586,7 +586,7 @@ class ChildProcessTest < Test::Unit::TestCase
|
|
586
586
|
m.lock
|
587
587
|
ran = true
|
588
588
|
pids << @d.child_process_id
|
589
|
-
proc_lines +=
|
589
|
+
proc_lines += IO.popen(["ps", "opid,cmd"]){|_io| _io.readlines }
|
590
590
|
m.unlock
|
591
591
|
readio.read
|
592
592
|
end
|
@@ -645,8 +645,8 @@ class ChildProcessTest < Test::Unit::TestCase
|
|
645
645
|
unless Fluent.windows?
|
646
646
|
test 'can change working directory' do
|
647
647
|
# check my real /tmp directory (for mac)
|
648
|
-
cmd =
|
649
|
-
mytmpdir =
|
648
|
+
cmd = ['ruby', '-e', 'Dir.chdir("/tmp"); puts Dir.pwd']
|
649
|
+
mytmpdir = IO.popen(cmd){|io| io.read.chomp }
|
650
650
|
|
651
651
|
m = Mutex.new
|
652
652
|
str = nil
|
@@ -15,7 +15,7 @@ class ServerPluginHelperTest < Test::Unit::TestCase
|
|
15
15
|
TMP_DIR = File.expand_path(File.dirname(__FILE__) + "/../tmp/plugin_helper_server")
|
16
16
|
|
17
17
|
setup do
|
18
|
-
@port = unused_port
|
18
|
+
@port = unused_port
|
19
19
|
if Fluent.windows?
|
20
20
|
@socket_manager_server = ServerEngine::SocketManager::Server.open
|
21
21
|
@socket_manager_path = @socket_manager_server.path
|
@@ -233,12 +233,11 @@ class ServerPluginHelperTest < Test::Unit::TestCase
|
|
233
233
|
# 'server_create_connection tcp' => [:server_create_connection, :unix],
|
234
234
|
)
|
235
235
|
test 'raise error if udp options specified for tcp/tls/unix' do |(m, proto)|
|
236
|
-
port = unused_port(protocol: proto)
|
237
236
|
assert_raise ArgumentError do
|
238
|
-
@d.__send__(m, :myserver, port, proto: proto, max_bytes: 128){|x| x }
|
237
|
+
@d.__send__(m, :myserver, @port, proto: proto, max_bytes: 128){|x| x }
|
239
238
|
end
|
240
239
|
assert_raise ArgumentError do
|
241
|
-
@d.__send__(m, :myserver, port, proto: proto, flags: 1){|x| x }
|
240
|
+
@d.__send__(m, :myserver, @port, proto: proto, flags: 1){|x| x }
|
242
241
|
end
|
243
242
|
end
|
244
243
|
|
@@ -246,9 +245,8 @@ class ServerPluginHelperTest < Test::Unit::TestCase
|
|
246
245
|
'server_create udp' => [:server_create, :udp],
|
247
246
|
)
|
248
247
|
test 'raise error if tcp/tls options specified for udp' do |(m, proto)|
|
249
|
-
port = unused_port(protocol: proto)
|
250
248
|
assert_raise(ArgumentError.new("BUG: linger_timeout is available for tcp/tls")) do
|
251
|
-
@d.__send__(m, :myserver, port, proto: proto, linger_timeout: 1, max_bytes: 128){|x| x }
|
249
|
+
@d.__send__(m, :myserver, @port, proto: proto, linger_timeout: 1, max_bytes: 128){|x| x }
|
252
250
|
end
|
253
251
|
end
|
254
252
|
|
@@ -256,9 +254,8 @@ class ServerPluginHelperTest < Test::Unit::TestCase
|
|
256
254
|
'server_create udp' => [:server_create, :udp],
|
257
255
|
)
|
258
256
|
test 'raise error if tcp/tls/unix backlog options specified for udp' do |(m, proto)|
|
259
|
-
port = unused_port(protocol: proto)
|
260
257
|
assert_raise(ArgumentError.new("BUG: backlog is available for tcp/tls")) do
|
261
|
-
@d.__send__(m, :myserver, port, proto: proto, backlog: 500){|x| x }
|
258
|
+
@d.__send__(m, :myserver, @port, proto: proto, backlog: 500){|x| x }
|
262
259
|
end
|
263
260
|
end
|
264
261
|
|
@@ -266,9 +263,8 @@ class ServerPluginHelperTest < Test::Unit::TestCase
|
|
266
263
|
'server_create udp' => [:server_create, :udp],
|
267
264
|
)
|
268
265
|
test 'raise error if tcp/tls send_keepalive_packet option is specified for udp' do |(m, proto)|
|
269
|
-
port = unused_port(protocol: proto)
|
270
266
|
assert_raise(ArgumentError.new("BUG: send_keepalive_packet is available for tcp/tls")) do
|
271
|
-
@d.__send__(m, :myserver, port, proto: proto, send_keepalive_packet: true){|x| x }
|
267
|
+
@d.__send__(m, :myserver, @port, proto: proto, send_keepalive_packet: true){|x| x }
|
272
268
|
end
|
273
269
|
end
|
274
270
|
|
@@ -280,9 +276,8 @@ class ServerPluginHelperTest < Test::Unit::TestCase
|
|
280
276
|
# 'server_create_connection unix' => [:server_create_connection, :unix, {}],
|
281
277
|
)
|
282
278
|
test 'raise error if tls options specified for tcp/udp/unix' do |(m, proto, kwargs)|
|
283
|
-
port = unused_port(protocol: proto)
|
284
279
|
assert_raise(ArgumentError.new("BUG: tls_options is available only for tls")) do
|
285
|
-
@d.__send__(m, :myserver, port, proto: proto, tls_options: {}, **kwargs){|x| x }
|
280
|
+
@d.__send__(m, :myserver, @port, proto: proto, tls_options: {}, **kwargs){|x| x }
|
286
281
|
end
|
287
282
|
end
|
288
283
|
|
@@ -294,8 +289,7 @@ class ServerPluginHelperTest < Test::Unit::TestCase
|
|
294
289
|
'server_create_connection tls' => [:server_create_connection, :tls, {tls_options: {insecure: true}}],
|
295
290
|
)
|
296
291
|
test 'can bind specified IPv4 address' do |(m, proto, kwargs)|
|
297
|
-
port
|
298
|
-
@d.__send__(m, :myserver, port, proto: proto, bind: "127.0.0.1", **kwargs){|x| x }
|
292
|
+
@d.__send__(m, :myserver, @port, proto: proto, bind: "127.0.0.1", **kwargs){|x| x }
|
299
293
|
assert_equal "127.0.0.1", @d._servers.first.bind
|
300
294
|
assert_equal "127.0.0.1", @d._servers.first.server.instance_eval{ instance_variable_defined?(:@listen_socket) ? @listen_socket : @_io }.addr[3]
|
301
295
|
end
|
@@ -309,8 +303,7 @@ class ServerPluginHelperTest < Test::Unit::TestCase
|
|
309
303
|
)
|
310
304
|
test 'can bind specified IPv6 address' do |(m, proto, kwargs)| # if available
|
311
305
|
omit "IPv6 unavailable here" unless ipv6_enabled?
|
312
|
-
port
|
313
|
-
@d.__send__(m, :myserver, port, proto: proto, bind: "::1", **kwargs){|x| x }
|
306
|
+
@d.__send__(m, :myserver, @port, proto: proto, bind: "::1", **kwargs){|x| x }
|
314
307
|
assert_equal "::1", @d._servers.first.bind
|
315
308
|
assert_equal "::1", @d._servers.first.server.instance_eval{ instance_variable_defined?(:@listen_socket) ? @listen_socket : @_io }.addr[3]
|
316
309
|
end
|
@@ -327,11 +320,10 @@ class ServerPluginHelperTest < Test::Unit::TestCase
|
|
327
320
|
test 'can create 2 or more servers which share same bind address and port if shared option is true' do |(m, proto, kwargs)|
|
328
321
|
begin
|
329
322
|
d2 = Dummy.new; d2.start; d2.after_start
|
330
|
-
port = unused_port(protocol: proto)
|
331
323
|
|
332
324
|
assert_nothing_raised do
|
333
|
-
@d.__send__(m, :myserver, port, proto: proto, **kwargs){|x| x }
|
334
|
-
d2.__send__(m, :myserver, port, proto: proto, **kwargs){|x| x }
|
325
|
+
@d.__send__(m, :myserver, @port, proto: proto, **kwargs){|x| x }
|
326
|
+
d2.__send__(m, :myserver, @port, proto: proto, **kwargs){|x| x }
|
335
327
|
end
|
336
328
|
ensure
|
337
329
|
d2.stop; d2.before_shutdown; d2.shutdown; d2.after_shutdown; d2.close; d2.terminate
|
@@ -352,13 +344,12 @@ class ServerPluginHelperTest < Test::Unit::TestCase
|
|
352
344
|
test 'cannot create 2 or more servers using same bind address and port if shared option is false' do |(m, proto, kwargs)|
|
353
345
|
begin
|
354
346
|
d2 = Dummy.new; d2.start; d2.after_start
|
355
|
-
port = unused_port(protocol: proto)
|
356
347
|
|
357
348
|
assert_nothing_raised do
|
358
|
-
@d.__send__(m, :myserver, port, proto: proto, shared: false, **kwargs){|x| x }
|
349
|
+
@d.__send__(m, :myserver, @port, proto: proto, shared: false, **kwargs){|x| x }
|
359
350
|
end
|
360
351
|
assert_raise(Errno::EADDRINUSE, Errno::EACCES) do
|
361
|
-
d2.__send__(m, :myserver, port, proto: proto, **kwargs){|x| x }
|
352
|
+
d2.__send__(m, :myserver, @port, proto: proto, **kwargs){|x| x }
|
362
353
|
end
|
363
354
|
ensure
|
364
355
|
d2.stop; d2.before_shutdown; d2.shutdown; d2.after_shutdown; d2.close; d2.terminate
|
@@ -374,18 +365,16 @@ class ServerPluginHelperTest < Test::Unit::TestCase
|
|
374
365
|
# 'unix' => [:unix, {}],
|
375
366
|
)
|
376
367
|
test 'raise error if block argument is not specified or too many' do |(proto, kwargs)|
|
377
|
-
port = unused_port(protocol: proto)
|
378
368
|
assert_raise(ArgumentError.new("BUG: block must have 1 or 2 arguments")) do
|
379
|
-
@d.server_create(:myserver, port, proto: proto, **kwargs){ 1 }
|
369
|
+
@d.server_create(:myserver, @port, proto: proto, **kwargs){ 1 }
|
380
370
|
end
|
381
371
|
assert_raise(ArgumentError.new("BUG: block must have 1 or 2 arguments")) do
|
382
|
-
@d.server_create(:myserver, port, proto: proto, **kwargs){|sock, conn, what_is_this| 1 }
|
372
|
+
@d.server_create(:myserver, @port, proto: proto, **kwargs){|sock, conn, what_is_this| 1 }
|
383
373
|
end
|
384
374
|
end
|
385
375
|
|
386
376
|
test 'creates udp server if specified in proto' do
|
387
|
-
port
|
388
|
-
@d.server_create(:myserver, port, proto: :udp, max_bytes: 512){|x| x }
|
377
|
+
@d.server_create(:myserver, @port, proto: :udp, max_bytes: 512){|x| x }
|
389
378
|
|
390
379
|
created_server_info = @d._servers.first
|
391
380
|
assert_equal :udp, created_server_info.proto
|
@@ -598,8 +587,7 @@ class ServerPluginHelperTest < Test::Unit::TestCase
|
|
598
587
|
sub_test_case '#server_create_udp' do
|
599
588
|
test 'can accept all keyword arguments valid for udp server' do
|
600
589
|
assert_nothing_raised do
|
601
|
-
port
|
602
|
-
@d.server_create_udp(:s, port, bind: '127.0.0.1', shared: false, resolve_name: true, max_bytes: 100, flags: 1) do |data, conn|
|
590
|
+
@d.server_create_udp(:s, @port, bind: '127.0.0.1', shared: false, resolve_name: true, max_bytes: 100, flags: 1) do |data, conn|
|
603
591
|
# ...
|
604
592
|
end
|
605
593
|
end
|
@@ -607,15 +595,14 @@ class ServerPluginHelperTest < Test::Unit::TestCase
|
|
607
595
|
|
608
596
|
test 'creates a udp server just to read data' do
|
609
597
|
received = ""
|
610
|
-
port
|
611
|
-
@d.server_create_udp(:s, port, max_bytes: 128) do |data|
|
598
|
+
@d.server_create_udp(:s, @port, max_bytes: 128) do |data|
|
612
599
|
received << data
|
613
600
|
end
|
614
601
|
bind_port = unused_port(protocol: :udp, bind: "127.0.0.1")
|
615
602
|
3.times do
|
616
603
|
sock = UDPSocket.new(Socket::AF_INET)
|
617
604
|
sock.bind("127.0.0.1", bind_port)
|
618
|
-
sock.connect("127.0.0.1", port)
|
605
|
+
sock.connect("127.0.0.1", @port)
|
619
606
|
sock.puts "yay"
|
620
607
|
sock.puts "foo"
|
621
608
|
sock.close
|
@@ -627,17 +614,16 @@ class ServerPluginHelperTest < Test::Unit::TestCase
|
|
627
614
|
test 'creates a udp server to read and write data' do
|
628
615
|
received = ""
|
629
616
|
responses = []
|
630
|
-
port
|
631
|
-
@d.server_create_udp(:s, port, max_bytes: 128) do |data, sock|
|
617
|
+
@d.server_create_udp(:s, @port, max_bytes: 128) do |data, sock|
|
632
618
|
received << data
|
633
619
|
sock.write "ack\n"
|
634
620
|
end
|
635
|
-
bind_port = unused_port
|
621
|
+
bind_port = unused_port
|
636
622
|
3.times do
|
637
623
|
begin
|
638
624
|
sock = UDPSocket.new(Socket::AF_INET)
|
639
625
|
sock.bind("127.0.0.1", bind_port)
|
640
|
-
sock.connect("127.0.0.1", port)
|
626
|
+
sock.connect("127.0.0.1", @port)
|
641
627
|
th = Thread.new do
|
642
628
|
while true
|
643
629
|
begin
|
@@ -668,12 +654,11 @@ class ServerPluginHelperTest < Test::Unit::TestCase
|
|
668
654
|
|
669
655
|
received = ""
|
670
656
|
responses = []
|
671
|
-
port
|
672
|
-
@d.server_create_udp(:s, port, bind: "::1", max_bytes: 128) do |data, sock|
|
657
|
+
@d.server_create_udp(:s, @port, bind: "::1", max_bytes: 128) do |data, sock|
|
673
658
|
received << data
|
674
659
|
sock.write "ack\n"
|
675
660
|
end
|
676
|
-
bind_port = unused_port
|
661
|
+
bind_port = unused_port
|
677
662
|
3.times do
|
678
663
|
begin
|
679
664
|
sock = UDPSocket.new(Socket::AF_INET6)
|
@@ -682,7 +667,7 @@ class ServerPluginHelperTest < Test::Unit::TestCase
|
|
682
667
|
responses << sock.recv(16)
|
683
668
|
true
|
684
669
|
end
|
685
|
-
sock.connect("::1", port)
|
670
|
+
sock.connect("::1", @port)
|
686
671
|
sock.write "yay\nfoo\n"
|
687
672
|
th.join(5)
|
688
673
|
ensure
|
@@ -697,14 +682,13 @@ class ServerPluginHelperTest < Test::Unit::TestCase
|
|
697
682
|
test 'does not resolve name of client address in default' do
|
698
683
|
received = ""
|
699
684
|
sources = []
|
700
|
-
port
|
701
|
-
@d.server_create_udp(:s, port, max_bytes: 128) do |data, sock|
|
685
|
+
@d.server_create_udp(:s, @port, max_bytes: 128) do |data, sock|
|
702
686
|
received << data
|
703
687
|
sources << sock.remote_host
|
704
688
|
end
|
705
689
|
3.times do
|
706
690
|
sock = UDPSocket.new(Socket::AF_INET)
|
707
|
-
sock.connect("127.0.0.1", port)
|
691
|
+
sock.connect("127.0.0.1", @port)
|
708
692
|
sock.puts "yay"
|
709
693
|
sock.close
|
710
694
|
end
|
@@ -718,14 +702,13 @@ class ServerPluginHelperTest < Test::Unit::TestCase
|
|
718
702
|
|
719
703
|
received = ""
|
720
704
|
sources = []
|
721
|
-
port
|
722
|
-
@d.server_create_udp(:s, port, resolve_name: true, max_bytes: 128) do |data, sock|
|
705
|
+
@d.server_create_udp(:s, @port, resolve_name: true, max_bytes: 128) do |data, sock|
|
723
706
|
received << data
|
724
707
|
sources << sock.remote_host
|
725
708
|
end
|
726
709
|
3.times do
|
727
710
|
sock = UDPSocket.new(Socket::AF_INET)
|
728
|
-
sock.connect("127.0.0.1", port)
|
711
|
+
sock.connect("127.0.0.1", @port)
|
729
712
|
sock.puts "yay"
|
730
713
|
sock.close
|
731
714
|
end
|
@@ -737,8 +720,7 @@ class ServerPluginHelperTest < Test::Unit::TestCase
|
|
737
720
|
test 'raises error if plugin registers data callback for connection object from #server_create' do
|
738
721
|
received = ""
|
739
722
|
errors = []
|
740
|
-
port
|
741
|
-
@d.server_create_udp(:s, port, max_bytes: 128) do |data, sock|
|
723
|
+
@d.server_create_udp(:s, @port, max_bytes: 128) do |data, sock|
|
742
724
|
received << data
|
743
725
|
begin
|
744
726
|
sock.data{|d| received << d.upcase }
|
@@ -747,7 +729,7 @@ class ServerPluginHelperTest < Test::Unit::TestCase
|
|
747
729
|
end
|
748
730
|
end
|
749
731
|
sock = UDPSocket.new(Socket::AF_INET)
|
750
|
-
sock.connect("127.0.0.1", port)
|
732
|
+
sock.connect("127.0.0.1", @port)
|
751
733
|
sock.write "foo\n"
|
752
734
|
sock.close
|
753
735
|
|
@@ -760,8 +742,7 @@ class ServerPluginHelperTest < Test::Unit::TestCase
|
|
760
742
|
test 'raise error if plugin registers write_complete callback for udp' do
|
761
743
|
received = ""
|
762
744
|
errors = []
|
763
|
-
port
|
764
|
-
@d.server_create_udp(:s, port, max_bytes: 128) do |data, sock|
|
745
|
+
@d.server_create_udp(:s, @port, max_bytes: 128) do |data, sock|
|
765
746
|
received << data
|
766
747
|
begin
|
767
748
|
sock.on(:write_complete){|conn| "" }
|
@@ -770,7 +751,7 @@ class ServerPluginHelperTest < Test::Unit::TestCase
|
|
770
751
|
end
|
771
752
|
end
|
772
753
|
sock = UDPSocket.new(Socket::AF_INET)
|
773
|
-
sock.connect("127.0.0.1", port)
|
754
|
+
sock.connect("127.0.0.1", @port)
|
774
755
|
sock.write "foo\n"
|
775
756
|
sock.close
|
776
757
|
|
@@ -783,8 +764,7 @@ class ServerPluginHelperTest < Test::Unit::TestCase
|
|
783
764
|
test 'raises error if plugin registers close callback for udp' do
|
784
765
|
received = ""
|
785
766
|
errors = []
|
786
|
-
port
|
787
|
-
@d.server_create_udp(:s, port, max_bytes: 128) do |data, sock|
|
767
|
+
@d.server_create_udp(:s, @port, max_bytes: 128) do |data, sock|
|
788
768
|
received << data
|
789
769
|
begin
|
790
770
|
sock.on(:close){|d| "" }
|
@@ -793,7 +773,7 @@ class ServerPluginHelperTest < Test::Unit::TestCase
|
|
793
773
|
end
|
794
774
|
end
|
795
775
|
sock = UDPSocket.new(Socket::AF_INET)
|
796
|
-
sock.connect("127.0.0.1", port)
|
776
|
+
sock.connect("127.0.0.1", @port)
|
797
777
|
sock.write "foo\n"
|
798
778
|
sock.close
|
799
779
|
|
@@ -806,12 +786,11 @@ class ServerPluginHelperTest < Test::Unit::TestCase
|
|
806
786
|
test 'can bind IPv4 / IPv6 together' do
|
807
787
|
omit "IPv6 unavailable here" unless ipv6_enabled?
|
808
788
|
|
809
|
-
port = unused_port(protocol: :udp)
|
810
789
|
assert_nothing_raised do
|
811
|
-
@d.server_create_udp(:s_ipv4_udp, port, bind: '0.0.0.0', shared: false, max_bytes: 128) do |data, sock|
|
790
|
+
@d.server_create_udp(:s_ipv4_udp, @port, bind: '0.0.0.0', shared: false, max_bytes: 128) do |data, sock|
|
812
791
|
# ...
|
813
792
|
end
|
814
|
-
@d.server_create_udp(:s_ipv6_udp, port, bind: '::', shared: false, max_bytes: 128) do |data, sock|
|
793
|
+
@d.server_create_udp(:s_ipv6_udp, @port, bind: '::', shared: false, max_bytes: 128) do |data, sock|
|
815
794
|
# ...
|
816
795
|
end
|
817
796
|
end
|
@@ -824,12 +803,11 @@ class ServerPluginHelperTest < Test::Unit::TestCase
|
|
824
803
|
max_bytes, records, expected = data.values
|
825
804
|
|
826
805
|
actual_records = []
|
827
|
-
port
|
828
|
-
@d.server_create_udp(:myserver, port, max_bytes: max_bytes) do |data, sock|
|
806
|
+
@d.server_create_udp(:myserver, @port, max_bytes: max_bytes) do |data, sock|
|
829
807
|
actual_records << data
|
830
808
|
end
|
831
809
|
|
832
|
-
open_client(:udp, "127.0.0.1", port) do |sock|
|
810
|
+
open_client(:udp, "127.0.0.1", @port) do |sock|
|
833
811
|
records.each do |record|
|
834
812
|
sock.send(record, 0)
|
835
813
|
end
|
@@ -845,12 +823,11 @@ class ServerPluginHelperTest < Test::Unit::TestCase
|
|
845
823
|
max_bytes, records, expected = data.values
|
846
824
|
|
847
825
|
actual_records = []
|
848
|
-
port
|
849
|
-
@d.server_create_udp(:myserver, port, max_bytes: max_bytes) do |data|
|
826
|
+
@d.server_create_udp(:myserver, @port, max_bytes: max_bytes) do |data|
|
850
827
|
actual_records << data
|
851
828
|
end
|
852
829
|
|
853
|
-
open_client(:udp, "127.0.0.1", port) do |sock|
|
830
|
+
open_client(:udp, "127.0.0.1", @port) do |sock|
|
854
831
|
records.each do |record|
|
855
832
|
sock.send(record, 0)
|
856
833
|
end
|