* Chore: Add initial support for deployment modes * revert CLI changes and start modules independently * add modules to codeowners * additional comments * add Engine and Manager interface to fix test issues * convert background service registry to dskit module * remove extra context from serviceListener logger Co-authored-by: Will Browne <wbrowne@users.noreply.github.com> * Remove whitespace * fix import * undo ide changes * only register All by default * with registry * add test * add comments * re-add debug log * fix import * reorganize arg * undo kind changes * add provide service test * fix import * rejig systemd calls * update codeowners --------- Co-authored-by: Todd Treece <todd.treece@grafana.com> Co-authored-by: Todd Treece <360020+toddtreece@users.noreply.github.com>
53 lines
1.1 KiB
Go
53 lines
1.1 KiB
Go
package backgroundsvcs
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"fmt"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func TestBackgroundServiceRunner_Run_Error(t *testing.T) {
|
|
testErr := errors.New("boom")
|
|
registry := NewBackgroundServiceRegistry(newTestService("A", nil, false), newTestService("B", testErr, false))
|
|
r := ProvideBackgroundServiceRunner(registry)
|
|
|
|
err := r.run(context.Background())
|
|
require.ErrorIs(t, err, testErr)
|
|
}
|
|
|
|
type testBackgroundService struct {
|
|
name string
|
|
started chan struct{}
|
|
runErr error
|
|
isDisabled bool
|
|
}
|
|
|
|
func newTestService(name string, runErr error, disabled bool) *testBackgroundService {
|
|
return &testBackgroundService{
|
|
name: name,
|
|
started: make(chan struct{}),
|
|
runErr: runErr,
|
|
isDisabled: disabled,
|
|
}
|
|
}
|
|
|
|
func (s *testBackgroundService) Run(ctx context.Context) error {
|
|
if s.isDisabled {
|
|
return fmt.Errorf("shouldn't run disabled service")
|
|
}
|
|
|
|
if s.runErr != nil {
|
|
return s.runErr
|
|
}
|
|
close(s.started)
|
|
<-ctx.Done()
|
|
return ctx.Err()
|
|
}
|
|
|
|
func (s *testBackgroundService) IsDisabled() bool {
|
|
return s.isDisabled
|
|
}
|