mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-05-23 23:16:49 +00:00
exchange_wrapper_coverage: deploy context value, fix panics (#1119)
* exchange_wrapper_coverage: deploy context value, fix panics at the disco. * wrap_cov: skip ftx impl. protect racey result map, reset verbosity when random wrapper functions are called. * fixed ocd trigger sequence * triggernometry eased Co-authored-by: Ryan O'Hara-Reid <ryan.oharareid@thrasher.io>
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"log"
|
||||
@@ -30,6 +31,10 @@ func main() {
|
||||
log.Printf("Loading exchanges..")
|
||||
var wg sync.WaitGroup
|
||||
for x := range exchange.Exchanges {
|
||||
if exchange.Exchanges[x] == "ftx" {
|
||||
log.Println("Skipping exchange FTX...")
|
||||
continue
|
||||
}
|
||||
err = engine.Bot.LoadExchange(exchange.Exchanges[x], &wg)
|
||||
if err != nil {
|
||||
log.Printf("Failed to load exchange %s. Err: %s",
|
||||
@@ -43,18 +48,21 @@ func main() {
|
||||
|
||||
log.Printf("Testing exchange wrappers..")
|
||||
results := make(map[string][]string)
|
||||
wg = sync.WaitGroup{}
|
||||
var mtx sync.Mutex
|
||||
|
||||
exchanges := engine.Bot.GetExchanges()
|
||||
for x := range exchanges {
|
||||
exch := exchanges[x]
|
||||
wg.Add(1)
|
||||
go func(e exchange.IBotExchange) {
|
||||
results[e.GetName()], err = testWrappers(e)
|
||||
go func(exch exchange.IBotExchange) {
|
||||
strResults, err := testWrappers(exch)
|
||||
if err != nil {
|
||||
fmt.Printf("failed to test wrappers for %s %s", e.GetName(), err)
|
||||
log.Printf("Failed to test wrappers for %s. Err: %s", exch.GetName(), err)
|
||||
}
|
||||
mtx.Lock()
|
||||
results[exch.GetName()] = strResults
|
||||
mtx.Unlock()
|
||||
wg.Done()
|
||||
}(exch)
|
||||
}(exchanges[x])
|
||||
}
|
||||
wg.Wait()
|
||||
log.Println("Done.")
|
||||
@@ -88,17 +96,33 @@ func testWrappers(e exchange.IBotExchange) ([]string, error) {
|
||||
actualExchange := reflect.ValueOf(e)
|
||||
errType := reflect.TypeOf(common.ErrNotYetImplemented)
|
||||
|
||||
contextParam := reflect.TypeOf((*context.Context)(nil)).Elem()
|
||||
|
||||
var funcs []string
|
||||
for x := 0; x < iExchange.NumMethod(); x++ {
|
||||
name := iExchange.Method(x).Name
|
||||
method := actualExchange.MethodByName(name)
|
||||
inputs := make([]reflect.Value, method.Type().NumIn())
|
||||
|
||||
for y := 0; y < method.Type().NumIn(); y++ {
|
||||
input := method.Type().In(y)
|
||||
|
||||
if input.Implements(contextParam) {
|
||||
// Need to deploy a context.Context value as nil value is not
|
||||
// checked throughout codebase.
|
||||
inputs[y] = reflect.ValueOf(context.Background())
|
||||
continue
|
||||
}
|
||||
inputs[y] = reflect.Zero(input)
|
||||
}
|
||||
|
||||
outputs := method.Call(inputs)
|
||||
if method.Type().NumIn() == 0 {
|
||||
// Some empty functions will reset the exchange struct to defaults,
|
||||
// so turn off verbosity.
|
||||
e.GetBase().Verbose = false
|
||||
}
|
||||
|
||||
for y := range outputs {
|
||||
incoming := outputs[y].Interface()
|
||||
if reflect.TypeOf(incoming) == errType {
|
||||
|
||||
Reference in New Issue
Block a user