VRFS-925 finishing up tests

This commit is contained in:
Jonathan Kolyer 2014-04-14 10:57:21 +00:00
parent 5a4bff14d2
commit 9ddbc6ba5c
2 changed files with 36 additions and 28 deletions

View File

@ -16,15 +16,17 @@ module JamRuby
@@log = Logging.logger[GoogleAnalyticsEvent]
SESSION_INTERVALS = [1, 5, 10, 15, 30, 45, 60, 90, 120, 180] # minutes
QUEUE_BAND_TRACKER = :band_tracker
QUEUE_SESSION_TRACKER = :session_tracker
class SessionDurationTracker
@queue = QUEUE_SESSION_TRACKER
def self.perform(session_id, interval_idx)
return unless session = MusicSession.find(session_id)
def self.perform(args={})
session_id, interval_idx = args['session_id'], args['interval_idx'].to_i
return unless session_id && session = MusicSession.find(session_id)
GoogleAnalyticsEvent.enqueue(CAT_SESS_DUR, ACTION_SESS_DUR, SESSION_INTERVALS[interval_idx])
interval_idx += 1
GoogleAnalyticsEvent.enqueue(CAT_SESS_DUR, ACTION_SESS_DUR, interval_idx)
if SESSION_INTERVALS.count-1 > interval_idx
next_time = session.created_at + SESSION_INTERVALS[interval_idx].minutes
@ -41,13 +43,13 @@ module JamRuby
end
class BandSessionTracker
@queue = QUEUE_SESSION_TRACKER
@queue = QUEUE_BAND_TRACKER
def self.perform(session_id)
return unless session = MusicSession.find(session_id)
band = session.band
if band.in_real_session?(session)
band.update_attributes!(did_real_session: true)
band.update_attribute(:did_real_session, true)
GoogleAnalyticsEvent.enqueue(CAT_BAND, ACTION_BAND_SESS, nil)
end if band
end
@ -57,9 +59,9 @@ module JamRuby
def self.track_band_real_session(session)
if session.band && !session.band.did_real_session?
Resque.enqueue_in(BAND_SESSION_MIN_DURATION.minutes,
Resque.enqueue_at(BAND_SESSION_MIN_DURATION.minutes.from_now,
BandSessionTracker,
:session_id => session.id)
session.id)
end
end

View File

@ -5,11 +5,8 @@ describe GoogleAnalyticsEvent do
let(:ga) { GoogleAnalyticsEvent.new }
describe "track band analytics" do
before :each do
ResqueSpec.reset!
end
it 'reports first recording' do
pending
ResqueSpec.reset!
user = FactoryGirl.create(:user)
band = FactoryGirl.create(:band)
music_session = FactoryGirl.create(:music_session,
@ -25,7 +22,6 @@ describe GoogleAnalyticsEvent do
end
it 'reports first real session' do
pending
ResqueSpec.reset!
JamRuby::GoogleAnalyticsEvent::BandSessionTracker.should have_schedule_size_of(0)
user = FactoryGirl.create(:user)
@ -46,16 +42,21 @@ describe GoogleAnalyticsEvent do
:music_session => music_session)
music_session.reload
expect(music_session.connected_participant_count).to eq(2)
expect(band.did_real_session).to eq(false)
JamRuby::GoogleAnalyticsEvent::BandSessionTracker.should have_schedule_size_of_at_least(1)
JamRuby::GoogleAnalyticsEvent.should have_queue_size_of(0)
Timecop.travel((GoogleAnalyticsEvent::BAND_SESSION_MIN_DURATION + 1).minutes.from_now)
band.reload; music_session.reload
expect(band.in_real_session?(music_session)).to eq(true)
JamRuby::GoogleAnalyticsEvent.should have_queue_size_of_at_least(1)
# JamRuby::GoogleAnalyticsEvent.should have_queued(GoogleAnalyticsEvent::CAT_BAND, GoogleAnalyticsEvent::ACTION_BAND_SESS, nil)
ResqueSpec.queues["#{GoogleAnalyticsEvent::QUEUE_BAND_TRACKER}_scheduled"].select do |qq|
qq[:class] == GoogleAnalyticsEvent::BandSessionTracker.name
end.count.should eq(1)
# GoogleAnalyticsEvent::BandSessionTracker.should have_schedule_size_of_at_least(1)
GoogleAnalyticsEvent.should_not have_queued(GoogleAnalyticsEvent::CAT_BAND, GoogleAnalyticsEvent::ACTION_BAND_SESS, nil)
Timecop.freeze((GoogleAnalyticsEvent::BAND_SESSION_MIN_DURATION + 1).minutes.from_now)
qname = "#{ResqueSpec.queue_name(JamRuby::GoogleAnalyticsEvent::BandSessionTracker)}_scheduled"
expect(ResqueSpec.peek(qname).present?).to eq(true)
ResqueSpec.perform_next(qname)
GoogleAnalyticsEvent.should have_queued(GoogleAnalyticsEvent::CAT_BAND,
GoogleAnalyticsEvent::ACTION_BAND_SESS,
nil)
band.reload
expect(band.did_real_session).to eq(true)
end
@ -67,7 +68,6 @@ describe GoogleAnalyticsEvent do
ResqueSpec.reset!
end
it 'reports size increment' do
pending
user = FactoryGirl.create(:user)
music_session = FactoryGirl.create(:music_session,
:creator => user,
@ -82,17 +82,23 @@ describe GoogleAnalyticsEvent do
end
it 'reports duration' do
# pending
user = FactoryGirl.create(:user)
JamRuby::GoogleAnalyticsEvent::SessionDurationTracker.should have_schedule_size_of_at_least(0)
JamRuby::GoogleAnalyticsEvent::SessionDurationTracker.should have_schedule_size_of(0)
music_session = FactoryGirl.create(:music_session,
:creator => user,
:musician_access => true)
JamRuby::GoogleAnalyticsEvent::SessionDurationTracker.should have_schedule_size_of_at_least(1)
# Timecop.travel((GoogleAnalyticsEvent::BAND_SESSION_MIN_DURATION + 1).minutes.from_now)
# GoogleAnalyticsEvent.should have_queued(GoogleAnalyticsEvent::CAT_SESS_SIZE,
# GoogleAnalyticsEvent::ACTION_SESS_SIZE,
# music_session.connected_participant_count)
GoogleAnalyticsEvent::SessionDurationTracker.should have_schedule_size_of(1)
GoogleAnalyticsEvent::SESSION_INTERVALS.each do |interval|
Timecop.travel((interval + 1).minutes.from_now)
qname = "#{ResqueSpec.queue_name(JamRuby::GoogleAnalyticsEvent::SessionDurationTracker)}_scheduled"
next unless ResqueSpec.peek(qname).present?
ResqueSpec.perform_next(qname)
GoogleAnalyticsEvent.should have_queued(GoogleAnalyticsEvent::CAT_SESS_DUR,
GoogleAnalyticsEvent::ACTION_SESS_DUR,
interval)
end
GoogleAnalyticsEvent.should have_queue_size_of(GoogleAnalyticsEvent::SESSION_INTERVALS.count - 1)
end
end