mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-05-31 15:10:42 +00:00
engine: Adds shutdown method to exchange manager and unload all exchanges when engine is stopped (#1112)
* engine: shutdown and unload exchange when engine is stopped * linter: fixes * engine/exchMan: add nil check * engine/exchanges: add shutdown method to exchanges, rm len check lock not needed, expanded code coverage, address some nits * exchMan: report all failed shutdowns across exchanges, implement timer and monitoring routines. * exchMan: improve shutdown sequence and aloc. * further improvement * exchman: log from warn to error * websockconnection: Suppress error return when closure is caused by library * linter: fix * fix racies * add note on why not parallel tests * glorious: nits * spelling kween * thrasher: nits * engine: change print of setting using reflection, I keep forgetting to implement this so program around forgetfulness * engine/exchange_management: remove wait group and just rely on intermediary lock * glorious: nits * Update common/common.go Co-authored-by: Adrian Gallagher <adrian.gallagher@thrasher.io> * Update main.go Co-authored-by: Adrian Gallagher <adrian.gallagher@thrasher.io> --------- Co-authored-by: Ryan O'Hara-Reid <ryan.oharareid@thrasher.io> Co-authored-by: Adrian Gallagher <adrian.gallagher@thrasher.io>
This commit is contained in:
@@ -32,7 +32,7 @@ func TestLoadConfigWithSettings(t *testing.T) {
|
||||
name: "test file",
|
||||
settings: &Settings{
|
||||
ConfigFile: config.TestFile,
|
||||
EnableDryRun: true,
|
||||
CoreSettings: CoreSettings{EnableDryRun: true},
|
||||
},
|
||||
want: &empty,
|
||||
wantErr: false,
|
||||
@@ -43,7 +43,7 @@ func TestLoadConfigWithSettings(t *testing.T) {
|
||||
settings: &Settings{
|
||||
ConfigFile: config.TestFile,
|
||||
DataDir: somePath,
|
||||
EnableDryRun: true,
|
||||
CoreSettings: CoreSettings{EnableDryRun: true},
|
||||
},
|
||||
want: &somePath,
|
||||
wantErr: false,
|
||||
@@ -79,7 +79,7 @@ func TestStartStopDoesNotCausePanic(t *testing.T) {
|
||||
tempDir := t.TempDir()
|
||||
botOne, err := NewFromSettings(&Settings{
|
||||
ConfigFile: config.TestFile,
|
||||
EnableDryRun: true,
|
||||
CoreSettings: CoreSettings{EnableDryRun: true},
|
||||
DataDir: tempDir,
|
||||
}, nil)
|
||||
if err != nil {
|
||||
@@ -110,7 +110,7 @@ func TestStartStopTwoDoesNotCausePanic(t *testing.T) {
|
||||
tempDir2 := t.TempDir()
|
||||
botOne, err := NewFromSettings(&Settings{
|
||||
ConfigFile: config.TestFile,
|
||||
EnableDryRun: true,
|
||||
CoreSettings: CoreSettings{EnableDryRun: true},
|
||||
DataDir: tempDir,
|
||||
}, nil)
|
||||
if err != nil {
|
||||
@@ -120,7 +120,7 @@ func TestStartStopTwoDoesNotCausePanic(t *testing.T) {
|
||||
|
||||
botTwo, err := NewFromSettings(&Settings{
|
||||
ConfigFile: config.TestFile,
|
||||
EnableDryRun: true,
|
||||
CoreSettings: CoreSettings{EnableDryRun: true},
|
||||
DataDir: tempDir2,
|
||||
}, nil)
|
||||
if err != nil {
|
||||
@@ -146,14 +146,17 @@ func TestGetExchangeByName(t *testing.T) {
|
||||
t.Errorf("received: %v expected: %v", err, ErrNilSubsystem)
|
||||
}
|
||||
|
||||
em := SetupExchangeManager()
|
||||
em := NewExchangeManager()
|
||||
exch, err := em.NewExchangeByName(testExchange)
|
||||
if !errors.Is(err, nil) {
|
||||
t.Fatalf("received '%v' expected '%v'", err, nil)
|
||||
}
|
||||
exch.SetDefaults()
|
||||
exch.SetEnabled(true)
|
||||
em.Add(exch)
|
||||
err = em.Add(exch)
|
||||
if !errors.Is(err, nil) {
|
||||
t.Fatalf("received: '%v' but expected: '%v'", err, nil)
|
||||
}
|
||||
e := &Engine{ExchangeManager: em}
|
||||
|
||||
if !exch.IsEnabled() {
|
||||
@@ -180,14 +183,17 @@ func TestGetExchangeByName(t *testing.T) {
|
||||
|
||||
func TestUnloadExchange(t *testing.T) {
|
||||
t.Parallel()
|
||||
em := SetupExchangeManager()
|
||||
em := NewExchangeManager()
|
||||
exch, err := em.NewExchangeByName(testExchange)
|
||||
if !errors.Is(err, nil) {
|
||||
t.Fatalf("received '%v' expected '%v'", err, nil)
|
||||
}
|
||||
exch.SetDefaults()
|
||||
exch.SetEnabled(true)
|
||||
em.Add(exch)
|
||||
err = em.Add(exch)
|
||||
if !errors.Is(err, nil) {
|
||||
t.Fatalf("received: '%v' but expected: '%v'", err, nil)
|
||||
}
|
||||
e := &Engine{ExchangeManager: em,
|
||||
Config: &config.Config{Exchanges: []config.Exchange{{Name: testExchange}}},
|
||||
}
|
||||
@@ -203,15 +209,15 @@ func TestUnloadExchange(t *testing.T) {
|
||||
}
|
||||
|
||||
err = e.UnloadExchange(testExchange)
|
||||
if !errors.Is(err, ErrNoExchangesLoaded) {
|
||||
t.Errorf("error '%v', expected '%v'", err, ErrNoExchangesLoaded)
|
||||
if !errors.Is(err, ErrExchangeNotFound) {
|
||||
t.Errorf("error '%v', expected '%v'", err, ErrExchangeNotFound)
|
||||
}
|
||||
}
|
||||
|
||||
func TestDryRunParamInteraction(t *testing.T) {
|
||||
t.Parallel()
|
||||
bot := &Engine{
|
||||
ExchangeManager: SetupExchangeManager(),
|
||||
ExchangeManager: NewExchangeManager(),
|
||||
Settings: Settings{},
|
||||
Config: &config.Config{
|
||||
Exchanges: []config.Exchange{
|
||||
@@ -323,3 +329,12 @@ func TestSetDefaultWebsocketDataHandler(t *testing.T) {
|
||||
t.Fatalf("received: '%v' but expected: '%v'", err, nil)
|
||||
}
|
||||
}
|
||||
|
||||
func TestSettingsPrint(t *testing.T) {
|
||||
t.Parallel()
|
||||
var s *Settings
|
||||
s.PrintLoadedSettings()
|
||||
|
||||
s = &Settings{}
|
||||
s.PrintLoadedSettings()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user