mirror of
https://github.com/fnproject/fn.git
synced 2022-10-28 21:29:17 +03:00
Speed up API tests (#624)
* Adjust API tests internal API * Refactor API tests to take less time - sqlite: tests 15s, overall time: 1m - mysql: tests 15s, overall time: 59s * Use retry func to survive in faulty places * Use retry func while trying to ping SQL datastore - implements retry func specifically for SQL datastore ping - fmt fixes - using sqlx.Db.PingContext instead of sqlx.Db.Ping - propogate context to SQL datastore * Simplify TestCanCauseTimeout retry loop * Call retry with sane timeout * Fix TestOversizedLog, use retry func * Increase number of attempts 2 test cases are really faulty in CI, so they need a lot more time to finish. * Increase TestCanCauseTimeout timeout * Use retry at TestMultiLog to speed it up * Use retry at TestCanWriteLogs to speed it up * Use retry at TestGetCallsSuccess to speed it up * Use retry at TestCanGetAsyncState to speed it up * Use retry at TestListCallsSuccess to speed it up * Remove sleep calls * Remove dup test case * Cleaup Calls API test * Build API tests binary once This patch lets CI to build API tests binary once and reuse that whenever it needs it * Swap API tests checks * Build API test binary by default dirty fix for CircleCI * Use retry func to determine if datastore is alive in tests * go install should also reduce build time * Fix rebase issues
This commit is contained in:
committed by
Reed Allman
parent
cafc277325
commit
9d6f0b2a05
@@ -12,6 +12,7 @@ import (
|
||||
"runtime"
|
||||
"strings"
|
||||
"sync"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/fnproject/fn/api/common"
|
||||
@@ -104,6 +105,8 @@ type SuiteSetup struct {
|
||||
RouteType string
|
||||
Format string
|
||||
Memory uint64
|
||||
Timeout int32
|
||||
IdleTimeout int32
|
||||
RouteConfig map[string]string
|
||||
RouteHeaders map[string][]string
|
||||
Cancel context.CancelFunc
|
||||
@@ -131,6 +134,8 @@ func SetupDefaultSuite() *SuiteSetup {
|
||||
RouteHeaders: map[string][]string{},
|
||||
Cancel: cancel,
|
||||
Memory: uint64(256),
|
||||
Timeout: int32(30),
|
||||
IdleTimeout: int32(30),
|
||||
}
|
||||
|
||||
if Host() != "localhost:8080" {
|
||||
@@ -224,3 +229,16 @@ func MyCaller() string {
|
||||
f, l := fun.FileLine(fpcs[0] - 1)
|
||||
return fmt.Sprintf("%s:%d", f, l)
|
||||
}
|
||||
|
||||
func APICallWithRetry(t *testing.T, attempts int, sleep time.Duration, callback func() error) (err error) {
|
||||
for i := 0; i < attempts; i++ {
|
||||
err = callback()
|
||||
if err == nil {
|
||||
t.Log("Exiting retry loop, API call was successful")
|
||||
return nil
|
||||
}
|
||||
time.Sleep(sleep)
|
||||
t.Logf("[%v] - Retryting API call after unsuccessful attemt with error: %v", i, err.Error())
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user