50 lines
1.7 KiB
Go
50 lines
1.7 KiB
Go
package mesh
|
|
|
|
import (
|
|
"context"
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/example/remote-access-platform/agents/rap-node-agent/internal/fabricproto"
|
|
)
|
|
|
|
func TestFabricOverlayTransportSendsThroughRouteSet(t *testing.T) {
|
|
transport := newFakeFabricRuntimeTransport(map[string]time.Duration{
|
|
"quic://node-b:19443": 0,
|
|
})
|
|
overlay := NewFabricOverlayTransport(transport, map[string]FabricRouteSet{
|
|
"node-b": {
|
|
TargetKind: FabricChannelTargetNode,
|
|
TargetID: "node-b",
|
|
Primary: FabricRoute{
|
|
RouteID: "node-b-direct",
|
|
ClusterID: "cluster-1",
|
|
SourceNodeID: "node-a",
|
|
DestinationNodeID: "node-b",
|
|
Hops: []FabricRouteHop{{NodeID: "node-b", Mode: FabricRouteDirect, EndpointID: "node-b-direct", Address: "quic://node-b:19443"}},
|
|
Capacity: 100,
|
|
Healthy: true,
|
|
},
|
|
},
|
|
}, FabricOverlayTransportConfig{ClusterID: "cluster-1", LocalNodeID: "node-a"})
|
|
ctx, cancel := context.WithTimeout(context.Background(), time.Second)
|
|
defer cancel()
|
|
result, err := overlay.Send(ctx, FabricOverlaySendRequest{
|
|
TargetID: "node-b",
|
|
TrafficClass: fabricproto.TrafficClassReliable,
|
|
Payloads: [][]byte{[]byte("payload")},
|
|
})
|
|
if err != nil {
|
|
t.Fatalf("send: %v", err)
|
|
}
|
|
if result.BytesSent != uint64(len("payload")) || result.AcksReceived != 1 {
|
|
t.Fatalf("result = %+v", result)
|
|
}
|
|
if pressure := overlay.SnapshotPressure(); pressure.ActiveTotal != 0 || pressure.AcquiredTotal != pressure.ReleasedTotal {
|
|
t.Fatalf("pressure leak: %+v", pressure)
|
|
}
|
|
if snapshot := overlay.Snapshot(); snapshot.RoutePressure.AcquiredTotal != 1 || len(snapshot.RouteHealth.Quarantined) != 0 {
|
|
t.Fatalf("snapshot = %+v", snapshot)
|
|
}
|
|
}
|