Files
zeekay 285bb5a76b rename: ziti → zt across all paths
- Repo names: ziti-* → zt-*
- Go modules: github.com/hanzozt/ziti → github.com/hanzozt/zt
- Docker images: hanzozt/ziti-* → hanzozt/zt-*
- C/Java/JS symbols: ziti_* → zt_*
- File and directory names updated
2026-02-18 18:34:10 -08:00

99 lines
2.2 KiB
Go

package network
import (
"fmt"
"github.com/hanzozt/channel/v4"
"github.com/hanzozt/sdk-golang/zt/edge"
"github.com/stretchr/testify/require"
"math"
"testing"
"time"
)
func Test_SeqNormalReadDeadline(t *testing.T) {
closeNotify := make(chan struct{})
defer close(closeNotify)
readQ := NewNoopSequencer[*channel.Message](closeNotify, 4)
start := time.Now()
readQ.SetReadDeadline(start.Add(10 * time.Millisecond))
req := require.New(t)
_, err := readQ.GetNext()
req.NotNil(err)
req.ErrorIs(err, &ReadTimout{})
first := time.Now()
req.True(first.Sub(start) >= 10*time.Millisecond)
_, err = readQ.GetNext()
req.NotNil(err)
req.ErrorIs(err, &ReadTimout{})
req.True(time.Since(first) < time.Millisecond)
}
func Test_SeqNormalReadWithDeadline(t *testing.T) {
closeNotify := make(chan struct{})
defer close(closeNotify)
readQ := NewNoopSequencer[*channel.Message](closeNotify, 4)
start := time.Now()
readQ.SetReadDeadline(start.Add(10 * time.Millisecond))
req := require.New(t)
data := make([]byte, 877)
msg := edge.NewDataMsg(1, data)
req.NoError(readQ.PutSequenced(msg))
val, err := readQ.GetNext()
req.NoError(err)
req.Equal(msg, val)
}
func Test_SeqNormalReadWithNoDeadline(t *testing.T) {
closeNotify := make(chan struct{})
defer close(closeNotify)
readQ := NewNoopSequencer[*channel.Message](closeNotify, 4)
req := require.New(t)
data := make([]byte, 877)
msg := edge.NewDataMsg(1, data)
req.NoError(readQ.PutSequenced(msg))
val, err := readQ.GetNext()
req.NoError(err)
req.Equal(msg, val)
}
func Test_SeqReadWithInterrupt(t *testing.T) {
closeNotify := make(chan struct{})
defer close(closeNotify)
readQ := NewNoopSequencer[*channel.Message](closeNotify, 4)
start := time.Now()
req := require.New(t)
go func() {
readQ.SetReadDeadline(start.Add(10 * time.Millisecond))
}()
_, err := readQ.GetNext()
req.NotNil(err)
req.ErrorIs(err, &ReadTimout{})
first := time.Now()
req.True(first.Sub(start) >= 10*time.Millisecond)
_, err = readQ.GetNext()
req.NotNil(err)
req.ErrorIs(err, &ReadTimout{})
req.True(time.Since(first) < time.Millisecond)
}
func Test_GetMaxMsgMux(t *testing.T) {
maxId := (math.MaxUint32 / 2) - 1
fmt.Printf("max id: %d\n", maxId)
}