require 'kintama' require_relative '../lib/socketlogger' require 'pry' context 'Logger' do setup do @topic = 'logging' @publisher = Logger.new 4000, :tcp, @topic @message = 'sike!' end it 'should publish to a socket and return a number equal to length of message + length of topic + 1' do sent = @publisher.log @message characters_sent = @message.length + @topic.length + 1 assert_equal characters_sent, sent end end context 'Receiver' do setup do @publisher = Logger.new 4000, :tcp, 'worker' @subscriber = EZMQ::Subscriber.new :bind, port: 4000, topic: 'worker' @message = 'sike!' Thread.new do loop do @publisher.log @message end end end it 'should receive messages' do messages = [] topics = [] 1000.times do message, topic = @subscriber.receive messages << message topics << topic end assert_equal 1000, messages.size end end