diff --git a/archives/archives_test.go b/archives/archives_test.go index daf91b0..b4d8cc7 100644 --- a/archives/archives_test.go +++ b/archives/archives_test.go @@ -517,7 +517,7 @@ func TestArchiveOrgRuns(t *testing.T) { time.Date(2020, 2, 1, 0, 0, 0, 0, time.UTC), ) assert.NoError(t, err) - assert.Equal(t, 2, count) + assert.Equal(t, 3, count) // more recent run unaffected (even though it was parent) count, err = getCountInRange( @@ -529,5 +529,21 @@ func TestArchiveOrgRuns(t *testing.T) { ) assert.NoError(t, err) assert.Equal(t, 1, count) + + // org 2 has a run that can't be archived because it's still active - as it has no existing archives + // this will manifest itself as a monthly which fails to save + created, deleted, err = ArchiveOrg(ctx, now, config, db, s3Client, orgs[1], RunType) + assert.NoError(t, err) + + assert.Equal(t, 34, len(created)) + assert.Equal(t, time.Date(2017, 8, 1, 0, 0, 0, 0, time.UTC), created[0].StartDate) + assert.Equal(t, MonthPeriod, created[0].Period) + assert.Equal(t, "", created[0].ArchiveFile) // failed to create + assert.Equal(t, time.Date(2017, 9, 1, 0, 0, 0, 0, time.UTC), created[1].StartDate) + assert.Equal(t, MonthPeriod, created[1].Period) + assert.NotEqual(t, "", created[1].ArchiveFile) + + assert.Equal(t, DayPeriod, created[2].Period) + assert.Equal(t, DayPeriod, created[33].Period) } } diff --git a/testdb.sql b/testdb.sql index 2352045..4bacc63 100644 --- a/testdb.sql +++ b/testdb.sql @@ -311,7 +311,8 @@ INSERT INTO flows_flowrun(id, uuid, responded, contact_id, flow_id, org_id, resu '[{"uuid": "babf4fc8-e12c-4bb9-a9dd-61178a118b5a", "node_uuid": "accbc6e2-b0df-46cd-9a76-bff0fdf4d753", "arrived_on": "2017-10-12T15:07:24.049815+02:00", "exit_uuid": "8249e2dc-c893-4200-b6d2-398d07a459bc"}]', '2017-10-10 21:11:59.890662+02:00','2017-10-10 21:11:59.890662+02:00','2017-10-10 21:11:59.890662+02:00', 'C', NULL), (5, 'abed67d2-06b8-4749-8bb9-ecda037b673b', TRUE, 7, 2, 3, '{}', '[]', '2017-10-10 21:11:59.890663+02:00','2017-10-10 21:11:59.890662+02:00','2017-10-10 21:11:59.890662+02:00', 'C', NULL), -(6, '6262eefe-a6e9-4201-9b76-a7f25e3b7f29', TRUE, 7, 2, 3, '{}', '[]', '2017-12-12 21:11:59.890662+02:00','2017-12-12 21:11:59.890662+02:00','2017-12-12 21:11:59.890662+02:00', 'C', NULL); +(6, '6262eefe-a6e9-4201-9b76-a7f25e3b7f29', TRUE, 7, 2, 3, '{}', '[]', '2017-12-12 21:11:59.890662+02:00','2017-12-12 21:11:59.890662+02:00','2017-12-12 21:11:59.890662+02:00', 'C', NULL), +(7, '6c0d7db9-076b-4edc-ab4b-38576ae394fc', TRUE, 7, 2, 2, '{}', '[]', '2017-08-13 13:11:59.890662+02:00','2017-08-14 16:11:59.890662+02:00', NULL, 'W', NULL); -- update run #5 to have a path longer than 500 steps UPDATE flows_flowrun SET path = s.path FROM (