* Move the server daemons into their own package With this change the internal/server package now is dedicated to the server domain (workers and controllers) and not to the server daemons. The hope is that this will make it easier to keep the daemons decoupled from the representation of the servers in the database.
65 lines
1.5 KiB
Go
65 lines
1.5 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) {
|
|
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)
|
|
}
|
|
})
|
|
}
|
|
}
|