kubo/test/cli/harness/nodes.go
Andrew Gillis ae068a8061
Some checks failed
CodeQL / codeql (push) Has been cancelled
Docker Build / docker-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 / go-test (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
fix: harness tests random panic (#10933)
* fix: harness tests random panic

Connecting nodes in parallel can cause TLS handshake failures. For each node, connect to the other nodes serially. It is not necessary to connect in parallel as it does not save any significant time.

Closes #10932
2025-08-22 13:57:35 -07:00

59 lines
1.2 KiB
Go

package harness
import (
"sync"
. "github.com/ipfs/kubo/test/cli/testutils"
"github.com/multiformats/go-multiaddr"
)
// Nodes is a collection of Kubo nodes along with operations on groups of nodes.
type Nodes []*Node
func (n Nodes) Init(args ...string) Nodes {
ForEachPar(n, func(node *Node) { node.Init(args...) })
return n
}
func (n Nodes) ForEachPar(f func(*Node)) {
var wg sync.WaitGroup
for _, node := range n {
wg.Add(1)
node := node
go func() {
defer wg.Done()
f(node)
}()
}
wg.Wait()
}
func (n Nodes) Connect() Nodes {
for i, node := range n {
for j, otherNode := range n {
if i == j {
continue
}
// Do not connect in parallel, because that can cause TLS handshake problems on some platforms.
node.Connect(otherNode)
}
}
for _, node := range n {
firstPeer := node.Peers()[0]
if _, err := firstPeer.ValueForProtocol(multiaddr.P_P2P); err != nil {
log.Panicf("unexpected state for node %d with peer ID %s: %s", node.ID, node.PeerID(), err)
}
}
return n
}
func (n Nodes) StartDaemons(args ...string) Nodes {
ForEachPar(n, func(node *Node) { node.StartDaemon(args...) })
return n
}
func (n Nodes) StopDaemons() Nodes {
ForEachPar(n, func(node *Node) { node.StopDaemon() })
return n
}