summaryrefslogtreecommitdiffstats
path: root/model/job_test.go
diff options
context:
space:
mode:
authorHarrison Healey <harrisonmhealey@gmail.com>2017-05-18 15:05:57 -0400
committerGitHub <noreply@github.com>2017-05-18 15:05:57 -0400
commit577ed27f1bb060080d311342047e31943a02ccbb (patch)
treead57fa69b1daf143e914ea2480a475e5450cc236 /model/job_test.go
parent920bc0d8712a50691b1f698779f60132536eb214 (diff)
downloadchat-577ed27f1bb060080d311342047e31943a02ccbb.tar.gz
chat-577ed27f1bb060080d311342047e31943a02ccbb.tar.bz2
chat-577ed27f1bb060080d311342047e31943a02ccbb.zip
PLT-6408 Framework for job server (#6404)
* Added initial job server * Added job server to be ran as part of platform * Added test job to the enterprise repo * Fixed job server not loading license * Renamed job package to jobs * Fixed TE not being buildable * Added JobStatus table to database * Changed fields used by JobStatus * Added APIs to query job status * Added config change listener to server * Added option to run job server from Makefile * Added ability to enable/disable jobs from config * Commented out placeholder for search indexing job * Fixed govet * Removed debug messages and fixed job api init message
Diffstat (limited to 'model/job_test.go')
-rw-r--r--model/job_test.go188
1 files changed, 0 insertions, 188 deletions
diff --git a/model/job_test.go b/model/job_test.go
deleted file mode 100644
index 6ba8edaf9..000000000
--- a/model/job_test.go
+++ /dev/null
@@ -1,188 +0,0 @@
-// Copyright (c) 2016-present Mattermost, Inc. All Rights Reserved.
-// See License.txt for license information.
-
-package model
-
-import (
- "testing"
- "time"
-)
-
-func TestCreateTask(t *testing.T) {
- TASK_NAME := "Test Task"
- TASK_TIME := time.Second * 3
-
- testValue := 0
- testFunc := func() {
- testValue = 1
- }
-
- task := CreateTask(TASK_NAME, testFunc, TASK_TIME)
- if testValue != 0 {
- t.Fatal("Unexpected execuition of task")
- }
-
- time.Sleep(TASK_TIME + time.Second)
-
- if testValue != 1 {
- t.Fatal("Task did not execute")
- }
-
- if task.Name != TASK_NAME {
- t.Fatal("Bad name")
- }
-
- if task.Interval != TASK_TIME {
- t.Fatal("Bad interval")
- }
-
- if task.Recurring != false {
- t.Fatal("should not reccur")
- }
-}
-
-func TestCreateRecurringTask(t *testing.T) {
- TASK_NAME := "Test Recurring Task"
- TASK_TIME := time.Second * 3
-
- testValue := 0
- testFunc := func() {
- testValue += 1
- }
-
- task := CreateRecurringTask(TASK_NAME, testFunc, TASK_TIME)
- if testValue != 0 {
- t.Fatal("Unexpected execuition of task")
- }
-
- time.Sleep(TASK_TIME + time.Second)
-
- if testValue != 1 {
- t.Fatal("Task did not execute")
- }
-
- time.Sleep(TASK_TIME)
-
- if testValue != 2 {
- t.Fatal("Task did not re-execute")
- }
-
- if task.Name != TASK_NAME {
- t.Fatal("Bad name")
- }
-
- if task.Interval != TASK_TIME {
- t.Fatal("Bad interval")
- }
-
- if task.Recurring != true {
- t.Fatal("should reccur")
- }
-
- task.Cancel()
-}
-
-func TestCancelTask(t *testing.T) {
- TASK_NAME := "Test Task"
- TASK_TIME := time.Second * 3
-
- testValue := 0
- testFunc := func() {
- testValue = 1
- }
-
- task := CreateTask(TASK_NAME, testFunc, TASK_TIME)
- if testValue != 0 {
- t.Fatal("Unexpected execuition of task")
- }
- task.Cancel()
-
- time.Sleep(TASK_TIME + time.Second)
-
- if testValue != 0 {
- t.Fatal("Unexpected execuition of task")
- }
-}
-
-func TestGetAllTasks(t *testing.T) {
- doNothing := func() {}
-
- CreateTask("Task1", doNothing, time.Hour)
- CreateTask("Task2", doNothing, time.Second)
- CreateRecurringTask("Task3", doNothing, time.Second)
- task4 := CreateRecurringTask("Task4", doNothing, time.Second)
-
- task4.Cancel()
-
- time.Sleep(time.Second * 3)
-
- tasks := *GetAllTasks()
- if len(tasks) != 2 {
- t.Fatal("Wrong number of tasks got: ", len(tasks))
- }
- for _, task := range tasks {
- if task.Name != "Task1" && task.Name != "Task3" {
- t.Fatal("Wrong tasks")
- }
- }
-}
-
-func TestExecuteTask(t *testing.T) {
- TASK_NAME := "Test Task"
- TASK_TIME := time.Second * 5
-
- testValue := 0
- testFunc := func() {
- testValue += 1
- }
-
- task := CreateTask(TASK_NAME, testFunc, TASK_TIME)
- if testValue != 0 {
- t.Fatal("Unexpected execuition of task")
- }
-
- task.Execute()
-
- if testValue != 1 {
- t.Fatal("Task did not execute")
- }
-
- time.Sleep(TASK_TIME + time.Second)
-
- if testValue != 2 {
- t.Fatal("Task re-executed")
- }
-}
-
-func TestExecuteTaskRecurring(t *testing.T) {
- TASK_NAME := "Test Recurring Task"
- TASK_TIME := time.Second * 5
-
- testValue := 0
- testFunc := func() {
- testValue += 1
- }
-
- task := CreateRecurringTask(TASK_NAME, testFunc, TASK_TIME)
- if testValue != 0 {
- t.Fatal("Unexpected execuition of task")
- }
-
- time.Sleep(time.Second * 3)
-
- task.Execute()
- if testValue != 1 {
- t.Fatal("Task did not execute")
- }
-
- time.Sleep(time.Second * 3)
- if testValue != 1 {
- t.Fatal("Task should not have executed before 5 seconds")
- }
-
- time.Sleep(time.Second * 3)
-
- if testValue != 2 {
- t.Fatal("Task did not re-execute after forced execution")
- }
-}