diff options
Diffstat (limited to 'model/job_test.go')
-rw-r--r-- | model/job_test.go | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/model/job_test.go b/model/job_test.go index 2a307de1e..8908fed58 100644 --- a/model/job_test.go +++ b/model/job_test.go @@ -126,3 +126,63 @@ func TestGetAllTasks(t *testing.T) { } } } + +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") + } +} |