From ca71f2cdc4a73824ff0fb7b4632e7a6ea39f4e30 Mon Sep 17 00:00:00 2001 From: Alessandro Yuichi Okimoto Date: Thu, 13 Jun 2024 15:53:07 +0900 Subject: [PATCH] test: refactor e2e tests to use parallel (#133) Signed-off-by: Alessandro Yuichi Okimoto --- test/e2e/sdk_local_evaluation_test.go | 6 ++ test/e2e/sdk_test.go | 108 +++++++++++++------------- 2 files changed, 60 insertions(+), 54 deletions(-) diff --git a/test/e2e/sdk_local_evaluation_test.go b/test/e2e/sdk_local_evaluation_test.go index 6ef7575..541c390 100644 --- a/test/e2e/sdk_local_evaluation_test.go +++ b/test/e2e/sdk_local_evaluation_test.go @@ -12,6 +12,7 @@ import ( ) func TestLocalStringVariation(t *testing.T) { + t.Parallel() tests := []struct { desc string user *user.User @@ -58,6 +59,7 @@ func TestLocalStringVariation(t *testing.T) { } func TestLocalBoolVariation(t *testing.T) { + t.Parallel() tests := []struct { desc string user *user.User @@ -98,6 +100,7 @@ func TestLocalBoolVariation(t *testing.T) { } func TestLocalIntVariation(t *testing.T) { + t.Parallel() tests := []struct { desc string user *user.User @@ -138,6 +141,7 @@ func TestLocalIntVariation(t *testing.T) { } func TestLocalInt64Variation(t *testing.T) { + t.Parallel() tests := []struct { desc string user *user.User @@ -178,6 +182,7 @@ func TestLocalInt64Variation(t *testing.T) { } func TestLocalFloat64Variation(t *testing.T) { + t.Parallel() tests := []struct { desc string user *user.User @@ -218,6 +223,7 @@ func TestLocalFloat64Variation(t *testing.T) { } func TestLocalJSONVariation(t *testing.T) { + t.Parallel() type TestJson struct { Str string `json:"str"` Int string `json:"int"` diff --git a/test/e2e/sdk_test.go b/test/e2e/sdk_test.go index 9ddd989..8a88efd 100644 --- a/test/e2e/sdk_test.go +++ b/test/e2e/sdk_test.go @@ -39,17 +39,17 @@ func TestStringVariation(t *testing.T) { }, } + ctx, cancel := context.WithTimeout(context.Background(), timeout) + defer cancel() + sdk := newSDK(t, ctx) + defer func() { + // Close + err := sdk.Close(ctx) + assert.NoError(t, err) + }() + for _, tt := range tests { t.Run(tt.desc, func(t *testing.T) { - ctx, cancel := context.WithTimeout(context.Background(), timeout) - defer cancel() - sdk := newSDK(t, ctx) - defer func() { - // Close - err := sdk.Close(ctx) - assert.NoError(t, err) - }() - actual := sdk.StringVariation(ctx, tt.user, tt.featureID, "default") assert.Equal(t, tt.expected, actual, "userID: %s, featureID: %s", tt.user.ID, tt.featureID) }) @@ -79,17 +79,17 @@ func TestBoolVariation(t *testing.T) { }, } + ctx, cancel := context.WithTimeout(context.Background(), timeout) + defer cancel() + sdk := newSDK(t, ctx) + defer func() { + // Close + err := sdk.Close(ctx) + assert.NoError(t, err) + }() + for _, tt := range tests { t.Run(tt.desc, func(t *testing.T) { - ctx, cancel := context.WithTimeout(context.Background(), timeout) - defer cancel() - sdk := newSDK(t, ctx) - defer func() { - // Close - err := sdk.Close(ctx) - assert.NoError(t, err) - }() - actual := sdk.BoolVariation(ctx, tt.user, tt.featureID, false) assert.Equal(t, tt.expected, actual, "userID: %s, featureID: %s", tt.user.ID, tt.featureID) }) @@ -119,17 +119,17 @@ func TestIntVariation(t *testing.T) { }, } + ctx, cancel := context.WithTimeout(context.Background(), timeout) + defer cancel() + sdk := newSDK(t, ctx) + defer func() { + // Close + err := sdk.Close(ctx) + assert.NoError(t, err) + }() + for _, tt := range tests { t.Run(tt.desc, func(t *testing.T) { - ctx, cancel := context.WithTimeout(context.Background(), timeout) - defer cancel() - sdk := newSDK(t, ctx) - defer func() { - // Close - err := sdk.Close(ctx) - assert.NoError(t, err) - }() - actual := sdk.IntVariation(ctx, tt.user, tt.featureID, -1) assert.Equal(t, tt.expected, actual, "userID: %s, featureID: %s", tt.user.ID, tt.featureID) }) @@ -159,17 +159,17 @@ func TestInt64Variation(t *testing.T) { }, } + ctx, cancel := context.WithTimeout(context.Background(), timeout) + defer cancel() + sdk := newSDK(t, ctx) + defer func() { + // Close + err := sdk.Close(ctx) + assert.NoError(t, err) + }() + for _, tt := range tests { t.Run(tt.desc, func(t *testing.T) { - ctx, cancel := context.WithTimeout(context.Background(), timeout) - defer cancel() - sdk := newSDK(t, ctx) - defer func() { - // Close - err := sdk.Close(ctx) - assert.NoError(t, err) - }() - actual := sdk.Int64Variation(ctx, tt.user, tt.featureID, -1000000000) assert.Equal(t, tt.expected, actual, "userID: %s, featureID: %s", tt.user.ID, tt.featureID) }) @@ -199,17 +199,17 @@ func TestFloat64Variation(t *testing.T) { }, } + ctx, cancel := context.WithTimeout(context.Background(), timeout) + defer cancel() + sdk := newSDK(t, ctx) + defer func() { + // Close + err := sdk.Close(ctx) + assert.NoError(t, err) + }() + for _, tt := range tests { t.Run(tt.desc, func(t *testing.T) { - ctx, cancel := context.WithTimeout(context.Background(), timeout) - defer cancel() - sdk := newSDK(t, ctx) - defer func() { - // Close - err := sdk.Close(ctx) - assert.NoError(t, err) - }() - actual := sdk.Float64Variation(ctx, tt.user, tt.featureID, -1.1) assert.Equal(t, tt.expected, actual, "userID: %s, featureID: %s", tt.user.ID, tt.featureID) }) @@ -244,17 +244,17 @@ func TestJSONVariation(t *testing.T) { }, } + ctx, cancel := context.WithTimeout(context.Background(), timeout) + defer cancel() + sdk := newSDK(t, ctx) + defer func() { + // Close + err := sdk.Close(ctx) + assert.NoError(t, err) + }() + for _, tt := range tests { t.Run(tt.desc, func(t *testing.T) { - ctx, cancel := context.WithTimeout(context.Background(), timeout) - defer cancel() - sdk := newSDK(t, ctx) - defer func() { - // Close - err := sdk.Close(ctx) - assert.NoError(t, err) - }() - v := &TestJson{} sdk.JSONVariation(ctx, tt.user, tt.featureID, v) assert.Equal(t, tt.expected, v, "userID: %s, featureID: %s", tt.user.ID, tt.featureID)