Files
node/mesh/peer/message_queue_test.go
zeekayandHanzo Dev 37e2940ead mesh is the peer layer, network is the validator set
Two packages were named for the same word and meant different things. network/
dialed peers, exchanged keys, throttled and tracked them; nets/ tracked which
chains share a validator set and when they have all bootstrapped. One letter
apart, and neither name said which was which.

The peer layer is mesh — the word this estate already uses for it, in
lux-rs/node's own mesh.rs. That frees network for the thing that is actually a
network: a set of chains sharing a validator set. A network holds chains; a
chain belongs to one network.

github.com/luxfi/p2p stays what it is, the gossip library the VMs use. Three
concerns, three names, none of them borrowed from another.

Co-authored-by: Hanzo Dev <[email protected]>
2026-09-07 21:17:09 -07:00

76 lines
1.5 KiB
Go

// Copyright (C) 2019-2025, Lux Industries Inc. All rights reserved.
// See the file LICENSE for licensing terms.
package peer
import (
"context"
"testing"
"github.com/stretchr/testify/require"
"github.com/luxfi/log"
"github.com/luxfi/node/message"
)
func TestMessageQueue(t *testing.T) {
require := require.New(t)
expectFail := false
q := NewBlockingMessageQueue(
SendFailedFunc(func(message.OutboundMessage) {
require.True(expectFail)
}),
log.NoLog{},
0,
)
mc := newMessageCreator(t)
msgs := []message.OutboundMessage{}
numToSend := 10
// Assert that the messages are popped in the same order they were pushed
for i := 0; i < numToSend; i++ {
m, err := mc.Ping(uint32(i))
require.NoError(err)
msgs = append(msgs, m)
}
go func() {
for i := 0; i < numToSend; i++ {
q.Push(context.Background(), msgs[i])
}
}()
for i := 0; i < numToSend; i++ {
msg, ok := q.Pop()
require.True(ok)
require.Equal(msgs[i], msg)
}
// Assert that PopNow returns false when the queue is empty
_, ok := q.PopNow()
require.False(ok)
// Assert that Push returns false when the context is canceled
ctx, cancel := context.WithCancel(context.Background())
cancel()
expectFail = true
gotOk := make(chan bool)
go func() {
gotOk <- q.Push(ctx, msgs[0])
}()
require.False(<-gotOk)
// Assert that Push returns false when the queue is closed
go func() {
gotOk <- q.Push(context.Background(), msgs[0])
}()
q.Close()
require.False(<-gotOk)
// Assert Pop returns false when the queue is closed
_, ok = q.Pop()
require.False(ok)
}