control/controlclient: introduce eventbus messages instead of callbacks (#16956)
This is a small introduction of the eventbus into controlclient that communicates with mainly ipnlocal. While ipnlocal is a complicated part of the codebase, the subscribers here are from the perspective of ipnlocal already called async. Updates #15160 Signed-off-by: Claus Lensbøl <claus@tailscale.com>
This commit is contained in:
+20
-11
@@ -7,6 +7,7 @@ import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"math/rand/v2"
|
||||
"net/netip"
|
||||
"strings"
|
||||
"sync"
|
||||
@@ -39,6 +40,7 @@ import (
|
||||
"tailscale.com/types/persist"
|
||||
"tailscale.com/types/preftype"
|
||||
"tailscale.com/util/dnsname"
|
||||
"tailscale.com/util/eventbus/eventbustest"
|
||||
"tailscale.com/util/mak"
|
||||
"tailscale.com/util/must"
|
||||
"tailscale.com/wgengine"
|
||||
@@ -113,10 +115,11 @@ func (nt *notifyThrottler) drain(count int) []ipn.Notify {
|
||||
// in the controlclient.Client, so by controlling it, we can check that
|
||||
// the state machine works as expected.
|
||||
type mockControl struct {
|
||||
tb testing.TB
|
||||
logf logger.Logf
|
||||
opts controlclient.Options
|
||||
paused atomic.Bool
|
||||
tb testing.TB
|
||||
logf logger.Logf
|
||||
opts controlclient.Options
|
||||
paused atomic.Bool
|
||||
controlClientID int64
|
||||
|
||||
mu sync.Mutex
|
||||
persist *persist.Persist
|
||||
@@ -127,12 +130,13 @@ type mockControl struct {
|
||||
|
||||
func newClient(tb testing.TB, opts controlclient.Options) *mockControl {
|
||||
return &mockControl{
|
||||
tb: tb,
|
||||
authBlocked: true,
|
||||
logf: opts.Logf,
|
||||
opts: opts,
|
||||
shutdown: make(chan struct{}),
|
||||
persist: opts.Persist.Clone(),
|
||||
tb: tb,
|
||||
authBlocked: true,
|
||||
logf: opts.Logf,
|
||||
opts: opts,
|
||||
shutdown: make(chan struct{}),
|
||||
persist: opts.Persist.Clone(),
|
||||
controlClientID: rand.Int64(),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -287,6 +291,10 @@ func (cc *mockControl) UpdateEndpoints(endpoints []tailcfg.Endpoint) {
|
||||
cc.called("UpdateEndpoints")
|
||||
}
|
||||
|
||||
func (cc *mockControl) ClientID() int64 {
|
||||
return cc.controlClientID
|
||||
}
|
||||
|
||||
func (b *LocalBackend) nonInteractiveLoginForStateTest() {
|
||||
b.mu.Lock()
|
||||
if b.cc == nil {
|
||||
@@ -1507,7 +1515,8 @@ func newLocalBackendWithMockEngineAndControl(t *testing.T, enableLogging bool) (
|
||||
dialer := &tsdial.Dialer{Logf: logf}
|
||||
dialer.SetNetMon(netmon.NewStatic())
|
||||
|
||||
sys := tsd.NewSystem()
|
||||
bus := eventbustest.NewBus(t)
|
||||
sys := tsd.NewSystemWithBus(bus)
|
||||
sys.Set(dialer)
|
||||
sys.Set(dialer.NetMon())
|
||||
|
||||
|
||||
Reference in New Issue
Block a user