You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

42 lines
735 B

  1. package service
  2. import (
  3. "context"
  4. "testing"
  5. "time"
  6. "github.com/stretchr/testify/require"
  7. )
  8. type testService struct {
  9. BaseService
  10. }
  11. func (testService) OnReset() error {
  12. return nil
  13. }
  14. func TestBaseServiceWait(t *testing.T) {
  15. ctx, cancel := context.WithCancel(context.Background())
  16. defer cancel()
  17. ts := &testService{}
  18. ts.BaseService = *NewBaseService(nil, "TestService", ts)
  19. err := ts.Start(ctx)
  20. require.NoError(t, err)
  21. waitFinished := make(chan struct{})
  22. go func() {
  23. ts.Wait()
  24. waitFinished <- struct{}{}
  25. }()
  26. go ts.Stop() //nolint:errcheck // ignore for tests
  27. select {
  28. case <-waitFinished:
  29. // all good
  30. case <-time.After(100 * time.Millisecond):
  31. t.Fatal("expected Wait() to finish within 100 ms.")
  32. }
  33. }