mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-05-31 23:16:54 +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:
@@ -34,12 +34,12 @@ var g Gemini
|
||||
|
||||
func TestStart(t *testing.T) {
|
||||
t.Parallel()
|
||||
err := g.Start(nil)
|
||||
err := g.Start(context.Background(), nil)
|
||||
if !errors.Is(err, common.ErrNilPointer) {
|
||||
t.Fatalf("received: '%v' but expected: '%v'", err, common.ErrNilPointer)
|
||||
}
|
||||
var testWg sync.WaitGroup
|
||||
err = g.Start(&testWg)
|
||||
err = g.Start(context.Background(), &testWg)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
@@ -30,7 +30,7 @@ import (
|
||||
)
|
||||
|
||||
// GetDefaultConfig returns a default exchange config
|
||||
func (g *Gemini) GetDefaultConfig() (*config.Exchange, error) {
|
||||
func (g *Gemini) GetDefaultConfig(ctx context.Context) (*config.Exchange, error) {
|
||||
g.SetDefaults()
|
||||
exchCfg := new(config.Exchange)
|
||||
exchCfg.Name = g.Name
|
||||
@@ -43,7 +43,7 @@ func (g *Gemini) GetDefaultConfig() (*config.Exchange, error) {
|
||||
}
|
||||
|
||||
if g.Features.Supports.RESTCapabilities.AutoPairUpdates {
|
||||
err := g.UpdateTradablePairs(context.TODO(), true)
|
||||
err := g.UpdateTradablePairs(ctx, true)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -192,20 +192,20 @@ func (g *Gemini) Setup(exch *config.Exchange) error {
|
||||
}
|
||||
|
||||
// Start starts the Gemini go routine
|
||||
func (g *Gemini) Start(wg *sync.WaitGroup) error {
|
||||
func (g *Gemini) Start(ctx context.Context, wg *sync.WaitGroup) error {
|
||||
if wg == nil {
|
||||
return fmt.Errorf("%T %w", wg, common.ErrNilPointer)
|
||||
}
|
||||
wg.Add(1)
|
||||
go func() {
|
||||
g.Run()
|
||||
g.Run(ctx)
|
||||
wg.Done()
|
||||
}()
|
||||
return nil
|
||||
}
|
||||
|
||||
// Run implements the Gemini wrapper
|
||||
func (g *Gemini) Run() {
|
||||
func (g *Gemini) Run(ctx context.Context) {
|
||||
if g.Verbose {
|
||||
g.PrintEnabledPairs()
|
||||
}
|
||||
@@ -263,7 +263,7 @@ func (g *Gemini) Run() {
|
||||
if !g.GetEnabledFeatures().AutoPairUpdates && !forceUpdate {
|
||||
return
|
||||
}
|
||||
err := g.UpdateTradablePairs(context.TODO(), forceUpdate)
|
||||
err := g.UpdateTradablePairs(ctx, forceUpdate)
|
||||
if err != nil {
|
||||
log.Errorf(log.ExchangeSys,
|
||||
"%s failed to update tradable pairs. Err: %s",
|
||||
|
||||
Reference in New Issue
Block a user