Skip to content

Commit b413431

Browse files
Furistoroboquat
authored andcommitted
Move test to ws-daemon folder
1 parent ba17816 commit b413431

File tree

2 files changed

+52
-13
lines changed

2 files changed

+52
-13
lines changed

test/pkg/agent/daemon/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ package main
77
import (
88
"context"
99
"encoding/json"
10-
"net/http"
1110
"io/fs"
11+
"net/http"
1212
"os"
1313
"path/filepath"
1414
"strings"

test/tests/components/ws-manager/cpu_burst_test.go renamed to test/tests/components/ws-daemon/cpu_burst_test.go

Lines changed: 51 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@
22
// Licensed under the GNU Affero General Public License (AGPL).
33
// See License-AGPL.txt in the project root for license information.
44

5-
package wsmanager
5+
package wsdaemon
66

77
import (
88
"context"
9+
"encoding/json"
910
"strings"
1011
"testing"
1112
"time"
@@ -22,21 +23,34 @@ import (
2223
corev1 "k8s.io/api/core/v1"
2324
)
2425

25-
const (
26-
expectedMinCpu = 200_000
27-
expectedBurstCpu = 600_000
28-
)
26+
type DaemonConfig struct {
27+
CpuLimitConfig struct {
28+
Enabled bool `json:"enabled"`
29+
Limit int64 `json:"limit,string"`
30+
BurstLimit int64 `json:"burstLimit,string"`
31+
} `json:"cpuLimit"`
32+
}
2933

3034
func TestCpuBurst(t *testing.T) {
3135
f := features.New("cpulimiting").WithLabel("component", "ws-manager").Assess("check cpu limiting", func(_ context.Context, t *testing.T, cfg *envconf.Config) context.Context {
32-
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Minute)
36+
t.Parallel()
37+
38+
ctx, cancel := context.WithTimeout(context.Background(), 8*time.Minute)
3339
defer cancel()
3440

3541
api := integration.NewComponentAPI(ctx, cfg.Namespace(), kubeconfig, cfg.Client())
3642
t.Cleanup(func() {
3743
api.Done(t)
3844
})
3945

46+
daemonConfig := getDaemonConfig(ctx, t, cfg)
47+
if !daemonConfig.CpuLimitConfig.Enabled {
48+
return ctx
49+
}
50+
51+
daemonConfig.CpuLimitConfig.Limit = daemonConfig.CpuLimitConfig.Limit * 100_000
52+
daemonConfig.CpuLimitConfig.BurstLimit = daemonConfig.CpuLimitConfig.BurstLimit * 100_000
53+
4054
swr := func(req *wsmanapi.StartWorkspaceRequest) error {
4155
req.Spec.Initializer = &csapi.WorkspaceInitializer{
4256
Spec: &csapi.WorkspaceInitializer_Git{
@@ -81,7 +95,7 @@ func TestCpuBurst(t *testing.T) {
8195
ContainerId: containerId,
8296
}, &resp)
8397

84-
if resp.CpuQuota == expectedMinCpu {
98+
if resp.CpuQuota == daemonConfig.CpuLimitConfig.Limit {
8599
break
86100
}
87101
time.Sleep(5 * time.Second)
@@ -91,8 +105,8 @@ func TestCpuBurst(t *testing.T) {
91105
t.Fatalf("cannot get workspace resources: %q", err)
92106
}
93107

94-
if resp.CpuQuota != expectedMinCpu {
95-
t.Fatalf("expected cpu quota of %v, but was %v", expectedMinCpu, resp.CpuQuota)
108+
if resp.CpuQuota != daemonConfig.CpuLimitConfig.Limit {
109+
t.Fatalf("expected cpu quota of %v, but was %v", daemonConfig.CpuLimitConfig.Limit, resp.CpuQuota)
96110
}
97111

98112
workspaceClient, workspaceCloser, err := integration.Instrument(integration.ComponentWorkspace, "workspace", cfg.Namespace(), kubeconfig, cfg.Client(),
@@ -122,7 +136,7 @@ func TestCpuBurst(t *testing.T) {
122136
ContainerId: containerId,
123137
}, &resp)
124138

125-
if resp.CpuQuota == expectedBurstCpu {
139+
if resp.CpuQuota == daemonConfig.CpuLimitConfig.BurstLimit {
126140
break
127141
}
128142
time.Sleep(5 * time.Second)
@@ -132,15 +146,40 @@ func TestCpuBurst(t *testing.T) {
132146
t.Fatalf("cannot get workspace resources: %q", err)
133147
}
134148

135-
if resp.CpuQuota != expectedBurstCpu {
136-
t.Fatalf("expected cpu quota of %v, but was %v", expectedBurstCpu, resp.CpuQuota)
149+
if resp.CpuQuota != daemonConfig.CpuLimitConfig.BurstLimit {
150+
t.Fatalf("expected cpu quota of %v, but was %v", daemonConfig.CpuLimitConfig.BurstLimit, resp.CpuQuota)
137151
}
138152
return ctx
139153
}).Feature()
140154

141155
testEnv.Test(t, f)
142156
}
143157

158+
func getDaemonConfig(ctx context.Context, t *testing.T, cfg *envconf.Config) DaemonConfig {
159+
var daemonConfigMap corev1.ConfigMap
160+
161+
if err := cfg.Client().Resources().Get(ctx, "ws-daemon", cfg.Namespace(), &daemonConfigMap); err != nil {
162+
t.Fatal(err)
163+
}
164+
165+
data, ok := daemonConfigMap.Data["config.json"]
166+
if !ok {
167+
t.Fatal("server config map does not contain config.json")
168+
}
169+
170+
config := make(map[string]json.RawMessage)
171+
if err := json.Unmarshal([]byte(data), &config); err != nil {
172+
t.Fatal(err)
173+
}
174+
175+
var daemonConfig DaemonConfig
176+
if err := json.Unmarshal(config["daemon"], &daemonConfig); err != nil {
177+
t.Fatal(err)
178+
}
179+
180+
return daemonConfig
181+
}
182+
144183
func getWorkspaceContainerId(pod *corev1.Pod) string {
145184
for _, c := range pod.Status.ContainerStatuses {
146185
if c.Name != "workspace" {

0 commit comments

Comments
 (0)