Skip to content

Commit 29089bf

Browse files
committed
Add tests for timeout
Signed-off-by: Shizuo Fujita <[email protected]>
1 parent 34291fb commit 29089bf

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

spec/fluent_logger_spec.rb

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
require 'logger'
77
require 'stringio'
88
require 'fluent/logger/fluent_logger/cui'
9+
require 'timeout'
910

1011
describe Fluent::Logger::FluentLogger do
1112
let(:fluentd) {
@@ -434,4 +435,24 @@ def flush(messages)
434435
}
435436
end
436437
end
438+
439+
if Gem::Version.new(RUBY_VERSION) >= Gem::Version.new('3.0.0')
440+
context "timeout" do
441+
it ('support connect_timeout') {
442+
Timeout::timeout(5) do
443+
# Use invalid IP address to make sure that the connection will timeout.
444+
# (192.0.2.0 is a special IP address that can be used in only documentation. Ref. RFC 5737)
445+
logger = Fluent::Logger::FluentLogger.new(nil, host: '192.0.2.0', port: fluentd.port, connect_timeout: 1)
446+
expect(logger.last_error).to be_a_kind_of(IO::TimeoutError)
447+
end
448+
}
449+
it ('support resolv_timeout') {
450+
expect {
451+
# It just checks that the resolv_timeout option is supported
452+
# because it can't use a stub for the DNS resolution.
453+
Fluent::Logger::FluentLogger.new(nil, host: 'localhost', port: fluentd.port, resolv_timeout: 1)
454+
}.to_not raise_error
455+
}
456+
end
457+
end
437458
end

0 commit comments

Comments
 (0)