Skip to content

Commit

Permalink
Test fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
gbjk committed Feb 19, 2024
1 parent 6f49e02 commit 0950ac3
Showing 1 changed file with 12 additions and 23 deletions.
35 changes: 12 additions & 23 deletions exchanges/stream/websocket_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -552,7 +552,7 @@ func TestGetSubscription(t *testing.T) {
t.Parallel()
assert.Nil(t, (*Websocket).GetSubscription(nil, "imaginary"), "GetSubscription on a nil Websocket should return nil")
assert.Nil(t, (&Websocket{}).GetSubscription("empty"), "GetSubscription on a Websocket with no sub store should return nil")
w := New()
w := NewWebsocket()
assert.Nil(t, w.GetSubscription(nil), "GetSubscription with a nil key should return nil")
s := &subscription.Subscription{Key: 42, Channel: "hello3"}
w.AddSubscription(s)
Expand All @@ -564,7 +564,7 @@ func TestGetSubscriptions(t *testing.T) {
t.Parallel()
assert.Nil(t, (*Websocket).GetSubscriptions(nil), "GetSubscription on a nil Websocket should return nil")
assert.Nil(t, (&Websocket{}).GetSubscriptions(), "GetSubscription on a Websocket with no sub store should return nil")
w := New()
w := NewWebsocket()
w.AddSubscriptions(subscription.List{
{Key: 42, Channel: "hello3"},
{Key: 45, Channel: "hello4"},
Expand Down Expand Up @@ -919,7 +919,7 @@ func TestGetChannelDifference(t *testing.T) {
s.SetState(subscription.SubscribedState)
}

w.AddSubscriptions(subs)
web.AddSubscriptions(subs)

flushedSubs := subscription.List{
{Channel: "Test2"},
Expand Down Expand Up @@ -1028,7 +1028,7 @@ func TestFlushChannels(t *testing.T) {
w.GenerateSubs = func() (subscription.List, error) {
return subscription.List{{Channel: "test"}}, nil
}
err = web.FlushChannels()
err = w.FlushChannels()
require.NoError(t, err, "Flush Channels must not error")

w.features.FullPayloadSubscribe = true
Expand All @@ -1040,36 +1040,28 @@ func TestFlushChannels(t *testing.T) {
err = w.FlushChannels() // No subs to sub
assert.NoError(t, err, "Flush Channels should not error")

web.GenerateSubs = newgen.generateSubs
subs, err := web.GenerateSubs()
w.GenerateSubs = newgen.generateSubs
subs, err := w.GenerateSubs()
require.NoError(t, err, "GenerateSubs must not error")
for _, s := range subs {
s.SetState(subscription.SubscribedState)
}
web.AddSubscriptions(subs)
err = web.FlushChannels()
if err != nil {
t.Fatal(err)
}
web.features.FullPayloadSubscribe = false
web.features.Subscribe = true

w.AddSuccessfulSubscriptions(subs...)
w.AddSubscriptions(subs)
err = w.FlushChannels()
assert.NoError(t, err, "FlushChannels should not error")
w.features.FullPayloadSubscribe = false
w.features.Subscribe = true

web.GenerateSubs = newgen.generateSubs
err = web.FlushChannels()
w.GenerateSubs = newgen.generateSubs
err = w.FlushChannels()
assert.ErrorIs(t, err, errDastardlyReason, "FlushChannels should error correctly")
web.subscriptions = subscription.NewStore()
web.subscriptions.Add(&subscription.Subscription{
w.subscriptions = subscription.NewStore()
w.subscriptions.Add(&subscription.Subscription{
Key: 41,
Channel: "match channel",
Pairs: currency.Pairs{currency.NewPair(currency.BTC, currency.AUD)},
})
web.subscriptions.Add(&subscription.Subscription{
w.subscriptions.Add(&subscription.Subscription{
Key: 42,
Channel: "unsub channel",
Pairs: currency.Pairs{currency.NewPair(currency.THETA, currency.USDT)},
Expand All @@ -1078,9 +1070,6 @@ func TestFlushChannels(t *testing.T) {
err = w.FlushChannels()
assert.NoError(t, err, "FlushChannels should not error")

err = w.FlushChannels()
assert.NoError(t, err, "FlushChannels should not error")

w.setState(connected)
w.features.Unsubscribe = true
err = w.FlushChannels()
Expand Down

0 comments on commit 0950ac3

Please sign in to comment.