Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

workspace integration test: enhance TestRegularWorkspaceTasks test speed #12856

Merged
merged 1 commit into from
Sep 12, 2022
Merged
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
88 changes: 40 additions & 48 deletions test/tests/components/ws-manager/tasks_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ package wsmanager
import (
"context"
"encoding/json"
"fmt"
"testing"
"time"

Expand All @@ -21,43 +22,33 @@ import (
)

func TestRegularWorkspaceTasks(t *testing.T) {
testRepo := "https://github.com/gitpod-io/empty"
testRepoName := "empty"
wsLoc := "/workspace/empty"

tests := []struct {
Name string
Task gitpod.TasksItems
LookForFile string
Task []gitpod.TasksItems
LookForFile []string
FF []wsmanapi.WorkspaceFeatureFlag
}{
{
Name: "classic-init",
Task: gitpod.TasksItems{Init: "touch /workspace/gitpod/init-ran; exit"},
LookForFile: "init-ran",
},
{
Name: "classic-before",
Task: gitpod.TasksItems{Before: "touch /workspace/gitpod/before-ran; exit"},
LookForFile: "before-ran",
},
{
Name: "classic-command",
Task: gitpod.TasksItems{Command: "touch /workspace/gitpod/command-ran; exit"},
LookForFile: "command-ran",
},
{
Name: "pvc-init",
Task: gitpod.TasksItems{Init: "touch /workspace/gitpod/init-ran; exit"},
LookForFile: "init-ran",
FF: []wsmanapi.WorkspaceFeatureFlag{wsmanapi.WorkspaceFeatureFlag_PERSISTENT_VOLUME_CLAIM},
Name: "classic",
Task: []gitpod.TasksItems{
{Init: fmt.Sprintf("touch %s/init-ran; exit", wsLoc)},
{Before: fmt.Sprintf("touch %s/before-ran; exit", wsLoc)},
{Command: fmt.Sprintf("touch %s/command-ran; exit", wsLoc)},
},
LookForFile: []string{"init-ran", "before-ran", "command-ran"},
},
{
Name: "pvc-before",
Task: gitpod.TasksItems{Before: "touch /workspace/gitpod/before-ran; exit"},
LookForFile: "before-ran",
FF: []wsmanapi.WorkspaceFeatureFlag{wsmanapi.WorkspaceFeatureFlag_PERSISTENT_VOLUME_CLAIM},
},
{
Name: "pvc-command",
Task: gitpod.TasksItems{Command: "touch /workspace/gitpod/command-ran; exit"},
LookForFile: "command-ran",
Name: "pvc",
Task: []gitpod.TasksItems{
{Init: fmt.Sprintf("touch %s/init-ran; exit", wsLoc)},
{Before: fmt.Sprintf("touch %s/before-ran; exit", wsLoc)},
{Command: fmt.Sprintf("touch %s/command-ran; exit", wsLoc)},
},
LookForFile: []string{"init-ran", "before-ran", "command-ran"},
FF: []wsmanapi.WorkspaceFeatureFlag{wsmanapi.WorkspaceFeatureFlag_PERSISTENT_VOLUME_CLAIM},
},
}
Expand All @@ -66,7 +57,7 @@ func TestRegularWorkspaceTasks(t *testing.T) {
WithLabel("component", "ws-manager").
WithLabel("type", "tasks").
Assess("it can run workspace tasks", func(_ context.Context, t *testing.T, cfg *envconf.Config) context.Context {
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Minute)
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Minute)
defer cancel()

api := integration.NewComponentAPI(ctx, cfg.Namespace(), kubeconfig, cfg.Client())
Expand All @@ -77,7 +68,7 @@ func TestRegularWorkspaceTasks(t *testing.T) {
for _, test := range tests {
t.Run(test.Name, func(t *testing.T) {
addInitTask := func(swr *wsmanapi.StartWorkspaceRequest) error {
tasks, err := json.Marshal([]gitpod.TasksItems{test.Task})
tasks, err := json.Marshal(test.Task)
if err != nil {
return err
}
Expand All @@ -89,15 +80,15 @@ func TestRegularWorkspaceTasks(t *testing.T) {
swr.Spec.Initializer = &csapi.WorkspaceInitializer{
Spec: &csapi.WorkspaceInitializer_Git{
Git: &csapi.GitInitializer{
RemoteUri: "https://github.com/gitpod-io/gitpod.git",
RemoteUri: testRepo,
TargetMode: csapi.CloneTargetMode_REMOTE_BRANCH,
CloneTaget: "main",
CheckoutLocation: "gitpod",
CheckoutLocation: testRepoName,
Config: &csapi.GitConfig{},
},
},
}
swr.Spec.WorkspaceLocation = "gitpod"
swr.Spec.WorkspaceLocation = testRepoName
return nil
}

Expand All @@ -107,8 +98,7 @@ func TestRegularWorkspaceTasks(t *testing.T) {
}

defer func() {
err = stopWs(true)
if err != nil {
if err = stopWs(true); err != nil {
t.Errorf("cannot stop workspace: %q", err)
}
}()
Expand All @@ -131,7 +121,7 @@ func TestRegularWorkspaceTasks(t *testing.T) {
for i := 1; i < 10; i++ {
var res agent.ExecResponse
err = rsa.Call("WorkspaceAgent.Exec", &agent.ExecRequest{
Dir: "/workspace/gitpod",
Dir: wsLoc,
Command: "curl",
// nftable rule only forwards to this ip address
Args: []string{"10.0.5.2:22999/_supervisor/v1/status/tasks"},
Expand All @@ -144,7 +134,7 @@ func TestRegularWorkspaceTasks(t *testing.T) {
t.Fatalf("cannot decode supervisor status response: %s", err)
}

if len(parsedResp.Result.Tasks) != 1 {
if len(parsedResp.Result.Tasks) != len(test.Task) {
t.Fatalf("expected one task to run, but got %d", len(parsedResp.Result.Tasks))
}
if parsedResp.Result.Tasks[0].State == supervisorapi.TaskState_name[int32(supervisorapi.TaskState_closed)] {
Expand All @@ -160,21 +150,23 @@ func TestRegularWorkspaceTasks(t *testing.T) {

var ls agent.ListDirResponse
err = rsa.Call("WorkspaceAgent.ListDir", &agent.ListDirRequest{
Dir: "/workspace/gitpod",
Dir: wsLoc,
}, &ls)
if err != nil {
t.Fatal(err)
}

var foundMaker bool
for _, f := range ls.Files {
if f == test.LookForFile {
foundMaker = true
break
for _, lff := range test.LookForFile {
var foundMaker bool
for _, f := range ls.Files {
if f == lff {
foundMaker = true
break
}
}
if !foundMaker {
t.Fatalf("task seems to have run, but cannot find %s it should have created", lff)
}
}
if !foundMaker {
t.Fatal("task seems to have run, but cannot find the file it should have created")
}
})
}
Expand Down