-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
trying to check whether fail at first or not
- Loading branch information
Showing
1 changed file
with
68 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
require_relative '../helper' | ||
require 'fluent/plugin_helper/server' | ||
require 'fluent/plugin/base' | ||
require 'timeout' | ||
|
||
require 'serverengine' | ||
require 'fileutils' | ||
|
||
class AToFailAtFirstTest < Test::Unit::TestCase | ||
class Dummy < Fluent::Plugin::TestBase | ||
helpers :server | ||
end | ||
|
||
PORT = unused_port | ||
|
||
setup do | ||
@socket_manager_path = ServerEngine::SocketManager::Server.generate_path | ||
if @socket_manager_path.is_a?(String) && File.exist?(@socket_manager_path) | ||
FileUtils.rm_f @socket_manager_path | ||
end | ||
@socket_manager_server = ServerEngine::SocketManager::Server.open(@socket_manager_path) | ||
ENV['SERVERENGINE_SOCKETMANAGER_PATH'] = @socket_manager_path.to_s | ||
|
||
@d = Dummy.new | ||
@d.start | ||
@d.after_start | ||
end | ||
|
||
teardown do | ||
@d.stopped? || @d.stop | ||
@d.before_shutdown? || @d.before_shutdown | ||
@d.shutdown? || @d.shutdown | ||
@d.after_shutdown? || @d.after_shutdown | ||
@d.closed? || @d.close | ||
@d.terminated? || @d.terminate | ||
|
||
@socket_manager_server.close | ||
if @socket_manager_server.is_a?(String) && File.exist?(@socket_manager_path) | ||
FileUtils.rm_f @socket_manager_path | ||
end | ||
end | ||
|
||
sub_test_case '#server_create and #server_create_connection' do | ||
data( | ||
'server_create tcp' => [:server_create, :tcp, {}], | ||
'server_create udp' => [:server_create, :udp, {max_bytes: 128}], | ||
# 'server_create tls' => [:server_create, :tls, {}], | ||
# 'server_create unix' => [:server_create, :unix, {}], | ||
'server_create_connection tcp' => [:server_create, :tcp, {}], | ||
# 'server_create_connection tls' => [:server_create, :tls, {}], | ||
# 'server_create_connection unix' => [:server_create, :unix, {}], | ||
) | ||
test 'cannot create 2 or more servers using same bind address and port if shared option is false' do |(m, proto, kwargs)| | ||
begin | ||
d2 = Dummy.new; d2.start; d2.after_start | ||
|
||
assert_nothing_raised do | ||
@d.__send__(m, :myserver, PORT, proto: proto, shared: false, **kwargs){|x| x } | ||
end | ||
assert_raise(Errno::EADDRINUSE) do | ||
d2.__send__(m, :myserver, PORT, proto: proto, **kwargs){|x| x } | ||
end | ||
ensure | ||
d2.stop; d2.before_shutdown; d2.shutdown; d2.after_shutdown; d2.close; d2.terminate | ||
end | ||
end | ||
end | ||
end |