VRFS-2282 tests and music session time queries

This commit is contained in:
Jonathan Kolyer 2014-10-14 03:54:58 +00:00
parent 6f27455b02
commit 649027cda7
3 changed files with 56 additions and 73 deletions

View File

@ -14,7 +14,7 @@ module JamRuby
UNSTARTED_INTERVAL_DAYS_SKIP = '14' # days past scheduled start to skip in query
UNSTARTED_INTERVAL_DAYS_PURGE = '28' # days past scheduled start to purge session
UNSTARTED_INTERVAL_DAYS_PURGE_RECUR = '56' # days past scheduled start to purge recurddingsession
UNSTARTED_INTERVAL_DAYS_PURGE_RECUR = '28' # days past scheduled start to purge recurddingsession
attr_accessor :legal_terms, :language_description, :access_description, :scheduling_info_changed
@ -737,7 +737,12 @@ module JamRuby
@@log.warn("unable to parse day=#{day}, timezone_offset=#{timezone_offset}, e=#{e}")
end
else
query = query.where("music_sessions.scheduled_start IS NULL OR (music_sessions.scheduled_start > NOW() - interval '#{UNSTARTED_INTERVAL_DAYS_SKIP} days')")
sql =<<SQL
music_sessions.started_at IS NULL AND
(music_sessions.created_at > NOW() - interval '#{UNSTARTED_INTERVAL_DAYS_SKIP} days' OR
music_sessions.scheduled_start > NOW() - interval '#{UNSTARTED_INTERVAL_DAYS_SKIP} days')
SQL
query = query.where(sql)
end
return query
end
@ -928,11 +933,15 @@ module JamRuby
def self.purgeable_sessions
sessions = []
sql =<<SQL
(recurring_mode = '#{RECURRING_WEEKLY}' AND
scheduled_start <= NOW() - interval '#{UNSTARTED_INTERVAL_DAYS_PURGE_RECUR} days')
(started_at IS NULL AND
(created_at <= NOW() - interval '#{UNSTARTED_INTERVAL_DAYS_PURGE} days' OR
scheduled_start <= NOW() - interval '#{UNSTARTED_INTERVAL_DAYS_PURGE} days'))
OR
(recurring_mode = '#{NO_RECURRING}' AND
scheduled_start <= NOW() - interval '#{UNSTARTED_INTERVAL_DAYS_PURGE} days')
OR
(recurring_mode = '#{RECURRING_WEEKLY}' AND
scheduled_start <= NOW() - interval '#{UNSTARTED_INTERVAL_DAYS_PURGE_RECUR} days')
SQL
self.where("started_at IS NULL").where(sql).find_each do |ms|
block_given? ? yield(ms) : sessions << ms

View File

