Add async fabric session pump
This commit is contained in:
@@ -133,6 +133,73 @@ func TestClientFabricSessionPersistentDataAcks(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestClientFabricSessionPumpMovesIndependentFrames(t *testing.T) {
|
||||
server := httptest.NewServer(Server{
|
||||
Local: PeerIdentity{ClusterID: "cluster-1", NodeID: "node-a"},
|
||||
FabricSessionEnabled: true,
|
||||
}.Handler())
|
||||
defer server.Close()
|
||||
|
||||
client := NewClient(server.URL)
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 2*time.Second)
|
||||
defer cancel()
|
||||
session, _, err := client.OpenFabricSession(ctx, FabricSessionDialOptions{
|
||||
Token: "rap_fsn_pump",
|
||||
Timeout: time.Second,
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatalf("open fabric session: %v", err)
|
||||
}
|
||||
pump := session.StartPump(ctx, FabricSessionPumpOptions{
|
||||
OutboundBuffer: 4,
|
||||
InboundBuffer: 4,
|
||||
ErrorBuffer: 4,
|
||||
})
|
||||
defer pump.Close()
|
||||
|
||||
if err := pump.Send(ctx, fabricproto.Frame{
|
||||
Type: fabricproto.FrameOpenStream,
|
||||
StreamID: 900,
|
||||
TrafficClass: fabricproto.TrafficClassBulk,
|
||||
}); err != nil {
|
||||
t.Fatalf("send open bulk stream: %v", err)
|
||||
}
|
||||
if err := pump.Send(ctx, fabricproto.Frame{
|
||||
Type: fabricproto.FrameData,
|
||||
StreamID: 900,
|
||||
Sequence: 31,
|
||||
TrafficClass: fabricproto.TrafficClassBulk,
|
||||
Payload: []byte("bulk payload"),
|
||||
}); err != nil {
|
||||
t.Fatalf("send bulk data: %v", err)
|
||||
}
|
||||
if err := pump.Send(ctx, fabricproto.Frame{
|
||||
Type: fabricproto.FramePing,
|
||||
Sequence: 32,
|
||||
Payload: []byte("control ping"),
|
||||
}); err != nil {
|
||||
t.Fatalf("send ping: %v", err)
|
||||
}
|
||||
|
||||
gotAck := false
|
||||
gotPong := false
|
||||
for !gotAck || !gotPong {
|
||||
select {
|
||||
case frame := <-pump.Frames():
|
||||
switch {
|
||||
case frame.Type == fabricproto.FrameAck && frame.StreamID == 900 && frame.Sequence == 31:
|
||||
gotAck = true
|
||||
case frame.Type == fabricproto.FramePong && frame.Sequence == 32 && string(frame.Payload) == "control ping":
|
||||
gotPong = true
|
||||
}
|
||||
case err := <-pump.Errors():
|
||||
t.Fatalf("pump error: %v", err)
|
||||
case <-ctx.Done():
|
||||
t.Fatalf("timed out waiting for pump frames: ack=%v pong=%v", gotAck, gotPong)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestClientFabricSessionReportsRejectedStatus(t *testing.T) {
|
||||
server := httptest.NewServer(Server{
|
||||
Local: PeerIdentity{ClusterID: "cluster-1", NodeID: "node-a"},
|
||||
|
||||
Reference in New Issue
Block a user