32 lines
593 B
Go
32 lines
593 B
Go
package main
|
|
|
|
import (
|
|
"context"
|
|
"sync"
|
|
"testing"
|
|
"time"
|
|
|
|
"micro_layout/cmd/crontab/config"
|
|
)
|
|
|
|
func TestRunCrontabStopsOnCancellation(t *testing.T) {
|
|
conf = &config.Config{}
|
|
conf.Server.ShutdownTimeout = time.Second
|
|
wg = &sync.WaitGroup{}
|
|
wg.Add(1)
|
|
ctx, cancel := context.WithCancel(context.Background())
|
|
defer cancel()
|
|
result := make(chan error, 1)
|
|
go func() { result <- runCrontab(ctx) }()
|
|
cancel()
|
|
select {
|
|
case err := <-result:
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
wg.Wait()
|
|
case <-time.After(2 * time.Second):
|
|
t.Fatal("crontab did not stop after cancellation")
|
|
}
|
|
}
|