Skip to content

Commit 875ce98

Browse files
committed
fix
1 parent 9449337 commit 875ce98

File tree

3 files changed

+31
-5
lines changed

3 files changed

+31
-5
lines changed

pkg/blob/controllerserver_test.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1503,11 +1503,8 @@ func TestCopyVolume(t *testing.T) {
15031503

15041504
m := util.NewMockEXEC(ctrl)
15051505
listStr1 := "JobId: ed1c3833-eaff-fe42-71d7-513fb065a9d9\nStart Time: Monday, 07-Aug-23 03:29:54 UTC\nStatus: InProgress\nCommand: copy https://{accountName}.file.core.windows.net/{srcFileshare}{SAStoken} https://{accountName}.file.core.windows.net/{dstFileshare}{SAStoken} --recursive --check-length=false"
1506-
listStr2 := "JobId: ed1c3833-eaff-fe42-71d7-513fb065a9d9\nStart Time: Monday, 07-Aug-23 03:29:54 UTC\nStatus: Completed\nCommand: copy https://{accountName}.file.core.windows.net/{srcFileshare}{SAStoken} https://{accountName}.file.core.windows.net/{dstFileshare}{SAStoken} --recursive --check-length=false"
1507-
o1 := m.EXPECT().RunCommand(gomock.Eq("azcopy jobs list | grep dstContainer -B 3"), gomock.Any()).Return(listStr1, nil).Times(1)
1506+
m.EXPECT().RunCommand(gomock.Eq("azcopy jobs list | grep dstContainer -B 3"), gomock.Any()).Return(listStr1, nil).Times(1)
15081507
m.EXPECT().RunCommand(gomock.Not("azcopy jobs list | grep dstBlobContainer -B 3"), gomock.Any()).Return("Percent Complete (approx): 50.0", nil)
1509-
o2 := m.EXPECT().RunCommand(gomock.Eq("azcopy jobs list | grep dstContainer -B 3"), gomock.Any()).Return(listStr2, nil)
1510-
gomock.InOrder(o1, o2)
15111508

15121509
d.azcopy.ExecCmd = m
15131510

pkg/blob/volume_lock.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ import (
2323
)
2424

2525
const (
26-
volumeOperationAlreadyExistsFmt = "An operation with the given Volume ID %s already exists"
26+
volumeOperationAlreadyExistsFmt = "An operation with the given Volume ID %s already exists"
27+
volumeOperationAlreadyExistsWithAzcopyFmt = "An operation using azcopy with the given Volume ID %s already exists. Azcopy job status: %s, copy percent: %s%%, error: %v"
2728
)
2829

2930
// VolumeLocks implements a map with atomic operations. It stores a set of all volume IDs

pkg/util/util.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import (
2323
"regexp"
2424
"strings"
2525
"sync"
26+
"time"
2627

2728
"github.com/go-ini/ini"
2829
"github.com/pkg/errors"
@@ -341,3 +342,30 @@ func GetKubeClient(kubeconfig string, kubeAPIQPS float64, kubeAPIBurst int, user
341342
kubeCfg.UserAgent = userAgent
342343
return kubernetes.NewForConfig(kubeCfg)
343344
}
345+
346+
// ExecFunc returns a exec function's output and error
347+
type ExecFunc func() (err error)
348+
349+
// TimeoutFunc returns output and error if an ExecFunc timeout
350+
type TimeoutFunc func() (err error)
351+
352+
// WaitUntilTimeout waits for the exec function to complete or return timeout error
353+
func WaitUntilTimeout(timeout time.Duration, execFunc ExecFunc, timeoutFunc TimeoutFunc) error {
354+
// Create a channel to receive the result of the azcopy exec function
355+
done := make(chan bool)
356+
var err error
357+
358+
// Start the azcopy exec function in a goroutine
359+
go func() {
360+
err = execFunc()
361+
done <- true
362+
}()
363+
364+
// Wait for the function to complete or time out
365+
select {
366+
case <-done:
367+
return err
368+
case <-time.After(timeout):
369+
return timeoutFunc()
370+
}
371+
}

0 commit comments

Comments
 (0)