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:
Denis Makogon
2018-01-02 21:29:49 +02:00
committed by Reed Allman
parent cafc277325
commit 9d6f0b2a05
10 changed files with 785 additions and 773 deletions

View File

@@ -9,121 +9,118 @@ import (
"github.com/fnproject/fn_go/client/apps"
)
func TestApps(t *testing.T) {
t.Run("delete-app-not-found-test", func(t *testing.T) {
t.Parallel()
s := SetupDefaultSuite()
cfg := &apps.DeleteAppsAppParams{
App: "missing-app",
Context: s.Context,
}
cfg.WithTimeout(time.Second * 60)
_, err := s.Client.Apps.DeleteAppsApp(cfg)
if err == nil {
t.Errorf("Error during app delete: we should get HTTP 404, but got: %s", err.Error())
}
})
t.Run("app-not-found-test", func(t *testing.T) {
t.Parallel()
s := SetupDefaultSuite()
cfg := &apps.GetAppsAppParams{
App: "missing-app",
Context: s.Context,
}
cfg.WithTimeout(time.Second * 60)
_, err := s.Client.Apps.GetAppsApp(cfg)
CheckAppResponseError(t, err)
})
t.Run("create-app-and-delete-no-config-test", func(t *testing.T) {
t.Parallel()
s := SetupDefaultSuite()
CreateApp(t, s.Context, s.Client, s.AppName, map[string]string{})
DeleteApp(t, s.Context, s.Client, s.AppName)
})
t.Run("create-app-with-config-test", func(t *testing.T) {
t.Parallel()
s := SetupDefaultSuite()
CreateApp(t, s.Context, s.Client, s.AppName, map[string]string{"A": "a"})
DeleteApp(t, s.Context, s.Client, s.AppName)
})
t.Run("inspect-app-with-config-test", func(t *testing.T) {
t.Parallel()
s := SetupDefaultSuite()
CreateApp(t, s.Context, s.Client, s.AppName, map[string]string{"A": "a"})
app := GetApp(t, s.Context, s.Client, s.AppName)
val, ok := app.Config["A"]
if !ok {
t.Error("Error during app config inspect: config map misses required entity `A` with value `a`.")
}
if !strings.Contains("a", val) {
t.Errorf("App config value is different. Expected: `a`. Actual %v", val)
}
DeleteApp(t, s.Context, s.Client, s.AppName)
})
t.Run("patch-app-with-exact-same-config-data", func(t *testing.T) {
t.Parallel()
s := SetupDefaultSuite()
config := map[string]string{
"A": "a",
}
appUpdatePayload := CreateUpdateApp(t, s.Context, s.Client, s.AppName, config)
_, ok := appUpdatePayload.Payload.App.Config["A"]
if !ok {
t.Error("Error during app update: config map misses required entity `A` with value `a`.")
}
DeleteApp(t, s.Context, s.Client, s.AppName)
})
t.Run("patch-override-app-config", func(t *testing.T) {
t.Parallel()
s := SetupDefaultSuite()
config := map[string]string{
"A": "b",
}
appPayload := CreateUpdateApp(t, s.Context, s.Client, s.AppName, config)
val, ok := appPayload.Payload.App.Config["A"]
if !ok {
t.Error("Error during app config inspect: config map misses required entity `A` with value `a`.")
}
if !strings.Contains("b", val) {
t.Errorf("App config value is different. Expected: `b`. Actual %v", val)
}
DeleteApp(t, s.Context, s.Client, s.AppName)
})
t.Run("patch-add-app-config", func(t *testing.T) {
t.Parallel()
s := SetupDefaultSuite()
config := map[string]string{
"B": "b",
}
appPayload := CreateUpdateApp(t, s.Context, s.Client, s.AppName, config)
val, ok := appPayload.Payload.App.Config["B"]
if !ok {
t.Error("Error during app config inspect: config map misses required entity `B` with value `b`.")
}
if !strings.Contains("b", val) {
t.Errorf("App config value is different. Expected: `b`. Actual %v", val)
}
DeleteApp(t, s.Context, s.Client, s.AppName)
})
t.Run("crete-app-duplicate", func(t *testing.T) {
t.Parallel()
s := SetupDefaultSuite()
CreateApp(t, s.Context, s.Client, s.AppName, map[string]string{})
_, err := CreateAppNoAssert(s.Context, s.Client, s.AppName, map[string]string{})
if reflect.TypeOf(err) != reflect.TypeOf(apps.NewPostAppsConflict()) {
CheckAppResponseError(t, err)
}
DeleteApp(t, s.Context, s.Client, s.AppName)
})
func TestAppDeleteNotFound(t *testing.T) {
t.Parallel()
s := SetupDefaultSuite()
cfg := &apps.DeleteAppsAppParams{
App: "missing-app",
Context: s.Context,
}
cfg.WithTimeout(time.Second * 60)
_, err := s.Client.Apps.DeleteAppsApp(cfg)
if err == nil {
t.Errorf("Error during app delete: we should get HTTP 404, but got: %s", err.Error())
}
}
func TestAppGetNotFound(t *testing.T) {
t.Parallel()
s := SetupDefaultSuite()
cfg := &apps.GetAppsAppParams{
App: "missing-app",
Context: s.Context,
}
cfg.WithTimeout(time.Second * 60)
_, err := s.Client.Apps.GetAppsApp(cfg)
CheckAppResponseError(t, err)
}
func TestAppCreateNoConfigSuccess(t *testing.T) {
t.Parallel()
s := SetupDefaultSuite()
CreateApp(t, s.Context, s.Client, s.AppName, map[string]string{})
DeleteApp(t, s.Context, s.Client, s.AppName)
}
func TestAppCreateWithConfigSuccess(t *testing.T) {
t.Parallel()
s := SetupDefaultSuite()
CreateApp(t, s.Context, s.Client, s.AppName, map[string]string{"A": "a"})
DeleteApp(t, s.Context, s.Client, s.AppName)
}
func TestAppInsect(t *testing.T) {
t.Parallel()
s := SetupDefaultSuite()
CreateApp(t, s.Context, s.Client, s.AppName, map[string]string{"A": "a"})
app := GetApp(t, s.Context, s.Client, s.AppName)
val, ok := app.Config["A"]
if !ok {
t.Error("Error during app config inspect: config map misses required entity `A` with value `a`.")
}
if !strings.Contains("a", val) {
t.Errorf("App config value is different. Expected: `a`. Actual %v", val)
}
DeleteApp(t, s.Context, s.Client, s.AppName)
}
func TestAppPatchSameConfig(t *testing.T) {
t.Parallel()
s := SetupDefaultSuite()
config := map[string]string{
"A": "a",
}
appUpdatePayload := CreateUpdateApp(t, s.Context, s.Client, s.AppName, config)
_, ok := appUpdatePayload.Payload.App.Config["A"]
if !ok {
t.Error("Error during app update: config map misses required entity `A` with value `a`.")
}
DeleteApp(t, s.Context, s.Client, s.AppName)
}
func TestAppPatchOverwriteConfig(t *testing.T) {
t.Parallel()
s := SetupDefaultSuite()
config := map[string]string{
"A": "b",
}
appPayload := CreateUpdateApp(t, s.Context, s.Client, s.AppName, config)
val, ok := appPayload.Payload.App.Config["A"]
if !ok {
t.Error("Error during app config inspect: config map misses required entity `A` with value `a`.")
}
if !strings.Contains("b", val) {
t.Errorf("App config value is different. Expected: `b`. Actual %v", val)
}
DeleteApp(t, s.Context, s.Client, s.AppName)
}
func TestAppsPatchConfigAddValue(t *testing.T) {
t.Parallel()
s := SetupDefaultSuite()
config := map[string]string{
"B": "b",
}
appPayload := CreateUpdateApp(t, s.Context, s.Client, s.AppName, config)
val, ok := appPayload.Payload.App.Config["B"]
if !ok {
t.Error("Error during app config inspect: config map misses required entity `B` with value `b`.")
}
if !strings.Contains("b", val) {
t.Errorf("App config value is different. Expected: `b`. Actual %v", val)
}
DeleteApp(t, s.Context, s.Client, s.AppName)
}
func TestAppDuplicate(t *testing.T) {
t.Parallel()
s := SetupDefaultSuite()
CreateApp(t, s.Context, s.Client, s.AppName, map[string]string{})
_, err := CreateAppNoAssert(s.Context, s.Client, s.AppName, map[string]string{})
if reflect.TypeOf(err) != reflect.TypeOf(apps.NewPostAppsConflict()) {
CheckAppResponseError(t, err)
}
DeleteApp(t, s.Context, s.Client, s.AppName)
}