chore: [cache-dir-size-fix] Part 2: Add configuration flags and parsing for file cache size fix#4415
Conversation
|
/gemini review |
|
/gemini summary |
There was a problem hiding this comment.
Code Review
This pull request introduces new configuration flags for a file cache size scan feature. The changes include updating the configuration struct, adding and parsing command-line flags, and implementing associated validation and rationalization logic. The implementation is clear and includes new tests for argument parsing and config rationalization. My primary feedback is to enhance the test coverage for the new validation logic to ensure all scenarios are properly handled.
| func TestValidateFileCacheConfig_SizeScanDeleteEmptyDirs(t *testing.T) { | ||
| t.Parallel() | ||
| testCases := []struct { | ||
| name string | ||
| config FileCacheConfig | ||
| wantErr bool | ||
| }{ | ||
| { | ||
| name: "Enable=False,_Delete=True_->_Error", | ||
| config: FileCacheConfig{ | ||
| SizeScanEnable: false, | ||
| SizeScanDeleteEmptyDirs: true, | ||
| // Valid defaults | ||
| CacheFileForRangeRead: false, | ||
| DownloadChunkSizeMb: 50, | ||
| EnableCrc: false, | ||
| EnableParallelDownloads: false, | ||
| MaxParallelDownloads: 4, | ||
| MaxSizeMb: -1, | ||
| ParallelDownloadsPerFile: 16, | ||
| WriteBufferSize: 4 * 1024 * 1024, | ||
| EnableODirect: true, | ||
| }, | ||
| wantErr: true, | ||
| }, | ||
| { | ||
| name: "Enable=True,_Delete=True_->_Valid", | ||
| config: FileCacheConfig{ | ||
| SizeScanEnable: true, | ||
| SizeScanDeleteEmptyDirs: true, | ||
| SizeScanFrequencySeconds: 10, | ||
| // Valid defaults | ||
| CacheFileForRangeRead: false, | ||
| DownloadChunkSizeMb: 50, | ||
| EnableCrc: false, | ||
| EnableParallelDownloads: false, | ||
| MaxParallelDownloads: 4, | ||
| MaxSizeMb: -1, | ||
| ParallelDownloadsPerFile: 16, | ||
| WriteBufferSize: 4 * 1024 * 1024, | ||
| EnableODirect: true, | ||
| }, | ||
| wantErr: false, | ||
| }, | ||
| } | ||
|
|
||
| for _, tc := range testCases { | ||
| t.Run(tc.name, func(t *testing.T) { | ||
| t.Parallel() | ||
| c := validConfig(t) | ||
| c.FileCache = tc.config | ||
|
|
||
| err := ValidateConfig(viper.New(), &c) | ||
|
|
||
| if tc.wantErr { | ||
| assert.Error(t, err) | ||
| } else { | ||
| assert.NoError(t, err) | ||
| } | ||
| }) | ||
| } | ||
| } |
There was a problem hiding this comment.
The new test TestValidateFileCacheConfig_SizeScanDeleteEmptyDirs is a good start, but it only covers one of the new validation scenarios for the size scan feature. To ensure robustness, it would be beneficial to expand this test to cover all the new validation logic added in isValidFileCacheConfig.
I'd suggest renaming the test to something more general, like TestValidateFileCacheConfig_SizeScanFlags, and adding test cases for the following scenarios:
SizeScanEnable=truewithSizeScanFrequencySeconds=0should return an error.SizeScanEnable=falsewithSizeScanFiles=trueshould return an error.SizeScanEnable=falsewithSizeScanFrequencySecondsexplicitly set to a non-zero value should return an error. This requires setting the value in theviperinstance passed toValidateConfig.
Here's an example for the last case:
// In a new test case
v := viper.New()
v.Set("file-cache.size-scan-frequency-seconds", 5)
c := validConfig(t)
c.FileCache.SizeScanEnable = false
c.FileCache.SizeScanFrequencySeconds = 5
err := ValidateConfig(v, &c)
assert.Error(t, err)This will make the tests for the new validation logic more comprehensive.
Summary of ChangesThis pull request, part two of a cache directory size fix, establishes the foundational configuration and parsing mechanisms for a new file cache size management feature. It introduces several new flags that allow users to precisely control how the file cache directory is scanned for size, including options for enabling/disabling the scan, specifying scan frequency, and managing empty directories. This work lays the groundwork for the actual implementation of the size scanning functionality. Highlights
Changelog
Activity
|
4a6bbb9 to
3938291
Compare
ebd1a5e to
fec64b0
Compare
3938291 to
9e7e9c4
Compare
fec64b0 to
28e5de1
Compare
9e7e9c4 to
1d5a9ce
Compare
28e5de1 to
cc61e60
Compare
1d5a9ce to
30075a4
Compare
cc61e60 to
77e24b9
Compare
30075a4 to
d754d78
Compare
Description
Link to the issue in case of a bug fix.
b/477828938
Testing details
Any backward incompatible change? If so, please explain.