diff options
author | George Goldberg <george@gberg.me> | 2017-09-28 17:11:13 +0100 |
---|---|---|
committer | Corey Hulen <corey@hulen.com> | 2017-09-28 09:11:13 -0700 |
commit | a06830b2f88a8d374c326a1191870cbc7cf7dac2 (patch) | |
tree | 4879ce49de061fba894fe01b54db701c639f0e94 /store/sqlstore/job_store_test.go | |
parent | f263d2b9510fb557fe075dee5097cb32e2b1e5e2 (diff) | |
download | chat-a06830b2f88a8d374c326a1191870cbc7cf7dac2.tar.gz chat-a06830b2f88a8d374c326a1191870cbc7cf7dac2.tar.bz2 chat-a06830b2f88a8d374c326a1191870cbc7cf7dac2.zip |
PLT-7644: Improve job scheduler architecture. (#7532)
Diffstat (limited to 'store/sqlstore/job_store_test.go')
-rw-r--r-- | store/sqlstore/job_store_test.go | 103 |
1 files changed, 103 insertions, 0 deletions
diff --git a/store/sqlstore/job_store_test.go b/store/sqlstore/job_store_test.go index bbeca6c3a..148d8b92d 100644 --- a/store/sqlstore/job_store_test.go +++ b/store/sqlstore/job_store_test.go @@ -10,6 +10,7 @@ import ( "github.com/mattermost/mattermost-server/model" "github.com/mattermost/mattermost-server/store" + "github.com/stretchr/testify/assert" ) func TestJobSaveGet(t *testing.T) { @@ -231,6 +232,108 @@ func TestJobGetAllByStatus(t *testing.T) { } } +func TestJobStoreGetNewestJobByStatusAndType(t *testing.T) { + ss := Setup() + + jobType1 := model.NewId() + jobType2 := model.NewId() + status1 := model.NewId() + status2 := model.NewId() + + jobs := []*model.Job{ + { + Id: model.NewId(), + Type: jobType1, + CreateAt: 1001, + Status: status1, + }, + { + Id: model.NewId(), + Type: jobType1, + CreateAt: 1000, + Status: status1, + }, + { + Id: model.NewId(), + Type: jobType2, + CreateAt: 1003, + Status: status1, + }, + { + Id: model.NewId(), + Type: jobType1, + CreateAt: 1004, + Status: status2, + }, + } + + for _, job := range jobs { + store.Must(ss.Job().Save(job)) + defer ss.Job().Delete(job.Id) + } + + result := <-ss.Job().GetNewestJobByStatusAndType(status1, jobType1) + assert.Nil(t, result.Err) + assert.EqualValues(t, jobs[0].Id, result.Data.(*model.Job).Id) +} + +func TestJobStoreGetCountByStatusAndType(t *testing.T) { + ss := Setup() + + jobType1 := model.NewId() + jobType2 := model.NewId() + status1 := model.NewId() + status2 := model.NewId() + + jobs := []*model.Job{ + { + Id: model.NewId(), + Type: jobType1, + CreateAt: 1000, + Status: status1, + }, + { + Id: model.NewId(), + Type: jobType1, + CreateAt: 999, + Status: status1, + }, + { + Id: model.NewId(), + Type: jobType2, + CreateAt: 1001, + Status: status1, + }, + { + Id: model.NewId(), + Type: jobType1, + CreateAt: 1002, + Status: status2, + }, + } + + for _, job := range jobs { + store.Must(ss.Job().Save(job)) + defer ss.Job().Delete(job.Id) + } + + result := <-ss.Job().GetCountByStatusAndType(status1, jobType1) + assert.Nil(t, result.Err) + assert.EqualValues(t, 2, result.Data.(int64)) + + result = <-ss.Job().GetCountByStatusAndType(status2, jobType2) + assert.Nil(t, result.Err) + assert.EqualValues(t, 0, result.Data.(int64)) + + result = <-ss.Job().GetCountByStatusAndType(status1, jobType2) + assert.Nil(t, result.Err) + assert.EqualValues(t, 1, result.Data.(int64)) + + result = <-ss.Job().GetCountByStatusAndType(status2, jobType1) + assert.Nil(t, result.Err) + assert.EqualValues(t, 1, result.Data.(int64)) +} + func TestJobUpdateOptimistically(t *testing.T) { ss := Setup() |