Files
shadowdaoandClaude Sonnet 5.5 962d708fdd Rename Go module paths to repo.anhonesthost.net/CyberCoveLLC/threshold
Rename root, api and sdk module paths (imports, go.mod, go_package,
ldflags, build scripts, buf configs) and regenerate protobuf/gateway
code with the project's pinned toolchain. Wire identifiers unchanged.
api gets a local replace for sdk; root/api/sdk require v0.1.0.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-10-12 10:33:41 -07:00

70 lines
1.9 KiB
Go

// Copyright IBM Corp. 2020, 2026
// SPDX-License-Identifier: BUSL-1.1
package worker
import (
"context"
"sync"
"sync/atomic"
"testing"
"time"
"repo.anhonesthost.net/CyberCoveLLC/threshold/internal/cmd/base"
"repo.anhonesthost.net/CyberCoveLLC/threshold/internal/daemon/worker/common"
"repo.anhonesthost.net/CyberCoveLLC/threshold/internal/event"
"github.com/hashicorp/go-hclog"
"github.com/stretchr/testify/require"
)
func TestWorkerWaitForNextSuccessfulRoutingInfoUpdate(t *testing.T) {
testConfig := event.DefaultEventerConfig()
testLock := &sync.Mutex{}
testLogger := hclog.New(&hclog.LoggerOptions{
Mutex: testLock,
})
err := event.InitSysEventer(testLogger, testLock, "TestWorkerWaitForNextSuccessfulRoutingInfoUpdate", event.WithEventerConfig(testConfig))
require.NoError(t, err)
t.Cleanup(func() { event.TestResetSystEventer(t) })
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),
lastRoutingInfoSuccess: new(atomic.Value),
baseContext: context.Background(),
successfulRoutingInfoGracePeriod: new(atomic.Int64),
conf: &Config{
Server: &base.Server{},
},
}
// This is present in New()
w.lastRoutingInfoSuccess.Store((*LastRoutingInfo)(nil))
w.successfulRoutingInfoGracePeriod.Store(int64(common.DefaultRoutingInfoTimeout))
var wg sync.WaitGroup
var err error
wg.Add(1)
go func() {
err = w.WaitForNextSuccessfulRoutingInfoUpdate()
wg.Done()
}()
if name == "ok" {
time.Sleep(time.Millisecond * 100)
w.lastRoutingInfoSuccess.Store(&LastRoutingInfo{RoutingInfoTime: time.Now()})
}
wg.Wait()
if name == "timeout" {
require.ErrorIs(err, context.DeadlineExceeded)
} else {
require.NoError(err)
}
})
}
}