Skip to content

Commit

Permalink
Fix failing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
adreed-msft committed Sep 20, 2022
1 parent aba5db8 commit e109305
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 13 deletions.
23 changes: 14 additions & 9 deletions e2etest/declarativeScenario.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,20 +71,25 @@ func (s *scenario) Run() {
defer s.cleanup()

// setup runner
logDir, err := os.MkdirTemp("", "")
azcopyDir, err := os.MkdirTemp("", "")
if err != nil {
s.a.Error(err.Error())
return
}
azcopyRan := false
defer func() {
if os.Getenv("AZCOPY_E2E_LOG_OUTPUT") == "" {
s.a.Assert(os.RemoveAll(azcopyDir), equals(), nil)
return // no need, just delete logdir
}

err := os.MkdirAll(os.Getenv("AZCOPY_E2E_LOG_OUTPUT"), os.ModePerm|os.ModeDir)
if err != nil {
s.a.Assert(err, equals(), nil)
return
}
if azcopyRan && s.a.Failed() {
s.uploadLogs(logDir)
s.uploadLogs(azcopyDir)
s.a.(*testingAsserter).t.Log("uploaded logs for job " + s.state.result.jobID.String() + " as an artifact")
}
}()
Expand All @@ -106,29 +111,29 @@ func (s *scenario) Run() {

// execute
azcopyRan = true
s.runAzCopy(logDir)
s.runAzCopy(azcopyDir)
if s.a.Failed() {
return // execution failed. No point in running validation
}

// resume if needed
if s.needResume {
tx, err := s.state.result.GetTransferList(common.ETransferStatus.Cancelled())
tx, err := s.state.result.GetTransferList(common.ETransferStatus.Cancelled(), azcopyDir)
s.a.AssertNoErr(err, "Failed to get transfer list for Cancelled")
s.a.Assert(len(tx), equals(), len(s.p.debugSkipFiles), "Job cancel didn't completely work")

if !s.runHook(s.hs.beforeResumeHook) {
return
}

s.resumeAzCopy(logDir)
s.resumeAzCopy(azcopyDir)
}
if s.a.Failed() {
return // resume failed. No point in running validation
}

// check
s.validateTransferStates()
s.validateTransferStates(azcopyDir)
if s.a.Failed() {
return // no point in doing more validation
}
Expand All @@ -148,7 +153,7 @@ func (s *scenario) Run() {
}

func (s *scenario) uploadLogs(logDir string) {
if s.state.result == nil {
if s.state.result == nil || os.Getenv("AZCOPY_E2E_LOG_OUTPUT") == "" {
return // nothing to upload
}
s.a.Assert(os.Rename(logDir, filepath.Join(os.Getenv("AZCOPY_E2E_LOG_OUTPUT"), s.state.result.jobID.String())), equals(), nil)
Expand Down Expand Up @@ -295,7 +300,7 @@ func (s *scenario) validateRemove() {
}
}
}
func (s *scenario) validateTransferStates() {
func (s *scenario) validateTransferStates(azcopyDir string) {
if s.operation == eOperation.Remove() {
s.validateRemove()
return
Expand All @@ -318,7 +323,7 @@ func (s *scenario) validateTransferStates() {
// Is that OK? (Not sure what to do if it's not, because azcopy jobs show, apparently doesn't offer us a way to get the skipped list)
} {
expectedTransfers := s.fs.getForStatus(statusToTest, expectFolders, expectRootFolder)
actualTransfers, err := s.state.result.GetTransferList(statusToTest)
actualTransfers, err := s.state.result.GetTransferList(statusToTest, azcopyDir)
s.a.AssertNoErr(err)

Validator{}.ValidateCopyTransfersAreScheduled(s.a, isSrcEncoded, isDstEncoded, srcRoot, dstRoot, expectedTransfers, actualTransfers, statusToTest, s.FromTo(), s.srcAccountType, s.destAccountType)
Expand Down
14 changes: 10 additions & 4 deletions e2etest/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -274,9 +274,15 @@ func (t *TestRunner) SetTransferStatusFlag(value string) {
t.flags["with-status"] = value
}

func (t *TestRunner) ExecuteJobsShowCommand(jobID common.JobID) (JobsShowCommandResult, error) {
func (t *TestRunner) ExecuteJobsShowCommand(jobID common.JobID, azcopyDir string) (JobsShowCommandResult, error) {
args := append([]string{"jobs", "show", jobID.String()}, t.computeArgs()...)
out, err := exec.Command(GlobalInputManager{}.GetExecutablePath(), args...).Output()
cmd := exec.Command(GlobalInputManager{}.GetExecutablePath(), args...)

if azcopyDir != "" {
cmd.Env = append(cmd.Env, "AZCOPY_JOB_PLAN_LOCATION="+filepath.Join(azcopyDir, "plans"))
}

out, err := cmd.Output()
if err != nil {
return JobsShowCommandResult{}, err
}
Expand Down Expand Up @@ -313,12 +319,12 @@ func newCopyOrSyncCommandResult(rawOutput string) (CopyOrSyncCommandResult, bool
return CopyOrSyncCommandResult{jobID: jobSummary.JobID, finalStatus: jobSummary}, true
}

func (c *CopyOrSyncCommandResult) GetTransferList(status common.TransferStatus) ([]common.TransferDetail, error) {
func (c *CopyOrSyncCommandResult) GetTransferList(status common.TransferStatus, azcopyDir string) ([]common.TransferDetail, error) {
runner := newTestRunner()
runner.SetTransferStatusFlag(status.String())

// invoke AzCopy to get the status from the plan files
result, err := runner.ExecuteJobsShowCommand(c.jobID)
result, err := runner.ExecuteJobsShowCommand(c.jobID, azcopyDir)
if err != nil {
return make([]common.TransferDetail, 0), err
}
Expand Down

0 comments on commit e109305

Please sign in to comment.