Skip to content

Commit

Permalink
Tweak signature of testsuite.FlushTasks
Browse files Browse the repository at this point in the history
  • Loading branch information
rowanseymour committed Nov 18, 2024
1 parent 4737982 commit 0c6fd11
Show file tree
Hide file tree
Showing 12 changed files with 26 additions and 26 deletions.
2 changes: 1 addition & 1 deletion core/tasks/campaigns/fire_campaign_event_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func TestFireCampaignEvents(t *testing.T) {
err := tasks.Queue(rc, tasks.BatchQueue, testdata.Org1.ID, task, false)
assert.NoError(t, err)

testsuite.FlushTasks(t, rt, nil)
testsuite.FlushTasks(t, rt)

// and left in redis marker
for _, fid := range fireIDs {
Expand Down
8 changes: 4 additions & 4 deletions core/tasks/campaigns/schedule_campaign_event_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func TestScheduleCampaignEvent(t *testing.T) {

// schedule first event...
testsuite.QueueBatchTask(t, rt, testdata.Org1, &campaigns.ScheduleCampaignEventTask{CampaignEventID: testdata.RemindersEvent1.ID})
testsuite.FlushTasks(t, rt, nil)
testsuite.FlushTasks(t, rt)

// cathy has no value for joined and alexandia has a value too far in past, but bob and george will have values...
assertContactFires(t, rt.DB, testdata.RemindersEvent1.ID, map[models.ContactID]time.Time{
Expand All @@ -46,7 +46,7 @@ func TestScheduleCampaignEvent(t *testing.T) {

// schedule second event...
testsuite.QueueBatchTask(t, rt, testdata.Org1, &campaigns.ScheduleCampaignEventTask{CampaignEventID: testdata.RemindersEvent2.ID})
testsuite.FlushTasks(t, rt, nil)
testsuite.FlushTasks(t, rt)

assertContactFires(t, rt.DB, testdata.RemindersEvent2.ID, map[models.ContactID]time.Time{
testdata.Bob.ID: time.Date(2030, 1, 1, 0, 10, 0, 0, time.UTC),
Expand All @@ -69,7 +69,7 @@ func TestScheduleCampaignEvent(t *testing.T) {
event3 := testdata.InsertCampaignFlowEvent(rt, testdata.RemindersCampaign, testdata.Favorites, testdata.CreatedOnField, 5, "M")

testsuite.QueueBatchTask(t, rt, testdata.Org1, &campaigns.ScheduleCampaignEventTask{CampaignEventID: event3.ID})
testsuite.FlushTasks(t, rt, nil)
testsuite.FlushTasks(t, rt)

// only cathy is in the group and new enough to have a fire
assertContactFires(t, rt.DB, event3.ID, map[models.ContactID]time.Time{
Expand All @@ -83,7 +83,7 @@ func TestScheduleCampaignEvent(t *testing.T) {
rt.DB.MustExec(`UPDATE contacts_contact SET last_seen_on = '2040-01-01T00:00:00Z' WHERE id = $1`, testdata.Bob.ID)

testsuite.QueueBatchTask(t, rt, testdata.Org1, &campaigns.ScheduleCampaignEventTask{CampaignEventID: event4.ID})
testsuite.FlushTasks(t, rt, nil)
testsuite.FlushTasks(t, rt)

assertContactFires(t, rt.DB, event4.ID, map[models.ContactID]time.Time{
testdata.Bob.ID: time.Date(2040, 1, 2, 0, 0, 0, 0, time.UTC),
Expand Down
4 changes: 2 additions & 2 deletions core/tasks/contacts/import_contact_batch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,14 @@ func TestImportContactBatch(t *testing.T) {

// perform first batch task...
testsuite.QueueBatchTask(t, rt, testdata.Org1, &contacts.ImportContactBatchTask{ContactImportBatchID: batch1ID})
testsuite.FlushTasks(t, rt, nil)
testsuite.FlushTasks(t, rt)

// import is still in progress
assertdb.Query(t, rt.DB, `SELECT status FROM contacts_contactimport WHERE id = $1`, importID).Columns(map[string]any{"status": "O"})

// perform second batch task...
testsuite.QueueBatchTask(t, rt, testdata.Org1, &contacts.ImportContactBatchTask{ContactImportBatchID: batch2ID})
testsuite.FlushTasks(t, rt, nil)
testsuite.FlushTasks(t, rt)

assertdb.Query(t, rt.DB, `SELECT count(*) FROM contacts_contact WHERE id >= 30000`).Returns(3)
assertdb.Query(t, rt.DB, `SELECT count(*) FROM contacts_contact WHERE name = 'Norbert' AND language = 'eng'`).Returns(1)
Expand Down
2 changes: 1 addition & 1 deletion core/tasks/handler/handle_contact_event_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func TestHandleContactEvent(t *testing.T) {
NewContact: false,
})

tasksRan := testsuite.FlushTasks(t, rt, nil)
tasksRan := testsuite.FlushTasks(t, rt)
assert.Equal(t, map[string]int{"handle_contact_event": 2}, tasksRan)

assertdb.Query(t, rt.DB, `SELECT count(*) FROM contacts_contact WHERE id = $1 AND status = 'S'`, testdata.Cathy.ID).Returns(1)
Expand Down
4 changes: 2 additions & 2 deletions core/tasks/interrupts/interrupt_channel_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func TestInterruptChannel(t *testing.T) {

// queue and perform a task to interrupt the Twilio channel
tasks.Queue(rc, tasks.BatchQueue, testdata.Org1.ID, &interrupts.InterruptChannelTask{ChannelID: testdata.TwilioChannel.ID}, false)
testsuite.FlushTasks(t, rt, nil)
testsuite.FlushTasks(t, rt)

assertdb.Query(t, rt.DB, `SELECT count(*) FROM msgs_msg WHERE status = 'F' and channel_id = $1`, testdata.VonageChannel.ID).Returns(1)
assertdb.Query(t, rt.DB, `SELECT count(*) FROM msgs_msg WHERE status = 'F' and failed_reason = 'R' and channel_id = $1`, testdata.VonageChannel.ID).Returns(0)
Expand Down Expand Up @@ -83,7 +83,7 @@ func TestInterruptChannel(t *testing.T) {

// queue and perform a task to interrupt the Vonage channel
tasks.Queue(rc, tasks.BatchQueue, testdata.Org1.ID, &interrupts.InterruptChannelTask{ChannelID: testdata.VonageChannel.ID}, false)
testsuite.FlushTasks(t, rt, nil)
testsuite.FlushTasks(t, rt)

assertdb.Query(t, rt.DB, `SELECT count(*) FROM msgs_msg WHERE status = 'F' and failed_reason = 'R' and channel_id = $1`, testdata.VonageChannel.ID).Returns(6)
assertdb.Query(t, rt.DB, `SELECT count(*) FROM msgs_msg WHERE status = 'F' and channel_id = $1`, testdata.VonageChannel.ID).Returns(7)
Expand Down
2 changes: 1 addition & 1 deletion core/tasks/ivr/cron_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func TestRetryCallsCron(t *testing.T) {
service.callError = nil
service.callID = ivr.CallID("call1")

testsuite.FlushTasks(t, rt, nil)
testsuite.FlushTasks(t, rt)

assertdb.Query(t, rt.DB, `SELECT COUNT(*) FROM ivr_call WHERE contact_id = $1 AND status = $2 AND external_id = $3`,
testdata.Cathy.ID, models.CallStatusWired, "call1").Returns(1)
Expand Down
6 changes: 3 additions & 3 deletions core/tasks/ivr/start_ivr_flow_batch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func TestIVR(t *testing.T) {
err = tasks.Queue(rc, tasks.BatchQueue, testdata.Org1.ID, &starts.StartFlowTask{FlowStart: start}, false)
require.NoError(t, err)

testsuite.FlushTasks(t, rt, nil)
testsuite.FlushTasks(t, rt)

// should have one call in a failed state
assertdb.Query(t, rt.DB, `SELECT COUNT(*) FROM ivr_call WHERE contact_id = $1 AND status = $2`, testdata.Cathy.ID, models.CallStatusFailed).Returns(1)
Expand All @@ -55,7 +55,7 @@ func TestIVR(t *testing.T) {
err = tasks.Queue(rc, tasks.BatchQueue, testdata.Org1.ID, &starts.StartFlowTask{FlowStart: start}, false)
require.NoError(t, err)

testsuite.FlushTasks(t, rt, nil)
testsuite.FlushTasks(t, rt)

assertdb.Query(t, rt.DB, `SELECT COUNT(*) FROM ivr_call WHERE contact_id = $1 AND status = $2 AND external_id = $3`, testdata.Cathy.ID, models.CallStatusWired, "call1").Returns(1)

Expand All @@ -66,7 +66,7 @@ func TestIVR(t *testing.T) {
err = tasks.Queue(rc, tasks.BatchQueue, testdata.Org1.ID, &starts.StartFlowTask{FlowStart: start}, false)
require.NoError(t, err)

testsuite.FlushTasks(t, rt, nil)
testsuite.FlushTasks(t, rt)

assertdb.Query(t, rt.DB, `SELECT COUNT(*) FROM ivr_call WHERE contact_id = $1 AND status = $2 AND next_attempt IS NOT NULL;`, testdata.Cathy.ID, models.CallStatusQueued).Returns(1)
}
Expand Down
4 changes: 2 additions & 2 deletions core/tasks/msgs/send_broadcast_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ func TestBroadcastsFromEvents(t *testing.T) {
err = tasks.Queue(rc, tc.queue, testdata.Org1.ID, &msgs.SendBroadcastTask{Broadcast: bcast}, false)
assert.NoError(t, err)

taskCounts := testsuite.FlushTasks(t, rt, nil)
taskCounts := testsuite.FlushTasks(t, rt)

// assert our count of batches
assert.Equal(t, tc.expectedBatchCount, taskCounts["send_broadcast_batch"], "%d: unexpected batch count", i)
Expand Down Expand Up @@ -291,7 +291,7 @@ func TestSendBroadcastTask(t *testing.T) {
err = tasks.Queue(rc, tasks.BatchQueue, testdata.Org1.ID, task, false)
assert.NoError(t, err)

taskCounts := testsuite.FlushTasks(t, rt, nil)
taskCounts := testsuite.FlushTasks(t, rt)

// assert our count of batches
assert.Equal(t, tc.expectedBatches, taskCounts["send_broadcast_batch"], "%d: unexpected batch count", i)
Expand Down
10 changes: 5 additions & 5 deletions core/tasks/starts/start_flow_batch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func TestStartFlowBatchTask(t *testing.T) {
// start the first batch...
err = tasks.Queue(rc, tasks.ThrottledQueue, testdata.Org1.ID, &starts.StartFlowBatchTask{FlowStartBatch: batch1}, false)
assert.NoError(t, err)
testsuite.FlushTasks(t, rt, nil)
testsuite.FlushTasks(t, rt)

assertdb.Query(t, rt.DB, `SELECT count(*) FROM flows_flowsession WHERE contact_id = ANY($1)
AND status = 'C' AND responded = FALSE AND org_id = 1 AND call_id IS NULL AND output IS NOT NULL`, pq.Array([]models.ContactID{testdata.Cathy.ID, testdata.Bob.ID})).
Expand All @@ -55,7 +55,7 @@ func TestStartFlowBatchTask(t *testing.T) {
// start the second and final batch...
err = tasks.Queue(rc, tasks.ThrottledQueue, testdata.Org1.ID, &starts.StartFlowBatchTask{FlowStartBatch: batch2}, false)
assert.NoError(t, err)
testsuite.FlushTasks(t, rt, nil)
testsuite.FlushTasks(t, rt)

assertdb.Query(t, rt.DB, `SELECT count(*) FROM flows_flowrun WHERE start_id = $1`, start1.ID).Returns(4)
assertdb.Query(t, rt.DB, `SELECT status FROM flows_flowstart WHERE id = $1`, start1.ID).Returns("C")
Expand All @@ -72,7 +72,7 @@ func TestStartFlowBatchTask(t *testing.T) {
// start the first batch...
err = tasks.Queue(rc, tasks.ThrottledQueue, testdata.Org1.ID, &starts.StartFlowBatchTask{FlowStartBatch: start2Batch1}, false)
assert.NoError(t, err)
testsuite.FlushTasks(t, rt, nil)
testsuite.FlushTasks(t, rt)

assertdb.Query(t, rt.DB, `SELECT count(*) FROM flows_flowrun WHERE start_id = $1`, start2.ID).Returns(2)

Expand All @@ -82,7 +82,7 @@ func TestStartFlowBatchTask(t *testing.T) {
// start the second batch...
err = tasks.Queue(rc, tasks.ThrottledQueue, testdata.Org1.ID, &starts.StartFlowBatchTask{FlowStartBatch: start2Batch2}, false)
assert.NoError(t, err)
testsuite.FlushTasks(t, rt, nil)
testsuite.FlushTasks(t, rt)

// check that second batch didn't create any runs and start status is still interrupted
assertdb.Query(t, rt.DB, `SELECT count(*) FROM flows_flowrun WHERE start_id = $1`, start2.ID).Returns(2)
Expand All @@ -105,7 +105,7 @@ func TestStartFlowBatchTaskNonPersistedStart(t *testing.T) {
// start the first batch...
err := tasks.Queue(rc, tasks.ThrottledQueue, testdata.Org1.ID, &starts.StartFlowBatchTask{FlowStartBatch: batch}, false)
assert.NoError(t, err)
testsuite.FlushTasks(t, rt, nil)
testsuite.FlushTasks(t, rt)

assertdb.Query(t, rt.DB, `SELECT count(*) FROM flows_flowrun`).Returns(2)
}
4 changes: 2 additions & 2 deletions core/tasks/starts/start_flow_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ func TestStartFlowTask(t *testing.T) {
err = tasks.Queue(rc, tc.queue, testdata.Org1.ID, &starts.StartFlowTask{FlowStart: start}, false)
assert.NoError(t, err)

taskCounts := testsuite.FlushTasks(t, rt, nil)
taskCounts := testsuite.FlushTasks(t, rt)

// assert our count of batches
assert.Equal(t, tc.expectedBatchCount, taskCounts["start_flow_batch"], "%d: unexpected batch count", i)
Expand Down Expand Up @@ -268,7 +268,7 @@ func TestStartFlowTaskNonPersistedStart(t *testing.T) {

err := tasks.Queue(rc, tasks.ThrottledQueue, testdata.Org1.ID, &starts.StartFlowTask{FlowStart: start}, false)
assert.NoError(t, err)
testsuite.FlushTasks(t, rt, nil)
testsuite.FlushTasks(t, rt)

assertdb.Query(t, rt.DB, `SELECT count(*) FROM flows_flowrun`).Returns(2)
}
2 changes: 1 addition & 1 deletion testsuite/tasks.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ func CurrentTasks(t *testing.T, rt *runtime.Runtime, qname string) map[models.Or
return tasks
}

func FlushTasks(t *testing.T, rt *runtime.Runtime, qnames []string) map[string]int {
func FlushTasks(t *testing.T, rt *runtime.Runtime, qnames ...string) map[string]int {
rc := rt.RP.Get()
defer rc.Close()

Expand Down
4 changes: 2 additions & 2 deletions web/ivr/ivr_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ func TestTwilioIVR(t *testing.T) {
err = tasks.Queue(rc, tasks.BatchQueue, testdata.Org1.ID, &starts.StartFlowTask{FlowStart: start}, false)
require.NoError(t, err)

testsuite.FlushTasks(t, rt, nil)
testsuite.FlushTasks(t, rt)

// check our 3 contacts have 3 wired calls
assertdb.Query(t, rt.DB, `SELECT COUNT(*) FROM ivr_call WHERE contact_id = $1 AND status = $2 AND external_id = $3`,
Expand Down Expand Up @@ -413,7 +413,7 @@ func TestVonageIVR(t *testing.T) {
err = tasks.Queue(rc, tasks.BatchQueue, testdata.Org1.ID, &starts.StartFlowTask{FlowStart: start}, false)
require.NoError(t, err)

testsuite.FlushTasks(t, rt, nil)
testsuite.FlushTasks(t, rt)

assertdb.Query(t, rt.DB, `SELECT COUNT(*) FROM ivr_call WHERE contact_id = $1 AND status = $2 AND external_id = $3`,
testdata.Cathy.ID, models.CallStatusWired, "Call1").Returns(1)
Expand Down

0 comments on commit 0c6fd11

Please sign in to comment.