Skip to content

Commit

Permalink
trying to check whether fail at first or not
Browse files Browse the repository at this point in the history
  • Loading branch information
tagomoris committed Nov 22, 2016
1 parent 1c49168 commit a7f83ce
Showing 1 changed file with 68 additions and 0 deletions.
68 changes: 68 additions & 0 deletions test/test_a.rb
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

0 comments on commit a7f83ce

Please sign in to comment.