tests/socketlogger.rb in socketlogger-0.0.1 vs tests/socketlogger.rb in socketlogger-0.0.2
- old
+ new
@@ -1,17 +1,44 @@
require 'kintama'
+require_relative '../lib/socketlogger'
require 'pry'
-context "Logger module" do
+context 'Logger' do
setup do
- require_relative '../lib/socketlogger'
+ @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
- message = 'sike!'
- topic = 'logging'
- sent = Logger::log message
- characters_sent = message.length + topic.length + 1
+ 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
\ No newline at end of file