Sha256: 80b2f4b57813e07011467231922775a6955cbad1a3352e55f61f8e1ee773ba90
Contents?: true
Size: 1.8 KB
Versions: 4
Compression:
Stored size: 1.8 KB
Contents
require 'minitest_helper' require 'powertrack' require 'multi_json' class TestTrackStream < Minitest::Test def test_track_simple_stream stream = new_stream # add a logger stream.logger = Logger.new(STDERR) rule = PowerTrack::Rule.new('ny OR nyc OR #nyc OR new york') assert rule.valid? begin assert_nil stream.add_rule(rule) rules_after_addition = stream.list_rules assert rules_after_addition.is_a?(Array) assert rules_after_addition.size > 0 heartbeats = 0 received = 0 tweeted = 0 closed = false # ready to track on_message = lambda do |message| received += 1 end on_heartbeat = lambda do heartbeats += 1 end on_activity = lambda do |tweet| tweeted += 1 end close_now = lambda { closed } delay = 60 Thread.new do $stderr.puts "Time-bomb thread running for #{delay} seconds..." sleep delay $stderr.puts "Time to shut down !" closed = true end started_at = Time.now res = stream.track(on_message: on_message, on_heartbeat: on_heartbeat, on_activity: on_activity, close_now: close_now, max_retries: 3, fake_disconnections: 20) assert_nil res assert closed, 'Stream not closed' assert Time.now - started_at >= delay assert heartbeats > 0, 'No heartbeat received' puts "#{heartbeats} heartbeats received" assert received > 0, 'No message received so far' puts "#{received} messages received" assert tweeted > 0, 'No tweet received so far' puts "#{tweeted} tweets received" ensure assert_nil stream.delete_rules(rule) end end end
Version data entries
4 entries across 4 versions & 1 rubygems
Version | Path |
---|---|
powertrack-1.0.3 | test/test_track_stream.rb |
powertrack-1.0.2 | test/test_track_stream.rb |
powertrack-1.0.1 | test/test_track_stream.rb |
powertrack-1.0.0 | test/test_track_stream.rb |