diff --git a/client/embed/embed.go b/client/embed/embed.go index 6b1d69935..32e567be4 100644 --- a/client/embed/embed.go +++ b/client/embed/embed.go @@ -49,6 +49,11 @@ type PeerConnStatus = peer.ConnStatus // PeerState is the status recorder's view of one remote peer, as carried in // the Peers field of the value returned by Status and StatusSnapshot. +// +// It is a read-only snapshot. The scalar fields are copied under the +// recorder's lock and are safe to read, but the value still shares its mutex +// and route map with the recorder, so callers must not mutate it or call its +// route methods. type PeerState = peer.State // Client manages a netbird embedded client instance. diff --git a/client/embed/embed_test.go b/client/embed/embed_test.go index 0f135efe8..169d131d6 100644 --- a/client/embed/embed_test.go +++ b/client/embed/embed_test.go @@ -233,9 +233,16 @@ func TestClientSyncResponsePersistence(t *testing.T) { } }) + // Start returns before the first sync response necessarily arrives, so + // wait for the engine to apply one. Without this the assertion below + // could pass on a client that simply has not synced yet. + require.Eventually(t, func() bool { + return client.StatusSnapshot().LocalPeerState.IP != "" + }, 30*time.Second, 200*time.Millisecond, "the initial management sync should be applied") + if !tc.persisted { _, err := client.GetLatestSyncResponse() - require.Error(t, err, "no sync response may be retained when persistence is disabled") + require.ErrorContains(t, err, "persistence is disabled", "the sync response must be dropped, not merely unavailable") return }