Skip to content

Commit

Permalink
refactoring test to avoid storing symlinks in git
Browse files Browse the repository at this point in the history
Signed-off-by: Golan Levy <[email protected]>
  • Loading branch information
GolanLevy committed Oct 1, 2023
1 parent b5ac87f commit ae0f441
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 7 deletions.
2 changes: 1 addition & 1 deletion model-serving-puller/puller/puller.go
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ func getModelDiskSize(modelPath string) (int64, error) {
}

// Calculating the size of the resolved path (for pvc) instead of the symlink itself.
// We are not expecting to have infinite recursions since the model would not be able to be loaded by the serving runtime
// We are not expecting to have infinite recursion since otherwise the serving runtime would not be able to load the model
if info.Mode()&os.ModeSymlink != 0 {
if resolvedPath, evalErr := os.Readlink(path); evalErr == nil {
if symlinkSize, err1 := getModelDiskSize(resolvedPath); err1 == nil {
Expand Down
25 changes: 19 additions & 6 deletions model-serving-puller/puller/puller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -605,18 +605,31 @@ func Test_getModelDiskSize(t *testing.T) {
{"testModelSize/1/airbnb.model.lr.zip", 15259},
{"testModelSize/1", 15259},
{"testModelSize/2", 39375276},
{"testModelSize/symlink/1/airbnb.model.lr.zip.lnk", 15259},
{"testModelSize/symlink/1", 15259},
{"testModelSize/symlink/1.lnk", 15259},
{"testModelSize/symlink/2.lnk", 39375276},
}

// creating symlinks on runtime since git is not managing symlinks by default
symlinkName := "symlink"
symlinkPath := filepath.Join(RootModelDir, symlinkName)

for _, tt := range diskSizeTests {
t.Run("", func(t *testing.T) {
fullPath := filepath.Join(RootModelDir, tt.modelPath)
diskSize, err := getModelDiskSize(fullPath)
validatePathDiskSize(t, fullPath, tt.expectedSize)

// testing symlink to the same path
err := os.Symlink(fullPath, symlinkPath)
assert.NoError(t, err)

validatePathDiskSize(t, symlinkPath, tt.expectedSize)

err = os.Remove(symlinkPath)
assert.NoError(t, err)
assert.EqualValues(t, tt.expectedSize, diskSize)
})
}
}

func validatePathDiskSize(t *testing.T, path string, expectedSize int64) {
diskSize, err := getModelDiskSize(path)
assert.NoError(t, err)
assert.EqualValues(t, expectedSize, diskSize)
}

0 comments on commit ae0f441

Please sign in to comment.