@ -484,17 +484,6 @@ describe MusicSession do
end
it "skip session with past due scheduled_start time" do
creator.last_jam_locidispid = conn.locidispid
creator.save!
music_session = FactoryGirl.create(:music_session,
creator: creator,
scheduled_start: Time.now - (MusicSession::UNSTARTED_INTERVAL_DAYS_SKIP.to_i + 1).days)
msess = FactoryGirl.create(:music_session, scheduled_start: Time.now - 1.day)
music_sessions, user_scores = sms(searcher, default_opts)
expect(music_sessions.length).to be(1)
end
it "one session, one RSVP (creator)" do
creator.last_jam_locidispid = conn.locidispid
creator.save!
@ -508,6 +497,18 @@ describe MusicSession do
user_scores[creator.id][:full_score].should == (network_score + searcher.last_jam_audio_latency + creator.last_jam_audio_latency )
end
it "skip session with past due scheduled_start time" do
interval = MusicSession::UNSTARTED_INTERVAL_DAYS_SKIP
dd = Time.now - (interval.to_i + 1).days
Timecop.travel(dd)
msess1 = FactoryGirl.create(:music_session, creator: creator, scheduled_start: dd)
Timecop.return
msess2 = FactoryGirl.create(:music_session, creator: creator)
music_sessions, user_scores = sms(searcher, default_opts)
expect(music_sessions.length).to be(1)
expect(music_sessions[0].id).to eq(msess2.id)
end
it "filters sessions in the past" do
music_session = FactoryGirl.create(:music_session, creator: creator)
@ -882,16 +883,30 @@ describe MusicSession do
end
describe "purgeable sessions " do
it 'selects unscheduled sessions past due date' do
interval = MusicSession::UNSTARTED_INTERVAL_DAYS_PURGE
dd = Time.now - (interval.to_i + 1).days
Timecop.travel(dd)
msess1 = FactoryGirl.create(:music_session)
Timecop.return
msess2 = FactoryGirl.create(:music_session)
purging = MusicSession.purgeable_sessions
expect(purging.size).to be(1)
expect(purging[0].id).to eq(msess1.id)
end
it 'selects recurring and non-recurring sessions past due date' do
[MusicSession::UNSTARTED_INTERVAL_DAYS_PURGE,
MusicSession::UNSTARTED_INTERVAL_DAYS_PURGE_RECUR].each do |interval|
dd = Time.now - (interval.to_i + 1).days
Timecop.travel(dd)
msess = FactoryGirl.create(:music_session, scheduled_start: Time.now)
msess1 = FactoryGirl.create(:music_session, scheduled_start: Time.now)
Timecop.return
msess = FactoryGirl.create(:music_session, scheduled_start: Time.now)
msess2 = FactoryGirl.create(:music_session, scheduled_start: Time.now)
purging = MusicSession.purgeable_sessions
expect(purging.size).to be(1)
expect(purging[0].id).to eq(msess1.id)
MusicSession.delete_all
end
end

View File

@ -1,62 +1,21 @@
require 'spec_helper'
describe ScheduledMusicSessionCleaner do
describe 'ScheduledMusicSessionCleaner' do
let(:check) { ScheduledMusicSessionCleaner.new }
it "purges old music sessions" do
[MusicSession::UNSTARTED_INTERVAL_DAYS_PURGE,
MusicSession::UNSTARTED_INTERVAL_DAYS_PURGE_RECUR].each do |interval|
dd = Time.now - (interval.to_i + 1).days
Timecop.travel(dd)
FactoryGirl.create(:music_session, scheduled_start: dd)
Timecop.return
end
msess2 = FactoryGirl.create(:music_session, scheduled_start: Time.now)
expect(MusicSession.count).to be(3)
describe "integration" do
it "find no music notataions if music_session_id is nil and created at 1 hour ago" do
notation = MusicNotation.new
notation.file_url = File.open(NOTATION_TEMP_FILE)
notation.size = 10
notation.user = FactoryGirl.create(:user)
notation.created_at = Time.now - 1.hours
notation.save!
check.should_not_receive(:handle_notifications)
check.run
end
it "find no music notataion if music_session_id is not nil and session_removed_at is in 1 hour" do
music_session = FactoryGirl.create(:music_session, :session_removed_at => Time.now - 1.hours)
notation = MusicNotation.new
notation.file_url = File.open(NOTATION_TEMP_FILE)
notation.size = 10
notation.user = FactoryGirl.create(:user)
notation.created_at = Time.now - 1.hours
notation.music_session = music_session
notation.save!
check.run
end
it "find music notataions if music_session_id is nil and created at 2 days ago" do
notation = MusicNotation.new
notation.file_url = File.open(NOTATION_TEMP_FILE)
notation.size = 10
notation.user = FactoryGirl.create(:user)
notation.created_at = Time.now - 2.days
notation.save!
check.should_receive(:handle_notifications)
check.run
end
it "find music notataion if music_session_id is not nil and session_removed_at 2 days ago" do
music_session = FactoryGirl.create(:music_session, :session_removed_at => Time.now - 2.days)
notation = MusicNotation.new
notation.file_url = File.open(NOTATION_TEMP_FILE)
notation.size = 10
notation.user = FactoryGirl.create(:user)
notation.created_at = Time.now - 3.days
notation.music_session = music_session
notation.save!
check.should_receive(:handle_notifications)
check.run
end
JamRuby::ScheduledMusicSessionCleaner.perform
expect(MusicSession.count).to be(1)
expect(MusicSession.first.id).to eq(msess2.id)
end
end