Skip to content

Commit d1ecee0

Browse files
committed
Add tests for timeout
Signed-off-by: Shizuo Fujita <[email protected]>
1 parent ee3f0d6 commit d1ecee0

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

spec/fluent_logger_spec.rb

Lines changed: 20 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,23 @@ 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+
logger = Fluent::Logger::FluentLogger.new(nil, host: '192.0.2.0', port: fluentd.port, connect_timeout: 1)
445+
expect(logger.last_error).to be_a_kind_of(IO::TimeoutError)
446+
end
447+
}
448+
it ('support resolv_timeout') {
449+
expect {
450+
# It just checks that the resolv_timeout option is supported
451+
# because it can't use a stub for the DNS resolution.
452+
Fluent::Logger::FluentLogger.new(nil, host: 'localhost', port: fluentd.port, resolv_timeout: 1)
453+
}.to_not raise_error
454+
}
455+
end
456+
end
437457
end

0 commit comments

Comments
 (0)