mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-05-13 23:16:45 +00:00
stream: force subscription store check as stop gap for wrapper side implementation (#1717)
* Add check for subscription store insertion and validation with tests * bybit: fix subscriptions * deribit: fix subscriptions * linter: fix * glorious/nits: add test for updateChannelSubscriptions RM GetChannelDifference method as its only used locally and Diff method can be accessed directly * glorious/nits: add to store in the loop; add correct formatting to template for edge case perps with settlement * spelling: fix * glorious/nit: silly billy * gk: nits * gk/nits: split PartitionByPresence into Contained and Missing * gk/nits: formatPerpetualPairWithSettlement -> formatChannelPair * stream/websocket: stop full websocket disconnect on Connect when encountering subscription specific error paths * stream/websocket: rm nil assignment * glorious: nits * gk: niterinos * Update exchanges/stream/websocket_test.go Co-authored-by: Adrian Gallagher <adrian.gallagher@thrasher.io> * Update exchanges/stream/websocket_test.go Co-authored-by: Adrian Gallagher <adrian.gallagher@thrasher.io> * Update exchanges/stream/websocket_test.go Co-authored-by: Adrian Gallagher <adrian.gallagher@thrasher.io> * thrasher: nits --------- Co-authored-by: shazbert <ryan.oharareid@thrasher.io> Co-authored-by: Adrian Gallagher <adrian.gallagher@thrasher.io>
This commit is contained in:
@@ -206,3 +206,33 @@ func (s *Store) Len() int {
|
||||
defer s.mu.RUnlock()
|
||||
return len(s.m)
|
||||
}
|
||||
|
||||
// Contained returns a list of subscriptions in `compare` that are already in the store.
|
||||
func (s *Store) Contained(compare List) (matched List) {
|
||||
if s == nil || s.m == nil {
|
||||
return nil
|
||||
}
|
||||
s.mu.RLock()
|
||||
defer s.mu.RUnlock()
|
||||
for _, sub := range compare {
|
||||
if found := s.get(sub); found != nil {
|
||||
matched = append(matched, found)
|
||||
}
|
||||
}
|
||||
return matched
|
||||
}
|
||||
|
||||
// Missing returns a list of subscriptions in `compare` that are not in the store.
|
||||
func (s *Store) Missing(compare List) (missing List) {
|
||||
if s == nil || s.m == nil {
|
||||
return compare // All are missing
|
||||
}
|
||||
s.mu.RLock()
|
||||
defer s.mu.RUnlock()
|
||||
for _, sub := range compare {
|
||||
if found := s.get(sub); found == nil {
|
||||
missing = append(missing, sub)
|
||||
}
|
||||
}
|
||||
return missing
|
||||
}
|
||||
|
||||
@@ -204,3 +204,56 @@ func EqualLists(tb testing.TB, a, b List) {
|
||||
assert.Fail(tb, fail, "Subscriptions should be equal")
|
||||
}
|
||||
}
|
||||
|
||||
func TestContained(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
var s *Store
|
||||
matched := s.Contained(nil)
|
||||
assert.Nil(t, matched)
|
||||
|
||||
matched = s.Contained(List{{Channel: TickerChannel}})
|
||||
assert.Nil(t, matched)
|
||||
|
||||
s = NewStore()
|
||||
matched = s.Contained(nil)
|
||||
assert.Nil(t, matched)
|
||||
|
||||
matched = s.Contained(List{})
|
||||
assert.Nil(t, matched)
|
||||
|
||||
matched = s.Contained(List{{Channel: TickerChannel}})
|
||||
assert.Nil(t, matched)
|
||||
|
||||
require.NoError(t, s.add(&Subscription{Channel: TickerChannel}))
|
||||
|
||||
matched = s.Contained(List{{Channel: TickerChannel}})
|
||||
assert.Len(t, matched, 1)
|
||||
}
|
||||
|
||||
func TestMissing(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
var s *Store
|
||||
|
||||
unmatched := s.Missing(nil)
|
||||
assert.Nil(t, unmatched)
|
||||
|
||||
unmatched = s.Missing(List{{Channel: TickerChannel}})
|
||||
assert.Len(t, unmatched, 1)
|
||||
|
||||
s = NewStore()
|
||||
unmatched = s.Missing(nil)
|
||||
assert.Nil(t, unmatched)
|
||||
|
||||
unmatched = s.Missing(List{})
|
||||
assert.Nil(t, unmatched)
|
||||
|
||||
unmatched = s.Missing(List{{Channel: TickerChannel}})
|
||||
assert.Len(t, unmatched, 1)
|
||||
|
||||
require.NoError(t, s.add(&Subscription{Channel: TickerChannel}))
|
||||
|
||||
unmatched = s.Missing(List{{Channel: TickerChannel}})
|
||||
assert.Nil(t, unmatched)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user