From 298e9d9fad765839fd0d79bde07434a997e7b3af Mon Sep 17 00:00:00 2001 From: riccardom Date: Tue, 20 Oct 2026 12:25:02 +0200 Subject: [PATCH] [client] Make the decode-once test exercise a pending target The later pass ran with no pending map, so it showed only that the update was not decoded, not that the map decoded on the first pass gets applied. It now starts from a pending map and checks the pass consumes it. --- client/internal/engine_test.go | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/client/internal/engine_test.go b/client/internal/engine_test.go index 6173e99d7..7394de106 100644 --- a/client/internal/engine_test.go +++ b/client/internal/engine_test.go @@ -1778,22 +1778,26 @@ func TestEngine_SyncResponsePersistenceKeepsEnvelope(t *testing.T) { // Decoding a components envelope runs Calculate(), the most expensive step of a // sync. It belongs to the target, not to the pass: the bounded re-runs that -// drain peer batches must reuse the map the first pass decoded. The second -// update below claims the components format without an envelope, which only -// fails if it gets decoded. +// drain peer batches must apply the map the first pass decoded. The update +// handed to the later pass claims the components format without an envelope, +// which only fails if it gets decoded again. func TestEngine_ApplySyncPassDecodesOncePerTarget(t *testing.T) { + // The pending map stands for one a first pass decoded and left unfinished. + // Its serial is below the applied one so updateNetworkMap consumes it + // without needing the interface, firewall or peer machinery. + pending := &mgmtProto.NetworkMap{Serial: 1} e := &Engine{ - ctx: context.Background(), - syncMsgMux: &sync.Mutex{}, + ctx: context.Background(), + syncMsgMux: &sync.Mutex{}, + networkSerial: 5, + syncTargetMap: pending, } - more, err := e.applySyncPass(&mgmtProto.SyncResponse{}, true) - require.NoError(t, err) - require.False(t, more, "a target without a network map has nothing left to apply") - undecodable := &mgmtProto.SyncResponse{Version: int32(sharedgrpc.ComponentNetworkMap)} - _, err = e.applySyncPass(undecodable, false) - assert.NoError(t, err, "a later pass must not decode the update again") + more, err := e.applySyncPass(undecodable, false) + require.NoError(t, err, "a later pass must apply the pending map, not decode the update again") + assert.False(t, more, "the pending map has no peer batches left") + assert.Nil(t, e.syncTargetMap, "the later pass should have consumed the pending map") _, err = e.applySyncPass(undecodable, true) assert.Error(t, err, "the first pass of a target decodes it")