A collection of testing facilities, mostly for RSpec.
- TESTING_FILE_DESCRIPTORS
The minimum number of file descriptors required for testing
Add hooks when the given context
has helpers added to it.
def self::included( context )
context.let( :gossip_hub ) { "inproc://gossip-hub-%s" % [ SecureRandom.hex(16) ] }
context.before( :each ) do
@gossip_endpoint = nil
@started_zyre_nodes = []
end
context.after( :each ) do
@started_zyre_nodes.each( &:stop )
end
super
end
Reset file descriptor limit higher for OSes that have low limits, e.g., OSX. Refs: - wiki.zeromq.org/docs:tuning-zeromq#toc1
def check_fdmax
current_fdmax, max_fdmax = Process.getrlimit( :NOFILE )
if max_fdmax < TESTING_FILE_DESCRIPTORS
warn <<~END_WARNING
>>>
>>> Can't set file-descriptor ulimit to #{TESTING_FILE_DESCRIPTORS}. Later specs
>>> might fail due to lack of file descriptors.
>>>
END_WARNING
else
Process.setrlimit( :NOFILE, TESTING_FILE_DESCRIPTORS ) if
current_fdmax < TESTING_FILE_DESCRIPTORS
end
end
started_node( name=nil ) { |node| ... }
Return a node that’s been configured and started.
def started_node( name=nil )
node = Zyre::Node.new( name )
node.endpoint = 'inproc://node-test-%s' % [ SecureRandom.hex(16) ]
yield( node ) if block_given?
if @gossip_endpoint
node.gossip_connect( @gossip_endpoint )
else
@gossip_endpoint = gossip_hub()
node.gossip_bind( @gossip_endpoint )
sleep 0.25
end
node.start
@started_zyre_nodes << node
return node
end