Skip to content

Commit

Permalink
add ut
Browse files Browse the repository at this point in the history
  • Loading branch information
cvvz committed Mar 22, 2023
1 parent cd9c5dd commit 0900961
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 2 deletions.
8 changes: 6 additions & 2 deletions pkg/blob/nodeserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -584,17 +584,21 @@ func (d *Driver) ensureMountPoint(target string, perm os.FileMode) (bool, error)
}

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

for {
select {
case <-time.After(intervel):
case <-timeTick:
notMount, err := mount.New("").IsLikelyNotMountPoint(path)
if err != nil {
return err
}
if !notMount {
klog.V(2).Infof("blobfuse mount at %s success", path)
return nil
}
case <-time.After(timeout):
case <-timeAfter:
return fmt.Errorf("timeout waiting for mount %s", path)
}
}
Expand Down
50 changes: 50 additions & 0 deletions pkg/blob/nodeserver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,10 @@ import (
"path/filepath"
"reflect"
"runtime"
"strings"
"syscall"
"testing"
"time"

"google.golang.org/grpc"
"google.golang.org/grpc/codes"
Expand Down Expand Up @@ -754,3 +756,51 @@ func TestMountBlobfuseInsideDriver(t *testing.T) {
// the error should be of type exec.ExitError
assert.NotNil(t, err)
}

func Test_waitForMount(t *testing.T) {
type args struct {
path string
intervel time.Duration
timeout time.Duration
}

tests := []struct {
name string
args args
wantErr bool
subErrMsg string
}{
{
name: "test timeout",
args: args{
path: "/",
intervel: 1 * time.Millisecond,
timeout: 10 * time.Millisecond,
},
wantErr: true,
subErrMsg: "timeout",
},
{
name: "test no such file or directory",
args: args{
path: "",
intervel: 1 * time.Millisecond,
timeout: 10 * time.Millisecond,
},
wantErr: true,
subErrMsg: "no such file or directory",
},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
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)
}
if err != nil && !strings.Contains(err.Error(), tt.subErrMsg) {
t.Errorf("waitForMount() error = %v, wantErr %v", err, tt.subErrMsg)
}
})
}
}

0 comments on commit 0900961

Please sign in to comment.