Skip to content

Commit

Permalink
Use updated params throughout tests
Browse files Browse the repository at this point in the history
Turns out some tests don't call init config, so they weren't handling the deprecated config. This updates the test to use the new params so they set the correct values.
  • Loading branch information
jhiemstrawisc committed Nov 26, 2024
1 parent 1721c25 commit 20fbc93
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 13 deletions.
8 changes: 4 additions & 4 deletions cache/cache_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ import (
func CheckCacheSentinelLocation() error {
if param.Cache_SentinelLocation.IsSet() {
sentinelPath := param.Cache_SentinelLocation.GetString()
dataLoc := param.Cache_LocalRoot.GetString()
dataLoc := param.Cache_StorageLocation.GetString()
sentinelPath = path.Clean(sentinelPath)
if path.Base(sentinelPath) != sentinelPath {
return errors.Errorf("invalid Cache.SentinelLocation path. File must not contain a directory. Got %s", sentinelPath)
Expand All @@ -51,17 +51,17 @@ func CheckCacheSentinelLocation() error {
return nil
}

// Periodically scan the /<Cache.LocalRoot>/pelican/monitoring directory to clean up test files
// Periodically scan the ${Cache.StorageLocation}/pelican/monitoring directory to clean up test files
// TODO: Director test files should be under /pelican/monitoring/directorTest and the file names
// should have director-test- as the prefix
func LaunchDirectorTestFileCleanup(ctx context.Context) {
server_utils.LaunchWatcherMaintenance(ctx,
[]string{filepath.Join(param.Cache_LocalRoot.GetString(), "pelican", "monitoring")},
[]string{filepath.Join(param.Cache_StorageLocation.GetString(), "pelican", "monitoring")},
"cache director-based health test clean up",
time.Minute,
func(notifyEvent bool) error {
// We run this function regardless of notifyEvent to do the cleanup
dirPath := filepath.Join(param.Cache_LocalRoot.GetString(), "pelican", "monitoring")
dirPath := filepath.Join(param.Cache_StorageLocation.GetString(), "pelican", "monitoring")
dirInfo, err := os.Stat(dirPath)
if err != nil {
return err
Expand Down
4 changes: 2 additions & 2 deletions cache/cache_api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func TestCheckCacheSentinelLocation(t *testing.T) {
tmpDir := t.TempDir()
server_utils.ResetTestState()
viper.Set(param.Cache_SentinelLocation.GetName(), "test.txt")
viper.Set(param.Cache_LocalRoot.GetName(), tmpDir)
viper.Set(param.Cache_StorageLocation.GetName(), tmpDir)
err := CheckCacheSentinelLocation()
require.Error(t, err)
assert.Contains(t, err.Error(), "failed to open Cache.SentinelLocation")
Expand All @@ -61,7 +61,7 @@ func TestCheckCacheSentinelLocation(t *testing.T) {
server_utils.ResetTestState()

viper.Set(param.Cache_SentinelLocation.GetName(), "test.txt")
viper.Set(param.Cache_LocalRoot.GetName(), tmpDir)
viper.Set(param.Cache_StorageLocation.GetName(), tmpDir)

file, err := os.Create(filepath.Join(tmpDir, "test.txt"))
require.NoError(t, err)
Expand Down
8 changes: 4 additions & 4 deletions cache/self_monitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func InitSelfTestDir() error {
return err
}

basePath := param.Cache_LocalRoot.GetString()
basePath := param.Cache_StorageLocation.GetString()
pelicanMonPath := filepath.Join(basePath, "/pelican")
monitoringPath := filepath.Join(pelicanMonPath, "/monitoring")
selfTestPath := filepath.Join(monitoringPath, "/selfTest")
Expand All @@ -80,9 +80,9 @@ func InitSelfTestDir() error {
}

func generateTestFile() (string, error) {
basePath := param.Cache_LocalRoot.GetString()
basePath := param.Cache_StorageLocation.GetString()
if basePath == "" {
return "", errors.New("failed to generate self-test file for cache: Cache.LocalRoot is not set.")
return "", errors.New("failed to generate self-test file for cache: Cache.StorageLocation is not set.")
}
selfTestPath := filepath.Join(basePath, selfTestDir)
_, err := os.Stat(selfTestPath)
Expand Down Expand Up @@ -225,7 +225,7 @@ func downloadTestFile(ctx context.Context, fileUrl string) error {
}

func deleteTestFile(fileUrlStr string) error {
basePath := param.Cache_LocalRoot.GetString()
basePath := param.Cache_StorageLocation.GetString()
fileUrl, err := url.Parse(fileUrlStr)
if err != nil {
return errors.Wrap(err, "invalid file url to remove the test file")
Expand Down
2 changes: 1 addition & 1 deletion client/fed_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -623,7 +623,7 @@ func TestDirectReads(t *testing.T) {
assert.Equal(t, transferResults[0].TransferredBytes, int64(17))

// Assert that the file was not cached
cacheDataLocation := param.Cache_LocalRoot.GetString() + export.FederationPrefix
cacheDataLocation := param.Cache_StorageLocation.GetString() + export.FederationPrefix
filepath := filepath.Join(cacheDataLocation, filepath.Base(tempFile.Name()))
_, err = os.Stat(filepath)
assert.True(t, os.IsNotExist(err))
Expand Down
2 changes: 1 addition & 1 deletion cmd/fed_serve_cache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ func TestFedServeCache(t *testing.T) {
viper.Set("ConfigDir", tmpPath)
viper.Set("Origin.RunLocation", filepath.Join(tmpPath, "xOrigin"))
viper.Set("Cache.RunLocation", filepath.Join(tmpPath, "xCache"))
viper.Set("Cache.LocalRoot", filepath.Join(tmpPath, "data"))
viper.Set("Cache.StorageLocation", filepath.Join(tmpPath, "data"))
viper.Set("Origin.StoragePrefix", filepath.Join(origPath, "ns"))
viper.Set("Origin.FederationPrefix", "/test")
testFilePath := filepath.Join(origPath, "ns", "test-file.txt")
Expand Down
2 changes: 1 addition & 1 deletion fed_test_utils/fed.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ func NewFedTest(t *testing.T, originConfig string) (ft *FedTest) {
viper.Set("Server.WebPort", 0)
viper.Set("Origin.RunLocation", filepath.Join(tmpPath, "origin"))
viper.Set("Cache.RunLocation", filepath.Join(tmpPath, "cache"))
viper.Set("Cache.LocalRoot", filepath.Join(tmpPath, "xcache-data"))
viper.Set("Cache.StorageLocation", filepath.Join(tmpPath, "xcache-data"))
viper.Set("LocalCache.RunLocation", filepath.Join(tmpPath, "local-cache"))
viper.Set("Registry.RequireOriginApproval", false)
viper.Set("Registry.RequireCacheApproval", false)
Expand Down

0 comments on commit 20fbc93

Please sign in to comment.