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.
This commit is contained in:
chaitalisg
2024-07-15 14:06:36 -07:00
committed by GitHub
parent 2ec9bbe43c
commit 00495c73ea
2 changed files with 37 additions and 2 deletions

View File

@@ -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
}

View File

@@ -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()