mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-05-13 15:09:42 +00:00
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
This commit is contained in:
@@ -13,7 +13,7 @@ func (i *Instance) SetConfig(cfg *Config) error {
|
||||
return ErrNilInstance
|
||||
}
|
||||
if cfg == nil {
|
||||
return errNilConfig
|
||||
return ErrNilConfig
|
||||
}
|
||||
i.m.Lock()
|
||||
i.config = cfg
|
||||
|
||||
@@ -20,8 +20,8 @@ func TestSetConfig(t *testing.T) {
|
||||
}
|
||||
|
||||
err = inst.SetConfig(nil)
|
||||
if !errors.Is(err, errNilConfig) {
|
||||
t.Errorf("received %v, expected %v", err, errNilConfig)
|
||||
if !errors.Is(err, ErrNilConfig) {
|
||||
t.Errorf("received %v, expected %v", err, ErrNilConfig)
|
||||
}
|
||||
|
||||
inst = nil
|
||||
|
||||
@@ -46,9 +46,10 @@ var (
|
||||
DefaultSQLiteDatabase = "gocryptotrader.db"
|
||||
// ErrNilInstance for when a database is nil
|
||||
ErrNilInstance = errors.New("database instance is nil")
|
||||
errNilConfig = errors.New("received nil config")
|
||||
errNilSQL = errors.New("database SQL connection is nil")
|
||||
errFailedPing = errors.New("unable to verify database is connected, failed ping")
|
||||
// ErrNilConfig for when a config is nil
|
||||
ErrNilConfig = errors.New("received nil config")
|
||||
errNilSQL = errors.New("database SQL connection is nil")
|
||||
errFailedPing = errors.New("unable to verify database is connected, failed ping")
|
||||
)
|
||||
|
||||
const (
|
||||
|
||||
@@ -11,6 +11,12 @@ import (
|
||||
|
||||
// Connect opens a connection to Postgres database and returns a pointer to database.DB
|
||||
func Connect(cfg *database.Config) (*database.Instance, error) {
|
||||
if cfg == nil {
|
||||
return nil, database.ErrNilConfig
|
||||
}
|
||||
if !cfg.Enabled {
|
||||
return nil, database.ErrDatabaseSupportDisabled
|
||||
}
|
||||
if cfg.SSLMode == "" {
|
||||
cfg.SSLMode = "disable"
|
||||
}
|
||||
|
||||
@@ -83,16 +83,13 @@ func TestAudit(t *testing.T) {
|
||||
if !testhelpers.CheckValidConfig(&test.config.ConnectionDetails) {
|
||||
t.Skip("database not configured skipping test")
|
||||
}
|
||||
|
||||
dbConn, err := testhelpers.ConnectToDatabase(test.config)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if test.runner != nil {
|
||||
test.runner(t)
|
||||
}
|
||||
|
||||
if test.closer != nil {
|
||||
err = test.closer(dbConn)
|
||||
if err != nil {
|
||||
|
||||
@@ -124,8 +124,8 @@ func TestDataHistoryJob(t *testing.T) {
|
||||
Asset: asset.Spot.String(),
|
||||
Base: currency.BTC.String(),
|
||||
Quote: currency.USD.String(),
|
||||
StartDate: time.Now().Add(time.Duration(i) * time.Second),
|
||||
EndDate: time.Now().Add(time.Minute * time.Duration(i)),
|
||||
StartDate: time.Now().Add(time.Duration(i+1) * time.Second).UTC(),
|
||||
EndDate: time.Now().Add(time.Minute * time.Duration(i+1)).UTC(),
|
||||
Interval: int64(i),
|
||||
})
|
||||
}
|
||||
@@ -144,8 +144,8 @@ func TestDataHistoryJob(t *testing.T) {
|
||||
Asset: asset.Spot.String(),
|
||||
Base: currency.BTC.String(),
|
||||
Quote: currency.USD.String(),
|
||||
StartDate: time.Now().Add(time.Duration(i) * time.Second),
|
||||
EndDate: time.Now().Add(time.Minute * time.Duration(i)),
|
||||
StartDate: time.Now().Add(time.Duration(i+1) * time.Second).UTC(),
|
||||
EndDate: time.Now().Add(time.Minute * time.Duration(i+1)).UTC(),
|
||||
Interval: int64(i),
|
||||
}
|
||||
if i == 19 {
|
||||
@@ -179,7 +179,7 @@ func TestDataHistoryJob(t *testing.T) {
|
||||
t.Errorf("expected 19, received %v", len(results))
|
||||
}
|
||||
|
||||
jerb, err := db.getJobAndAllResultsPostgres(jerberoos[0].Nickname)
|
||||
jerb, err := db.GetJobAndAllResults(jerberoos[0].Nickname)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
@@ -107,7 +107,7 @@ func verifyTradeInIntervalsSqlite(ctx context.Context, tx *sql.Tx, exchangeName,
|
||||
quote,
|
||||
irh.Ranges[i].Intervals[j].Start.Time.UTC().Format(time.RFC3339),
|
||||
irh.Ranges[i].Intervals[j].End.Time.UTC().Format(time.RFC3339))).One(ctx, tx)
|
||||
if err != nil {
|
||||
if err != nil && err != sql.ErrNoRows {
|
||||
return err
|
||||
}
|
||||
if result != nil {
|
||||
@@ -126,14 +126,14 @@ func verifyTradeInIntervalsPostgres(ctx context.Context, tx *sql.Tx, exchangeNam
|
||||
}
|
||||
for i := range irh.Ranges {
|
||||
for j := range irh.Ranges[i].Intervals {
|
||||
result, err := postgres.Trades(qm.Where("exchange_name_id = ? AND asset = ? AND base = ? AND quote = ? timestamp between ? AND ?",
|
||||
result, err := postgres.Trades(qm.Where("exchange_name_id = ? AND asset = ? AND base = ? AND quote = ? AND timestamp between ? AND ?",
|
||||
exch.ID,
|
||||
assetType,
|
||||
base,
|
||||
quote,
|
||||
irh.Ranges[i].Intervals[j].Start.Time.UTC().Format(time.RFC3339),
|
||||
irh.Ranges[i].Intervals[j].End.Time.UTC().Format(time.RFC3339))).One(ctx, tx)
|
||||
if err != nil {
|
||||
irh.Ranges[i].Intervals[j].Start.Time.UTC(),
|
||||
irh.Ranges[i].Intervals[j].End.Time.UTC())).One(ctx, tx)
|
||||
if err != nil && err != sql.ErrNoRows {
|
||||
return err
|
||||
}
|
||||
if result != nil {
|
||||
|
||||
@@ -103,7 +103,7 @@ func tradeSQLTester(t *testing.T) {
|
||||
uu, _ := uuid.NewV4()
|
||||
trades = append(trades, Data{
|
||||
ID: uu.String(),
|
||||
Timestamp: firstTime.Add(time.Minute * time.Duration(i)),
|
||||
Timestamp: firstTime.Add(time.Minute * time.Duration(i+1)),
|
||||
Exchange: testExchanges[0].Name,
|
||||
Base: currency.BTC.String(),
|
||||
Quote: currency.USD.String(),
|
||||
@@ -123,7 +123,7 @@ func tradeSQLTester(t *testing.T) {
|
||||
uu, _ := uuid.NewV4()
|
||||
trades2 = append(trades2, Data{
|
||||
ID: uu.String(),
|
||||
Timestamp: firstTime.Add(time.Minute * time.Duration(i)),
|
||||
Timestamp: firstTime.Add(time.Minute * time.Duration(i+1)),
|
||||
Exchange: testExchanges[0].Name,
|
||||
Base: currency.BTC.String(),
|
||||
Quote: currency.USD.String(),
|
||||
@@ -171,7 +171,6 @@ func tradeSQLTester(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
err = VerifyTradeInIntervals(testExchanges[0].Name,
|
||||
asset.Spot.String(),
|
||||
currency.BTC.String(),
|
||||
@@ -181,15 +180,10 @@ func tradeSQLTester(t *testing.T) {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
if !ranges.HasDataAtDate(firstTime) {
|
||||
t.Error("expected data")
|
||||
}
|
||||
|
||||
err = DeleteTrades(trades...)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
err = DeleteTrades(trades2...)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
|
||||
Reference in New Issue
Block a user