Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions test/commands/deploy_cmd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,10 @@ func deployTestSpec(tc deployTestCase) infra.TestDefinition {
Only: tc.only,
Skip: tc.skip,
Test: func(it *infra.Test) {
suffix := infra.UniqueID()

for _, initialWorker := range tc.initWorkers {
initialWorker.Key = initialWorker.Key + "-" + suffix
it.CreateWorker(initialWorker)
it.Cleanup(func() {
it.DeleteWorker(initialWorker.Key)
Expand All @@ -102,7 +105,7 @@ func deployTestSpec(tc deployTestCase) infra.TestDefinition {

_, workerName := it.PrepareWorkerTestDir()
if tc.workerKey != "" {
workerName = tc.workerKey
workerName = tc.workerKey + "-" + suffix
}

workerAction := tc.workerAction
Expand Down Expand Up @@ -147,7 +150,7 @@ func deployTestSpec(tc deployTestCase) infra.TestDefinition {
}

func assertWorkerDeployed(it *infra.Test, mf *model.Manifest) {
ctx, cancelCtx := context.WithTimeout(context.Background(), 3*time.Second)
ctx, cancelCtx := context.WithTimeout(context.Background(), 15*time.Second)
it.Cleanup(cancelCtx)

deployed := model.WorkerDetails{}
Expand Down
10 changes: 9 additions & 1 deletion test/commands/execute_cmd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,10 +109,18 @@ func executeSpec(tc executeTestCase) infra.TestDefinition {
Skip: tc.skip,
CaptureOutput: true,
Test: func(it *infra.Test) {
suffix := infra.UniqueID()

workerDir, workerName := it.PrepareWorkerTestDir()

if tc.workerKey != "" {
workerName = tc.workerKey
uniqueKey := tc.workerKey + "-" + suffix
for i, arg := range tc.commandArgs {
if arg == tc.workerKey {
tc.commandArgs[i] = uniqueKey
}
}
workerName = uniqueKey
}

action := "GENERIC_EVENT"
Expand Down
11 changes: 6 additions & 5 deletions test/commands/list_cmd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (
"slices"
"strings"
"testing"
"time"

"github.com/jfrog/jfrog-cli-platform-services/commands/common"

Expand All @@ -32,23 +31,25 @@ type listTestCase struct {
}

func TestListCommand(t *testing.T) {
id := infra.UniqueID()

initialWorkers := []*model.WorkerDetails{
{
Key: fmt.Sprintf("w%v", time.Now().Unix()),
Key: "w0-" + id,
Description: "My worker 0",
Enabled: true,
SourceCode: `export default async function() { return { "status": "OK" } }`,
Action: "GENERIC_EVENT",
},
{
Key: fmt.Sprintf("w%v", time.Now().Unix()+1),
Key: "w1-" + id,
Description: "My worker 1",
Enabled: true,
SourceCode: `export default async function() { return { "status": "OK" } }`,
Action: "GENERIC_EVENT",
},
{
Key: fmt.Sprintf("w%v", time.Now().Unix()+2),
Key: "w2-" + id,
Description: "My worker 2",
Enabled: true,
SourceCode: `export default async function() { return { "status": "OK" } }`,
Expand All @@ -62,7 +63,7 @@ func TestListCommand(t *testing.T) {
}

workerWithProject := &model.WorkerDetails{
Key: fmt.Sprintf("w%v", time.Now().Unix()+3),
Key: "w3-" + id,
Description: "My worker 3",
Enabled: true,
Debug: true,
Expand Down
12 changes: 10 additions & 2 deletions test/commands/remove_cmd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,17 @@ func removeTestSpec(tc removeTestCase) infra.TestDefinition {
Only: tc.only,
Skip: tc.skip,
Test: func(it *infra.Test) {
suffix := infra.UniqueID()

_, workerName := it.PrepareWorkerTestDir()
if tc.workerKey != "" {
workerName = tc.workerKey
uniqueKey := tc.workerKey + "-" + suffix
for i, arg := range tc.commandArgs {
if arg == tc.workerKey {
tc.commandArgs[i] = uniqueKey
}
}
workerName = uniqueKey
}

err := it.RunCommand(infra.AppName, "init", "GENERIC_EVENT", workerName)
Expand Down Expand Up @@ -86,7 +94,7 @@ func removeTestSpec(tc removeTestCase) infra.TestDefinition {
}

func assertWorkerRemoved(it *infra.Test, mf *model.Manifest) {
ctx, cancelCtx := context.WithTimeout(context.Background(), 3*time.Second)
ctx, cancelCtx := context.WithTimeout(context.Background(), 15*time.Second)
it.Cleanup(cancelCtx)

it.NewHttpRequestWithContext(ctx).
Expand Down
19 changes: 19 additions & 0 deletions test/infra/http_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
package infra

import (
"bytes"
"context"
"encoding/json"
"fmt"
Expand Down Expand Up @@ -138,6 +139,21 @@ func (h *HttpExecutor) DoAndCaptureError() (*HttpResponse, error) {
}

func (h *HttpExecutor) doWithRetries() (*HttpResponse, error) {
var bodyBytes []byte
if h.request.Body != nil {
var err error
bodyBytes, err = io.ReadAll(h.request.Body)
_ = h.request.Body.Close()
if err != nil {
return nil, err
}
h.request.Body = io.NopCloser(bytes.NewReader(bodyBytes))
h.request.ContentLength = int64(len(bodyBytes))
h.request.GetBody = func() (io.ReadCloser, error) {
return io.NopCloser(bytes.NewReader(bodyBytes)), nil
}
}

start := time.Now()

resp, err := http.DefaultClient.Do(h.request)
Expand All @@ -150,6 +166,9 @@ func (h *HttpExecutor) doWithRetries() (*HttpResponse, error) {

for slices.Index(h.retryOnStatuses, resp.StatusCode) > -1 && elapsed < h.retryTimeout {
time.Sleep(backoff)
if bodyBytes != nil {
h.request.Body = io.NopCloser(bytes.NewReader(bodyBytes))
}
resp, err = http.DefaultClient.Do(h.request)
if err != nil {
return nil, err
Expand Down
8 changes: 6 additions & 2 deletions test/infra/itest_runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@ type Test struct {
}

const (
requestTimeout = 5 * time.Second
requestTimeout = 15 * time.Second
defaultRetryBackoff = 250 * time.Millisecond
defaultRetryTimeout = 2 * time.Second
defaultRetryTimeout = 10 * time.Second
)

var defaultRetryCommandOnErrors = []string{
Expand Down Expand Up @@ -359,6 +359,10 @@ func (it *Test) Run(name string, f func(t *Test)) bool {
})
}

func UniqueID() string {
return uuid.NewString()[:8]
}

func (it *Test) NewHttpRequest() *HttpRequest {
return &HttpRequest{
it: it,
Expand Down
3 changes: 1 addition & 2 deletions test/infra/secrets_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ package infra

import (
"context"
"time"

"github.com/jfrog/jfrog-cli-platform-services/commands/common"

Expand All @@ -17,7 +16,7 @@ func AddSecretPasswordToEnv(t common.Test) {
}

func AssertSecretValueFromServer(it *Test, workerKey string, secretKey string, wantValue string) {
ctx, cancelCtx := context.WithTimeout(context.Background(), 5*time.Second)
ctx, cancelCtx := context.WithTimeout(context.Background(), requestTimeout)
defer cancelCtx()

check := struct {
Expand Down
Loading