MCPcopy Index your code
hub / github.com/coder/coder / TestConfigMaps_updatePeers_same

Function TestConfigMaps_updatePeers_same

tailnet/configmaps_internal_test.go:432–489  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

430}
431
432func TestConfigMaps_updatePeers_same(t *testing.T) {
433 t.Parallel()
434 ctx := testutil.Context(t, testutil.WaitShort)
435 logger := testutil.Logger(t)
436 fEng := newFakeEngineConfigurable()
437 nodePrivateKey := key.NewNode()
438 nodeID := tailcfg.NodeID(5)
439 discoKey := key.NewDisco()
440 uut := newConfigMaps(logger, fEng, nodeID, nodePrivateKey, discoKey.Public(), CoderDNSSuffixFQDN)
441 defer uut.close()
442
443 // Then: we don't configure
444 requireNeverConfigures(ctx, t, &uut.phased)
445
446 p1ID := uuid.UUID{1}
447 p1Node := newTestNode(1)
448 p1n, err := NodeToProto(p1Node)
449 require.NoError(t, err)
450 p1tcn, err := uut.protoNodeToTailcfg(p1n)
451 p1tcn.KeepAlive = true
452 require.NoError(t, err)
453
454 // Given: peer already exists
455 uut.L.Lock()
456 uut.peers[p1ID] = &peerLifecycle{
457 peerID: p1ID,
458 node: p1tcn,
459 lastHandshake: time.Date(2024, 1, 7, 12, 0, 10, 0, time.UTC),
460 }
461 uut.L.Unlock()
462
463 go func() {
464 b := <-fEng.status
465 b.AddPeer(p1Node.Key, &ipnstate.PeerStatus{
466 PublicKey: p1Node.Key,
467 LastHandshake: time.Date(2024, 1, 7, 12, 13, 10, 0, time.UTC),
468 Active: true,
469 })
470 fEng.statusDone <- struct{}{}
471 }()
472
473 // When: update with no changes
474 updates := []*proto.CoordinateResponse_PeerUpdate{
475 {
476 Id: p1ID[:],
477 Kind: proto.CoordinateResponse_PeerUpdate_NODE,
478 Node: p1n,
479 },
480 }
481 uut.updatePeers(updates)
482
483 done := make(chan struct{})
484 go func() {
485 defer close(done)
486 uut.close()
487 }()
488 _ = testutil.TryReceive(ctx, t, done)
489}

Callers

nothing calls this directly

Calls 13

ContextFunction · 0.92
LoggerFunction · 0.92
TryReceiveFunction · 0.92
newConfigMapsFunction · 0.85
requireNeverConfiguresFunction · 0.85
newTestNodeFunction · 0.85
NodeToProtoFunction · 0.85
protoNodeToTailcfgMethod · 0.80
updatePeersMethod · 0.80
closeMethod · 0.65
LockMethod · 0.45

Tested by

no test coverage detected