kubo/test/cli/backup_bootstrap_test.go
Andrew Gillis aa3c88dcdd
Some checks failed
CodeQL / codeql (push) Has been cancelled
Docker Check / lint (push) Has been cancelled
Docker Check / build (push) Has been cancelled
Gateway Conformance / gateway-conformance (push) Has been cancelled
Gateway Conformance / gateway-conformance-libp2p-experiment (push) Has been cancelled
Go Build / go-build (push) Has been cancelled
Go Check / go-check (push) Has been cancelled
Go Lint / go-lint (push) Has been cancelled
Go Test / unit-tests (push) Has been cancelled
Go Test / cli-tests (push) Has been cancelled
Go Test / example-tests (push) Has been cancelled
Interop / interop-prep (push) Has been cancelled
Sharness / sharness-test (push) Has been cancelled
Spell Check / spellcheck (push) Has been cancelled
Interop / helia-interop (push) Has been cancelled
Interop / ipfs-webui (push) Has been cancelled
shutdown daemon after test (#11135)
2026-01-07 20:51:19 -08:00

64 lines
1.8 KiB
Go

package cli
import (
"fmt"
"testing"
"time"
"github.com/ipfs/kubo/config"
"github.com/ipfs/kubo/test/cli/harness"
"github.com/stretchr/testify/assert"
)
func TestBackupBootstrapPeers(t *testing.T) {
nodes := harness.NewT(t).NewNodes(3).Init()
nodes.ForEachPar(func(n *harness.Node) {
n.UpdateConfig(func(cfg *config.Config) {
cfg.Bootstrap = []string{}
cfg.Addresses.Swarm = []string{fmt.Sprintf("/ip4/127.0.0.1/tcp/%d", harness.NewRandPort())}
cfg.Discovery.MDNS.Enabled = false
cfg.Internal.BackupBootstrapInterval = config.NewOptionalDuration(250 * time.Millisecond)
})
})
// Start all nodes and ensure they all have no peers.
nodes.StartDaemons()
nodes.ForEachPar(func(n *harness.Node) {
assert.Len(t, n.Peers(), 0)
})
// Connect nodes 0 and 1, ensure they know each other.
nodes[0].Connect(nodes[1])
assert.Len(t, nodes[0].Peers(), 1)
assert.Len(t, nodes[1].Peers(), 1)
assert.Len(t, nodes[2].Peers(), 0)
// Wait a bit to ensure that 0 and 1 saved their temporary bootstrap backups.
time.Sleep(time.Millisecond * 500)
nodes.StopDaemons()
// Start 1 and 2. 2 does not know anyone yet.
nodes[1].StartDaemon()
defer nodes[1].StopDaemon()
nodes[2].StartDaemon()
defer nodes[2].StopDaemon()
assert.Len(t, nodes[1].Peers(), 0)
assert.Len(t, nodes[2].Peers(), 0)
// Connect 1 and 2, ensure they know each other.
nodes[1].Connect(nodes[2])
assert.Len(t, nodes[1].Peers(), 1)
assert.Len(t, nodes[2].Peers(), 1)
// Start 0, wait a bit. Should connect to 1, and then discover 2 via the
// backup bootstrap peers.
nodes[0].StartDaemon()
defer nodes[0].StopDaemon()
time.Sleep(time.Millisecond * 500)
// Check if they're all connected.
assert.Len(t, nodes[0].Peers(), 2)
assert.Len(t, nodes[1].Peers(), 2)
assert.Len(t, nodes[2].Peers(), 2)
}