Skip to content

Commit

Permalink
Added dummy test for RTP2
Browse files Browse the repository at this point in the history
  • Loading branch information
sacOO7 committed Nov 9, 2023
1 parent 5e28c99 commit 1e58236
Show file tree
Hide file tree
Showing 2 changed files with 83 additions and 8 deletions.
83 changes: 83 additions & 0 deletions ably/proto_presence_message_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@ import (
"encoding/json"
"fmt"
"testing"
"time"

"github.com/ably/ably-go/ably"
"github.com/ably/ably-go/ably/internal/ablyutil"
"github.com/ably/ably-go/ablytest"

"github.com/stretchr/testify/assert"
)
Expand Down Expand Up @@ -159,3 +161,84 @@ func TestPresenceMessagesShouldReturnErrorForWrongMessageSerials__RTP2b2(t *test
assert.Contains(t, fmt.Sprint(err), "the presence message has invalid msgSerial, for msgId 123:1a:0")
assert.True(t, isNewMsg)
}

func Test_PresenceMap_RTP2(t *testing.T) {
const channelRetryTimeout = 123 * time.Millisecond
const realtimeRequestTimeout = 2 * time.Second

setup := func(t *testing.T) (
in, out chan *ably.ProtocolMessage,
c *ably.Realtime,
channel *ably.RealtimeChannel,
stateChanges ably.ChannelStateChanges,
afterCalls chan ablytest.AfterCall,
) {
in = make(chan *ably.ProtocolMessage, 1)
out = make(chan *ably.ProtocolMessage, 16)
afterCalls = make(chan ablytest.AfterCall, 1)
now, after := ablytest.TimeFuncs(afterCalls)

c, _ = ably.NewRealtime(
ably.WithToken("fake:token"),
ably.WithAutoConnect(false),
ably.WithChannelRetryTimeout(channelRetryTimeout),
ably.WithRealtimeRequestTimeout(realtimeRequestTimeout),
ably.WithDial(MessagePipe(in, out)),
ably.WithNow(now),
ably.WithAfter(after),
)

in <- &ably.ProtocolMessage{
Action: ably.ActionConnected,
ConnectionID: "connection-id",
ConnectionDetails: &ably.ConnectionDetails{},
}

err := ablytest.Wait(ablytest.ConnWaiter(c, c.Connect, ably.ConnectionEventConnected), nil)
assert.NoError(t, err)

channel = c.Channels.Get("test")
stateChanges = make(ably.ChannelStateChanges, 10)
return
}

t.Run("RTL14: when Error, should transition to failed state", func(t *testing.T) {
in, out, _, channel, stateChanges, afterCalls := setup(t)

errInfo := ably.ProtoErrorInfo{
StatusCode: 500,
Code: 50500,
Message: "fake error",
}

in <- &ably.ProtocolMessage{
Action: ably.ActionError,
Channel: channel.Name,
Error: &errInfo,
}

// Expect a state change with the error.

var change ably.ChannelStateChange
ablytest.Instantly.Recv(t, &change, stateChanges, t.Fatalf)
assert.Equal(t, ably.ChannelStateFailed, change.Current,
"expected %v; got %v (event: %+v)", change)

got := fmt.Sprint(change.Reason)
assert.Contains(t, got, "fake error",
"expected error info to contain \"fake error\"; got %v", got)

got = fmt.Sprint(channel.ErrorReason())
assert.Contains(t, got, "fake error",
"expected error info to contain \"fake error\"; got %v", got)

ablytest.Instantly.NoRecv(t, nil, afterCalls, t.Fatalf)
ablytest.Instantly.NoRecv(t, nil, stateChanges, t.Fatalf)
ablytest.Instantly.NoRecv(t, nil, out, t.Fatalf)
})

}

func Test_Presence_SYNC_RTP18(t *testing.T) {
assert.True(t, true)
}
8 changes: 0 additions & 8 deletions ably/realtime_presence_internal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,11 +113,3 @@ func TestSend(t *testing.T) {
})
}
}

func Test_PresenceMap_RTP2(t *testing.T) {
assert.True(t, true)
}

func Test_Presence_SYNC_RTP18(t *testing.T) {
assert.True(t, true)
}

0 comments on commit 1e58236

Please sign in to comment.