Files
gocryptotrader/engine/communication_manager_test.go
Scott 63257ce4ca Improvement: Speeding up slow tests (#707)
* Speeds up tests

* Reduces time.Sleeps, lowers CreateTestBot complexity. Breaks things

* Removal of unecessary config reads. Parallel tests. Lower times

* Speeds up recent trades results

* mini update

* zoooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooom

* Removes the dupes

* Lint

* post cherrypick

* Fix rare kraken data race

* Fixes banking global issues. Fixes postgres trades

* rmline for appveyor test

* Expands timeout in event that channel is closed before send

* Fix data race

* No rows, no bows and definitely no shows

* Removes parallel from createsnapshot tests

* Extends timedmutext test a smidge. Exchange fatality

* Shorter end timeframe and bigger candle
2021-07-07 12:42:03 +10:00

157 lines
3.6 KiB
Go

package engine
import (
"errors"
"testing"
"github.com/thrasher-corp/gocryptotrader/communications"
"github.com/thrasher-corp/gocryptotrader/communications/base"
)
func TestSetup(t *testing.T) {
t.Parallel()
_, err := SetupCommunicationManager(nil)
if !errors.Is(err, errNilConfig) {
t.Errorf("error '%v', expected '%v'", err, errNilConfig)
}
_, err = SetupCommunicationManager(&base.CommunicationsConfig{})
if !errors.Is(err, communications.ErrNoCommunicationRelayersEnabled) {
t.Errorf("error '%v', expected '%v'", err, communications.ErrNoCommunicationRelayersEnabled)
}
m, err := SetupCommunicationManager(&base.CommunicationsConfig{
SlackConfig: base.SlackConfig{
Enabled: true,
},
})
if !errors.Is(err, nil) {
t.Errorf("error '%v', expected '%v'", err, nil)
}
if m == nil {
t.Error("expected manager")
}
}
func TestIsRunning(t *testing.T) {
t.Parallel()
m, err := SetupCommunicationManager(&base.CommunicationsConfig{
SMSGlobalConfig: base.SMSGlobalConfig{
Enabled: true,
},
})
if !errors.Is(err, nil) {
t.Errorf("error '%v', expected '%v'", err, nil)
}
err = m.Start()
if !errors.Is(err, nil) {
t.Errorf("error '%v', expected '%v'", err, nil)
}
if !m.IsRunning() {
t.Error("expected true")
}
m.started = 0
if m.IsRunning() {
t.Error("expected false")
}
m = nil
if m.IsRunning() {
t.Error("expected false")
}
}
func TestStart(t *testing.T) {
t.Parallel()
m, err := SetupCommunicationManager(&base.CommunicationsConfig{
SMTPConfig: base.SMTPConfig{
Enabled: true,
},
})
if !errors.Is(err, nil) {
t.Errorf("error '%v', expected '%v'", err, nil)
}
err = m.Start()
if !errors.Is(err, nil) {
t.Errorf("error '%v', expected '%v'", err, nil)
}
m.started = 1
err = m.Start()
if !errors.Is(err, ErrSubSystemAlreadyStarted) {
t.Errorf("error '%v', expected '%v'", err, ErrSubSystemAlreadyStarted)
}
}
func TestGetStatus(t *testing.T) {
t.Parallel()
m, err := SetupCommunicationManager(&base.CommunicationsConfig{
TelegramConfig: base.TelegramConfig{
Enabled: true,
},
})
if !errors.Is(err, nil) {
t.Errorf("error '%v', expected '%v'", err, nil)
}
err = m.Start()
if !errors.Is(err, nil) {
t.Errorf("error '%v', expected '%v'", err, nil)
}
_, err = m.GetStatus()
if !errors.Is(err, nil) {
t.Errorf("error '%v', expected '%v'", err, nil)
}
m.started = 0
_, err = m.GetStatus()
if !errors.Is(err, ErrSubSystemNotStarted) {
t.Errorf("error '%v', expected '%v'", err, ErrSubSystemNotStarted)
}
}
func TestStop(t *testing.T) {
t.Parallel()
m, err := SetupCommunicationManager(&base.CommunicationsConfig{
SlackConfig: base.SlackConfig{
Enabled: true,
},
})
if !errors.Is(err, nil) {
t.Errorf("error '%v', expected '%v'", err, nil)
}
err = m.Start()
if !errors.Is(err, nil) {
t.Errorf("error '%v', expected '%v'", err, nil)
}
err = m.Stop()
if !errors.Is(err, nil) {
t.Errorf("error '%v', expected '%v'", err, nil)
}
err = m.Stop()
if !errors.Is(err, ErrSubSystemNotStarted) {
t.Errorf("error '%v', expected '%v'", err, ErrSubSystemNotStarted)
}
m = nil
err = m.Stop()
if !errors.Is(err, ErrNilSubsystem) {
t.Errorf("error '%v', expected '%v'", err, ErrNilSubsystem)
}
}
func TestPushEvent(t *testing.T) {
t.Parallel()
m, err := SetupCommunicationManager(&base.CommunicationsConfig{
SlackConfig: base.SlackConfig{
Enabled: true,
},
})
if !errors.Is(err, nil) {
t.Errorf("error '%v', expected '%v'", err, nil)
}
err = m.Start()
if !errors.Is(err, nil) {
t.Errorf("error '%v', expected '%v'", err, nil)
}
m.PushEvent(base.Event{})
m.PushEvent(base.Event{})
m = nil
m.PushEvent(base.Event{})
}