From 00495c73ea9c63562614bf2ce7cbc00d50dd94cd Mon Sep 17 00:00:00 2001 From: chaitalisg Date: Mon, 15 Jul 2024 14:06:36 -0700 Subject: [PATCH] test(general): set cache size limits for the repository under test used in robustness tests (#3945) The robustness tests set soft limits for content cache size and metadata cache size. This PR adds the hard limits for both the caches, thus reducing the memory required to run the robustness tests for long term. --- .../multiclient_test/framework/harness.go | 16 +++++++++++-- .../multiclient_test/framework/snapshotter.go | 23 +++++++++++++++++++ 2 files changed, 37 insertions(+), 2 deletions(-) diff --git a/tests/robustness/multiclient_test/framework/harness.go b/tests/robustness/multiclient_test/framework/harness.go index 36f2ff99f..7f5330648 100644 --- a/tests/robustness/multiclient_test/framework/harness.go +++ b/tests/robustness/multiclient_test/framework/harness.go @@ -23,8 +23,10 @@ ) const ( - dataSubPath = "robustness-data" - metadataSubPath = "robustness-metadata" + dataSubPath = "robustness-data" + metadataSubPath = "robustness-metadata" + contentCacheLimitMB = 500 + metadataCacheLimitMB = 500 ) var repoPathPrefix = flag.String("repo-path-prefix", "", "Point the robustness tests at this path prefix") @@ -146,6 +148,16 @@ func (th *TestHarness) getSnapshotter() bool { return false } + // Set size limits for content cache and metadata cache for repository under test. + if err = s.setContentCacheSizeLimit(contentCacheLimitMB); err != nil { + log.Println("Error setting content cache size limits for kopia Snapshotter:", err) + return false + } + if err = s.setMetadataCacheSizeLimit(metadataCacheLimitMB); err != nil { + log.Println("Error setting metadata cache size limits for kopia Snapshotter:", err) + return false + } + return true } diff --git a/tests/robustness/multiclient_test/framework/snapshotter.go b/tests/robustness/multiclient_test/framework/snapshotter.go index c73e52a30..59b965514 100644 --- a/tests/robustness/multiclient_test/framework/snapshotter.go +++ b/tests/robustness/multiclient_test/framework/snapshotter.go @@ -16,6 +16,11 @@ "github.com/kopia/kopia/tests/robustness/snapmeta" ) +const ( + contentCacheLimitMBFlag = "--content-cache-size-limit-mb" + metadataCacheLimitMBFlag = "--metadata-cache-size-limit-mb" +) + // MultiClientSnapshotter manages a set of client Snapshotter instances and // implements the Snapshotter interface itself. Snapshotter methods must be // provided with a client-wrapped context so the MultiClientSnapshotter can @@ -67,6 +72,24 @@ func (mcs *MultiClientSnapshotter) ConnectOrCreateRepo(repoPath string) error { return err } +// setCacheSizeLimits sets the content cache size limits for an existing repository +// the repository server is connected to. +func (mcs *MultiClientSnapshotter) setContentCacheSizeLimit(contentCacheSizeLimitMB int) error { + _, _, err := mcs.server.Run("cache", "set", + contentCacheLimitMBFlag, strconv.Itoa(contentCacheSizeLimitMB), + ) + + return err +} + +// setMetadataCacheSizeLimit sets the metadata cache size limits for an existing repository, the repository server is connected to. +func (mcs *MultiClientSnapshotter) setMetadataCacheSizeLimit(metadataCacheSizeLimitMB int) error { + _, _, err := mcs.server.Run("cache", "set", + metadataCacheLimitMBFlag, strconv.Itoa(metadataCacheSizeLimitMB)) + + return err +} + // ServerCmd returns the server command. func (mcs *MultiClientSnapshotter) ServerCmd() *exec.Cmd { return mcs.server.ServerCmd()