Path: blob/main/test/tests/components/ws-daemon/io_limiting_test.go
2501 views
// Copyright (c) 2022 Gitpod GmbH. All rights reserved.1// Licensed under the GNU Affero General Public License (AGPL).2// See License.AGPL.txt in the project root for license information.34package wsdaemon56import (7"context"8"testing"9"time"1011daemon "github.com/gitpod-io/gitpod/test/pkg/agent/daemon/api"12"github.com/gitpod-io/gitpod/test/pkg/integration"13corev1 "k8s.io/api/core/v1"14"sigs.k8s.io/e2e-framework/pkg/envconf"15"sigs.k8s.io/e2e-framework/pkg/features"16)1718func TestIOLimiting(t *testing.T) {19f := features.New("IO limiting").20WithLabel("component", "ws-daemon").21Assess("verify if io limiting works fine", func(testCtx context.Context, t *testing.T, cfg *envconf.Config) context.Context {22t.Parallel()2324ctx, cancel := context.WithTimeout(testCtx, time.Duration(5*time.Minute))25defer cancel()2627api := integration.NewComponentAPI(ctx, cfg.Namespace(), kubeconfig, cfg.Client())28t.Cleanup(func() {29api.Done(t)30})3132daemonConfig := getDaemonConfig(ctx, t, cfg)33if daemonConfig.IOLimitConfig.ReadBandwidthPerSecond.IsZero() {34t.Fatal("io limiting ReadBandwidthPerSecond is not enabled")35}36if daemonConfig.IOLimitConfig.WriteBandwidthPerSecond.IsZero() {37t.Fatal("io limiting WriteBandwidthPerSecond is not enabled")38}3940nfo, stopWs, err := integration.LaunchWorkspaceDirectly(t, ctx, api)41if err != nil {42t.Fatal(err)43}4445t.Cleanup(func() {46sctx, scancel := context.WithTimeout(context.Background(), 5*time.Minute)47defer scancel()4849sapi := integration.NewComponentAPI(sctx, cfg.Namespace(), kubeconfig, cfg.Client())50defer sapi.Done(t)5152if _, err = stopWs(true, sapi); err != nil {53t.Errorf("cannot stop workspace: %q", err)54}55})5657daemonClient, daemonCloser, err := integration.Instrument(integration.ComponentWorkspaceDaemon, "daemon", cfg.Namespace(), kubeconfig, cfg.Client(),58integration.WithWorkspacekitLift(false),59integration.WithContainer("ws-daemon"),60)6162if err != nil {63t.Fatal(err)64}65integration.DeferCloser(t, daemonCloser)6667var pod corev1.Pod68if err := cfg.Client().Resources().Get(ctx, "ws-"+nfo.Req.Id, cfg.Namespace(), &pod); err != nil {69t.Fatal(err)70}7172containerId := getWorkspaceContainerId(&pod)73var resp daemon.GetWorkspaceResourcesResponse74if err = daemonClient.Call("DaemonAgent.GetWorkspaceResources", daemon.GetWorkspaceResourcesRequest{75ContainerId: containerId,76}, &resp); err != nil {77t.Fatalf("cannot get workspace resources: %q", err)78}7980t.Logf("workspace resources: %+v", resp)81if resp.FoundIOMax == false {82t.Fatalf("cannot find io max")83}84if len(resp.IOMax) == 0 {85t.Fatalf("cannot find workspace io max")86}8788for _, ioMax := range resp.IOMax {89if ioMax.Read != uint64(daemonConfig.IOLimitConfig.ReadBandwidthPerSecond.Value()) {90t.Fatalf("expected max read bandwidth %v but got %v", daemonConfig.IOLimitConfig.ReadBandwidthPerSecond.Value(), ioMax.Read)91}92if ioMax.Write != uint64(daemonConfig.IOLimitConfig.WriteBandwidthPerSecond.Value()) {93t.Fatalf("expected max write bandwidth %v but got %v", daemonConfig.IOLimitConfig.WriteBandwidthPerSecond.Value(), ioMax.Write)94}95}9697return testCtx98}).Feature()99100testEnv.Test(t, f)101}102103104