Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix bug with incorrect time duration of tests #66

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 31 additions & 4 deletions pkg/allure/result.go
Original file line number Diff line number Diff line change
Expand Up @@ -223,11 +223,12 @@ func (result *Result) SkipOnPrint() {
}

// Print If `Result.ToPrint` = `true` - the method terminates without creating any files. Otherwise:
// - Calls `Result.PrintAttachments()`.
// - Saves the file `uuid4-Result.json`.
// - Calls `Result.Container.Print()`
// - Returns error (if any)
// - Calls `Result.PrintAttachments()`.
// - Saves the file `uuid4-Result.json`.
// - Calls `Result.Container.Print()`
// - Returns error (if any)
func (result *Result) Print() error {
overWriteStartAndEndTime(result)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if len(result.Steps) > 0 {
    overWriteStartAndEndTime(result)
}

if !result.ToPrint {
return nil
}
Expand Down Expand Up @@ -300,3 +301,29 @@ func getMD5Hash(text string) string {
hash := md5.Sum([]byte(text))
return hex.EncodeToString(hash[:])
}

// getTimeSumOfSteps gets first step start time and last step end time
func getTimeSumOfSteps(result *Result) (startTimeInt int64, endTimeInt int64) {
startTime := result.Steps[0].Start
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there will be panic if Steps array is empty

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

although, how are you going work with following case?

func TestSome(t provider.T) {
    time.Sleep(3 * time.Second)
    t.WithNewStep(...)
}

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sorry,what do u mean?

endTime := result.Steps[0].Start

for i := range result.Steps {
ladatkinS marked this conversation as resolved.
Show resolved Hide resolved
if result.Steps[i].Stop > endTime {
endTime = result.Steps[i].Stop
}
if result.Steps[i].Start < startTime {
startTime = result.Steps[i].Start
}
}

return startTime, endTime
}

func overWriteStartAndEndTime(result *Result) {
if result.Status == Skipped {
result.Stop = result.Start
} else {
result.Start, _ = getTimeSumOfSteps(result)
ladatkinS marked this conversation as resolved.
Show resolved Hide resolved
_, result.Stop = getTimeSumOfSteps(result)
}
}