Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
gitpod-io
GitHub Repository: gitpod-io/gitpod
Path: blob/main/components/usage/pkg/scheduler/scheduler_test.go
2498 views
1
// Copyright (c) 2022 Gitpod GmbH. All rights reserved.
2
// Licensed under the GNU Affero General Public License (AGPL).
3
// See License.AGPL.txt in the project root for license information.
4
5
package scheduler
6
7
import (
8
"testing"
9
"time"
10
11
"github.com/alicebob/miniredis/v2"
12
"github.com/go-redis/redis"
13
"github.com/go-redsync/redsync/v4"
14
"github.com/go-redsync/redsync/v4/redis/goredis"
15
"github.com/robfig/cron"
16
"github.com/stretchr/testify/require"
17
)
18
19
func TestScheduler_StopsAll(t *testing.T) {
20
red := miniredis.RunT(t)
21
client := redis.NewClient(&redis.Options{Addr: red.Addr()})
22
23
pool := goredis.NewPool(client)
24
rs := redsync.New(pool)
25
26
firstRan := false
27
secondRan := false
28
s := New(
29
rs,
30
JobSpec{
31
Job: JobFunc(func() error {
32
firstRan = true
33
return nil
34
}),
35
ID: "first",
36
Schedule: cron.ConstantDelaySchedule{Delay: time.Second},
37
InitialLockDuration: time.Second,
38
},
39
JobSpec{
40
Job: JobFunc(func() error {
41
secondRan = true
42
return nil
43
}),
44
ID: "second",
45
Schedule: cron.ConstantDelaySchedule{Delay: time.Second},
46
InitialLockDuration: time.Second,
47
},
48
)
49
s.Start()
50
time.Sleep(1 * time.Second)
51
s.Stop()
52
53
require.True(t, firstRan)
54
require.True(t, secondRan)
55
}
56
57