Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
gitpod-io
GitHub Repository: gitpod-io/gitpod
Path: blob/main/test/tests/components/ws-daemon/io_limiting_test.go
2501 views
1
// Copyright (c) 2022 Gitpod GmbH. All rights reserved.
2
// Licensed under the GNU Affero General Public License (AGPL).
3
// See License.AGPL.txt in the project root for license information.
4
5
package wsdaemon
6
7
import (
8
"context"
9
"testing"
10
"time"
11
12
daemon "github.com/gitpod-io/gitpod/test/pkg/agent/daemon/api"
13
"github.com/gitpod-io/gitpod/test/pkg/integration"
14
corev1 "k8s.io/api/core/v1"
15
"sigs.k8s.io/e2e-framework/pkg/envconf"
16
"sigs.k8s.io/e2e-framework/pkg/features"
17
)
18
19
func TestIOLimiting(t *testing.T) {
20
f := features.New("IO limiting").
21
WithLabel("component", "ws-daemon").
22
Assess("verify if io limiting works fine", func(testCtx context.Context, t *testing.T, cfg *envconf.Config) context.Context {
23
t.Parallel()
24
25
ctx, cancel := context.WithTimeout(testCtx, time.Duration(5*time.Minute))
26
defer cancel()
27
28
api := integration.NewComponentAPI(ctx, cfg.Namespace(), kubeconfig, cfg.Client())
29
t.Cleanup(func() {
30
api.Done(t)
31
})
32
33
daemonConfig := getDaemonConfig(ctx, t, cfg)
34
if daemonConfig.IOLimitConfig.ReadBandwidthPerSecond.IsZero() {
35
t.Fatal("io limiting ReadBandwidthPerSecond is not enabled")
36
}
37
if daemonConfig.IOLimitConfig.WriteBandwidthPerSecond.IsZero() {
38
t.Fatal("io limiting WriteBandwidthPerSecond is not enabled")
39
}
40
41
nfo, stopWs, err := integration.LaunchWorkspaceDirectly(t, ctx, api)
42
if err != nil {
43
t.Fatal(err)
44
}
45
46
t.Cleanup(func() {
47
sctx, scancel := context.WithTimeout(context.Background(), 5*time.Minute)
48
defer scancel()
49
50
sapi := integration.NewComponentAPI(sctx, cfg.Namespace(), kubeconfig, cfg.Client())
51
defer sapi.Done(t)
52
53
if _, err = stopWs(true, sapi); err != nil {
54
t.Errorf("cannot stop workspace: %q", err)
55
}
56
})
57
58
daemonClient, daemonCloser, err := integration.Instrument(integration.ComponentWorkspaceDaemon, "daemon", cfg.Namespace(), kubeconfig, cfg.Client(),
59
integration.WithWorkspacekitLift(false),
60
integration.WithContainer("ws-daemon"),
61
)
62
63
if err != nil {
64
t.Fatal(err)
65
}
66
integration.DeferCloser(t, daemonCloser)
67
68
var pod corev1.Pod
69
if err := cfg.Client().Resources().Get(ctx, "ws-"+nfo.Req.Id, cfg.Namespace(), &pod); err != nil {
70
t.Fatal(err)
71
}
72
73
containerId := getWorkspaceContainerId(&pod)
74
var resp daemon.GetWorkspaceResourcesResponse
75
if err = daemonClient.Call("DaemonAgent.GetWorkspaceResources", daemon.GetWorkspaceResourcesRequest{
76
ContainerId: containerId,
77
}, &resp); err != nil {
78
t.Fatalf("cannot get workspace resources: %q", err)
79
}
80
81
t.Logf("workspace resources: %+v", resp)
82
if resp.FoundIOMax == false {
83
t.Fatalf("cannot find io max")
84
}
85
if len(resp.IOMax) == 0 {
86
t.Fatalf("cannot find workspace io max")
87
}
88
89
for _, ioMax := range resp.IOMax {
90
if ioMax.Read != uint64(daemonConfig.IOLimitConfig.ReadBandwidthPerSecond.Value()) {
91
t.Fatalf("expected max read bandwidth %v but got %v", daemonConfig.IOLimitConfig.ReadBandwidthPerSecond.Value(), ioMax.Read)
92
}
93
if ioMax.Write != uint64(daemonConfig.IOLimitConfig.WriteBandwidthPerSecond.Value()) {
94
t.Fatalf("expected max write bandwidth %v but got %v", daemonConfig.IOLimitConfig.WriteBandwidthPerSecond.Value(), ioMax.Write)
95
}
96
}
97
98
return testCtx
99
}).Feature()
100
101
testEnv.Test(t, f)
102
}
103
104