Path: blob/main/components/usage/pkg/scheduler/scheduler_test.go
2498 views
// Copyright (c) 2022 Gitpod GmbH. All rights reserved.1// Licensed under the GNU Affero General Public License (AGPL).2// See License.AGPL.txt in the project root for license information.34package scheduler56import (7"testing"8"time"910"github.com/alicebob/miniredis/v2"11"github.com/go-redis/redis"12"github.com/go-redsync/redsync/v4"13"github.com/go-redsync/redsync/v4/redis/goredis"14"github.com/robfig/cron"15"github.com/stretchr/testify/require"16)1718func TestScheduler_StopsAll(t *testing.T) {19red := miniredis.RunT(t)20client := redis.NewClient(&redis.Options{Addr: red.Addr()})2122pool := goredis.NewPool(client)23rs := redsync.New(pool)2425firstRan := false26secondRan := false27s := New(28rs,29JobSpec{30Job: JobFunc(func() error {31firstRan = true32return nil33}),34ID: "first",35Schedule: cron.ConstantDelaySchedule{Delay: time.Second},36InitialLockDuration: time.Second,37},38JobSpec{39Job: JobFunc(func() error {40secondRan = true41return nil42}),43ID: "second",44Schedule: cron.ConstantDelaySchedule{Delay: time.Second},45InitialLockDuration: time.Second,46},47)48s.Start()49time.Sleep(1 * time.Second)50s.Stop()5152require.True(t, firstRan)53require.True(t, secondRan)54}555657