Skip to content

Commit

Permalink
Bitfinex: Test parallelChanOp
Browse files Browse the repository at this point in the history
  • Loading branch information
gbjk committed Oct 21, 2023
1 parent d10684d commit 20400f7
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions exchanges/bitfinex/bitfinex_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1871,6 +1871,7 @@ func TestCancelMultipleOrdersV2(t *testing.T) {
}
}

// TestGetErrResp unit tests the helper func getErrResp
func TestGetErrResp(t *testing.T) {
t.Parallel()
fixture, err := os.Open("testdata/getErrResp.json")
Expand Down Expand Up @@ -1903,6 +1904,42 @@ func TestGetErrResp(t *testing.T) {
assert.NoError(t, fixture.Close(), "Closing the fixture file should not error")
}

// TestParallelChanOp unit tests the helper func parallelChanOp
func TestParallelChanOp(t *testing.T) {
t.Parallel()
c := []stream.ChannelSubscription{
{Channel: "red"},
{Channel: "blue"},
{Channel: "violent"},
{Channel: "spin"},
{Channel: "charm"},
}
var testErr error
run := make(chan struct{}, 5)
go func() {
testErr = b.parallelChanOp(c, func(c *stream.ChannelSubscription) error {
time.Sleep(300 * time.Millisecond)
run <- struct{}{}
switch c.Channel {
case "spin", "violent":
return errors.New(c.Channel)
}
return nil
})
close(run)
}()
f := func(c *assert.CollectT) {
assert.ErrorContains(c, testErr, "violent", "Should get a violent error")
assert.ErrorContains(c, testErr, "spin", "Should get a spin error")
}
assert.EventuallyWithT(t, f, 500*time.Millisecond, 50*time.Millisecond, "ParallelChanOp should complete within 500ms not 5*300ms")
got := 0
for range run {
got++
}
assert.Equal(t, got, 5, "Every channel was run to completion")
}

// setupWs is a helper function to connect both auth and normal websockets
// It will skip the test if websockets are not enabled
// It's up to the test to skip if it requires creds, though
Expand Down

0 comments on commit 20400f7

Please sign in to comment.