Skip to content

Commit

Permalink
fix ut
Browse files Browse the repository at this point in the history
  • Loading branch information
cvvz committed Mar 24, 2023
1 parent f1238c6 commit 92aa40e
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 23 deletions.
6 changes: 3 additions & 3 deletions pkg/blob/nodeserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,7 @@ func (d *Driver) NodeStageVolume(ctx context.Context, req *csi.NodeStageVolumeRe

// wait a few seconds to make sure blobfuse mount is successful
// please refer to https://github.com/Azure/azure-storage-fuse/pull/1088 for more details
if err := d.waitForMount(targetPath, waitForMountInterval, waitForMountTimeout); err != nil {
if err := waitForMount(targetPath, waitForMountInterval, waitForMountTimeout); err != nil {
return nil, fmt.Errorf("failed to wait for mount: %w", err)
}

Expand Down Expand Up @@ -583,14 +583,14 @@ func (d *Driver) ensureMountPoint(target string, perm os.FileMode) (bool, error)
return !notMnt, nil
}

func (d *Driver) waitForMount(path string, intervel, timeout time.Duration) error {
func waitForMount(path string, intervel, timeout time.Duration) error {
timeAfter := time.After(timeout)
timeTick := time.Tick(intervel)

for {
select {
case <-timeTick:
notMount, err := d.mounter.IsLikelyNotMountPoint(path)
notMount, err := mount.New("").IsLikelyNotMountPoint(path)
if err != nil {
return err
}
Expand Down
33 changes: 13 additions & 20 deletions pkg/blob/nodeserver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -758,6 +758,14 @@ func TestMountBlobfuseInsideDriver(t *testing.T) {
}

func Test_waitForMount(t *testing.T) {
if runtime.GOOS == "windows" || runtime.GOOS == "darwin" {
t.Skip("Skipping test on ", runtime.GOOS)
}

tmpDir, err := os.MkdirTemp("", "")
assert.NoError(t, err)
defer os.RemoveAll(tmpDir)

type args struct {
path string
intervel time.Duration
Expand All @@ -773,43 +781,28 @@ func Test_waitForMount(t *testing.T) {
{
name: "test error timeout",
args: args{
path: "",
path: tmpDir,
intervel: 1 * time.Millisecond,
timeout: 10 * time.Millisecond,
},
wantErr: true,
subErrMsg: "timeout",
},
{
name: "test error",
name: "test error no such file or directory",
args: args{
path: "error_is_likely",
path: "/no/such/file/or/directory",
intervel: 1 * time.Millisecond,
timeout: 10 * time.Millisecond,
},
wantErr: true,
subErrMsg: "fake error",
},
{
name: "test mount success",
args: args{
path: "false_is_likely",
intervel: 1 * time.Millisecond,
timeout: 10 * time.Millisecond,
},
wantErr: false,
subErrMsg: "no such file or directory",
},
}

d := NewFakeDriver()
fakeMounter := &fakeMounter{}
d.mounter = &mount.SafeFormatAndMount{
Interface: fakeMounter,
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
err := d.waitForMount(tt.args.path, tt.args.intervel, tt.args.timeout)
err := waitForMount(tt.args.path, tt.args.intervel, tt.args.timeout)
if (err != nil) != tt.wantErr {
t.Errorf("waitForMount() error = %v, wantErr %v", err, tt.wantErr)
}
Expand Down

0 comments on commit 92aa40e

Please sign in to comment.