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
Show file tree
Hide file tree
Changes from all 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
34 changes: 30 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,28 @@ 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 _, step := range result.Steps {
if step.Stop > endTime {
endTime = step.Stop
}
if step.Start < startTime {
startTime = step.Start
}
}

return startTime, endTime
}

func overWriteStartAndEndTime(result *Result) {
if result.Status == Skipped {
result.Stop = result.Start
} else {
result.Start, result.Stop = getTimeSumOfSteps(result)
}
}
7 changes: 6 additions & 1 deletion pkg/allure/result_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,7 @@ func TestResult_WithLabels(t *testing.T) {
func TestResult_PrintAttachments(t *testing.T) {
attachmentText := `THIS IS A TEXT ATTACHMENT`
result := new(Result)
result.Steps = append(result.Steps, NewStep(testName, "complete", 1, 1, []*Parameter{}))
result.Attachments = append(result.Attachments, NewAttachment("Text Attachment if TestAttachment", Text, []byte(attachmentText)))
result.PrintAttachments()
defer os.RemoveAll(allureDir)
Expand All @@ -298,6 +299,7 @@ func TestResult_PrintAttachments(t *testing.T) {

func TestResult_Print_toPrintFalse(t *testing.T) {
result := new(Result)
result.Steps = append(result.Steps, NewStep(testName, "complete", 1, 1, []*Parameter{}))
err := result.Print()

require.NoError(t, err)
Expand All @@ -306,6 +308,7 @@ func TestResult_Print_toPrintFalse(t *testing.T) {

func TestResult_Print(t *testing.T) {
result := NewResult(testName, testFullName)
result.Steps = append(result.Steps, NewStep(testName, "complete", 1, 1, []*Parameter{}))
err := result.Print()

require.NoError(t, err)
Expand Down Expand Up @@ -340,6 +343,7 @@ func TestResult_Print(t *testing.T) {
func TestResult_Print_withAttachment(t *testing.T) {
attachmentText := `THIS IS A TEXT ATTACHMENT`
result := NewResult(testName, testFullName)
result.Steps = append(result.Steps, NewStep(testName, "complete", 1, 1, []*Parameter{}))
result.Attachments = append(result.Attachments, NewAttachment("Text Attachment if TestAttachment", Text, []byte(attachmentText)))
result.PrintAttachments()
err := result.Print()
Expand Down Expand Up @@ -396,10 +400,11 @@ func TestResult_Print_withAttachment(t *testing.T) {

func TestResult_Done(t *testing.T) {
attachmentText := `THIS IS A TEXT ATTACHMENT`
now := GetNow()
result := NewResult(testName, testFullName)
result.Attachments = append(result.Attachments, NewAttachment("Text Attachment if TestAttachment", Text, []byte(attachmentText)))
result.Steps = append(result.Steps, NewStep(testName, "complete", now, now, []*Parameter{}))
result.PrintAttachments()
now := GetNow()
result.Done()

defer os.RemoveAll(allureDir)
Expand Down