Zyre::

Testing module

A collection of testing facilities, mostly for RSpec.

Constants

TESTING_FILE_DESCRIPTORS

The minimum number of file descriptors required for testing

Public Class Methods

included( context )

Add hooks when the given context has helpers added to it.

# File lib/zyre/testing.rb, line 259
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

Public Instance Methods

check_fdmax()

Reset file descriptor limit higher for OSes that have low limits, e.g., OSX. Refs: - wiki.zeromq.org/docs:tuning-zeromq#toc1

# File lib/zyre/testing.rb, line 308
        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.

# File lib/zyre/testing.rb, line 281
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
                # $stderr.puts "Connecting to %p" % [ @gossip_endpoint ]
                node.gossip_connect( @gossip_endpoint )
        else
                @gossip_endpoint = gossip_hub()
                # $stderr.puts "Binding to %p" % [ @gossip_endpoint ]
                node.gossip_bind( @gossip_endpoint )
                sleep 0.25
        end

        # $stderr.puts "Starting %p" % [ node ]
        node.start
        @started_zyre_nodes << node

        return node
end