mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-06-02 07:26:53 +00:00
cmd/wrapper_coverage: prevent non-needed REST requests via context timeout (#1154)
* wrapper_coverage/exchanges: cancel context to not send rest requests/ populate context through functions that do rest requests * linter: fix * exchange_template: fix test --------- Co-authored-by: Ryan O'Hara-Reid <ryan.oharareid@thrasher.io>
This commit is contained in:
@@ -61,12 +61,12 @@ func TestMain(m *testing.M) {
|
||||
log.Fatal("Binanceus TestMain()", err)
|
||||
}
|
||||
bi.setupOrderbookManager()
|
||||
err = bi.Start(nil)
|
||||
err = bi.Start(context.Background(), nil)
|
||||
if !errors.Is(err, common.ErrNilPointer) {
|
||||
log.Fatalf("%s received: '%v' but expected: '%v'", bi.Name, err, common.ErrNilPointer)
|
||||
}
|
||||
var testWg sync.WaitGroup
|
||||
err = bi.Start(&testWg)
|
||||
err = bi.Start(context.Background(), &testWg)
|
||||
if err != nil {
|
||||
log.Fatal("Binanceus Starting error ", err)
|
||||
}
|
||||
|
||||
@@ -31,7 +31,7 @@ import (
|
||||
)
|
||||
|
||||
// GetDefaultConfig returns a default exchange config
|
||||
func (bi *Binanceus) GetDefaultConfig() (*config.Exchange, error) {
|
||||
func (bi *Binanceus) GetDefaultConfig(ctx context.Context) (*config.Exchange, error) {
|
||||
bi.SetDefaults()
|
||||
exchCfg := new(config.Exchange)
|
||||
exchCfg.Name = bi.Name
|
||||
@@ -44,7 +44,7 @@ func (bi *Binanceus) GetDefaultConfig() (*config.Exchange, error) {
|
||||
}
|
||||
|
||||
if bi.Features.Supports.RESTCapabilities.AutoPairUpdates {
|
||||
err := bi.UpdateTradablePairs(context.TODO(), true)
|
||||
err := bi.UpdateTradablePairs(ctx, true)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -216,20 +216,20 @@ func (bi *Binanceus) Setup(exch *config.Exchange) error {
|
||||
}
|
||||
|
||||
// Start starts the Binanceus go routine
|
||||
func (bi *Binanceus) Start(wg *sync.WaitGroup) error {
|
||||
func (bi *Binanceus) Start(ctx context.Context, wg *sync.WaitGroup) error {
|
||||
if wg == nil {
|
||||
return fmt.Errorf("%T %w", wg, common.ErrNilPointer)
|
||||
}
|
||||
wg.Add(1)
|
||||
go func() {
|
||||
bi.Run()
|
||||
bi.Run(ctx)
|
||||
wg.Done()
|
||||
}()
|
||||
return nil
|
||||
}
|
||||
|
||||
// Run implements the Binanceus wrapper
|
||||
func (bi *Binanceus) Run() {
|
||||
func (bi *Binanceus) Run(ctx context.Context) {
|
||||
if bi.Verbose {
|
||||
log.Debugf(log.ExchangeSys,
|
||||
"%s Websocket: %s.",
|
||||
@@ -242,7 +242,7 @@ func (bi *Binanceus) Run() {
|
||||
return
|
||||
}
|
||||
|
||||
err := bi.UpdateTradablePairs(context.TODO(), false)
|
||||
err := bi.UpdateTradablePairs(ctx, false)
|
||||
if err != nil {
|
||||
log.Errorf(log.ExchangeSys,
|
||||
"%s failed to update tradable pairs. Err: %s",
|
||||
|
||||
Reference in New Issue
Block a user