go.charczuk.com@v0.0.0-20240327042549-bc490516bd1a/sdk/cron/job_manager_test.go (about) 1 /* 2 3 Copyright (c) 2023 - Present. Will Charczuk. All rights reserved. 4 Use of this source code is governed by a MIT license that can be found in the LICENSE file at the root of the repository. 5 6 */ 7 8 package cron 9 10 import ( 11 "context" 12 "testing" 13 14 "go.charczuk.com/sdk/assert" 15 ) 16 17 func Test_JobManager_New(t *testing.T) { 18 jm := New() 19 assert.ItsNotNil(t, jm.latch) 20 assert.ItsNotNil(t, jm.jobs) 21 } 22 23 func Test_JobManager_Start(t *testing.T) { 24 jm := New() 25 defer jm.Stop(context.Background()) 26 27 // start blocks, use a channel and goroutine 28 errors := make(chan error, 1) 29 go func() { 30 if err := jm.Start(context.Background()); err != nil { 31 errors <- err 32 } 33 }() 34 <-jm.latch.NotifyStarted() 35 assert.ItsEqual(t, 0, len(errors)) 36 err := jm.Start(context.Background()) 37 assert.ItsNotNil(t, err) 38 } 39 40 func Test_JobManager_E2E(t *testing.T) { 41 jm := New() 42 jm.Register(context.TODO(), NewJob( 43 OptJobSchedule(Never()), 44 )) 45 }