Skip to content

Commit

Permalink
WIP: Flush channels test
Browse files Browse the repository at this point in the history
  • Loading branch information
gbjk committed Feb 17, 2024
1 parent 09a26f3 commit 062ea61
Showing 1 changed file with 15 additions and 23 deletions.
38 changes: 15 additions & 23 deletions exchanges/stream/websocket_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"encoding/json"
"errors"
"fmt"
"io"
"net"
"net/http"
"sort"
Expand Down Expand Up @@ -1114,25 +1115,22 @@ func TestFlushChannels(t *testing.T) {

dodgyWs := Websocket{}
err := dodgyWs.FlushChannels()
if err == nil {
t.Fatal("error cannot be nil")
}
assert.ErrorIs(t, err, io.EOF, "FlushChannels should error correctly")

dodgyWs.setEnabled(true)
err = dodgyWs.FlushChannels()
if err == nil {
t.Fatal("error cannot be nil")
}
assert.ErrorIs(t, err, io.EOF, "FlushChannels should error correctly")

web := Websocket{
enabled: true,
connected: true,
connector: connect,
ShutdownC: make(chan struct{}),
Subscriber: newgen.SUBME,
Unsubscriber: newgen.UNSUBME,
Wg: new(sync.WaitGroup),
features: &protocol.Features{
enabled: true,
connected: true,
connector: connect,
subscriptions: subscriptions.NewStore(),
ShutdownC: make(chan struct{}),
Subscriber: newgen.SUBME,
Unsubscriber: newgen.UNSUBME,
Wg: new(sync.WaitGroup),
features: &protocol.Features{
// No features
},
trafficTimeout: time.Second * 30, // Added for when we utilise connect()
Expand All @@ -1155,22 +1153,16 @@ func TestFlushChannels(t *testing.T) {
return subscription.List{{Channel: "test"}}, nil
}
err = web.FlushChannels()
if err != nil {
t.Fatal(err)
}
require.NoError(t, err, "Flush Channels must not error")

web.features.FullPayloadSubscribe = true
web.GenerateSubs = problemFunc
err = web.FlushChannels() // error on full subscribeToChannels
if err == nil {
t.Fatal("error cannot be nil")
}
assert.ErrorIs(t, err, io.EOF, "Flush Channels should error correctly")

web.GenerateSubs = noSub
err = web.FlushChannels() // No subs to sub
if err != nil {
t.Fatal(err)
}
assert.NoError(t, err, "Flush Channels should not error")

web.GenerateSubs = newgen.generateSubs
subs, err := web.GenerateSubs()
Expand Down

0 comments on commit 062ea61

Please sign in to comment.