Files
threshold/internal/servers/worker/status_test.go
T
Louis RuchandJeff Mitchell 31af49e76d refactor(worker): Move tcp_proxy into its own package (#1458)
* refactor(worker): Move tcp_proxy into its own package

This refactors:

- the tcp_proxy.go into worker/proxy/tcp
- add a missing unit test for the HandleTcpProxyV1
- refactors session.go into worker/session, needed to avoid import cycle
- adds a baseline for a mock controller session client
- go lint fixes

* Add sleep between spinning listener goroutine and dialing

Co-authored-by: Jeff Mitchell <jeffrey.mitchell@gmail.com>
2021-08-18 15:30:55 +02:00

67 lines
1.6 KiB
Go

package worker
import (
"context"
"sync"
"sync/atomic"
"testing"
"time"
"github.com/hashicorp/boundary/internal/cmd/base"
"github.com/hashicorp/boundary/internal/observability/event"
"github.com/hashicorp/go-hclog"
"github.com/stretchr/testify/require"
)
func TestWorkerWaitForNextSuccessfulStatusUpdate(t *testing.T) {
// do not run using t.Parallel() since it relies on the sys eventer
event.TestEnableEventing(t, true)
testConfig := event.DefaultEventerConfig()
testLock := &sync.Mutex{}
testLogger := hclog.New(&hclog.LoggerOptions{
Mutex: testLock,
})
err := event.InitSysEventer(testLogger, testLock, "TestWorkerWaitForNextSuccessfulStatusUpdate", event.WithEventerConfig(testConfig))
require.NoError(t, err)
for _, name := range []string{"ok", "timeout"} {
t.Run(name, func(t *testing.T) {
require := require.New(t)
// As-needed initialization of a mock worker
w := &Worker{
logger: hclog.New(nil),
lastStatusSuccess: new(atomic.Value),
baseContext: context.Background(),
conf: &Config{
Server: &base.Server{
StatusGracePeriodDuration: time.Second * 2,
},
},
}
// This is present in New()
w.lastStatusSuccess.Store((*LastStatusInformation)(nil))
var wg sync.WaitGroup
var err error
wg.Add(1)
go func() {
err = w.WaitForNextSuccessfulStatusUpdate()
wg.Done()
}()
if name == "ok" {
time.Sleep(time.Millisecond * 100)
w.lastStatusSuccess.Store(&LastStatusInformation{StatusTime: time.Now()})
}
wg.Wait()
if name == "timeout" {
require.ErrorIs(err, context.DeadlineExceeded)
} else {
require.NoError(err)
}
})
}
}