Skip to content

Commit

Permalink
Fix timeline for concurrent scenarios (#7)
Browse files Browse the repository at this point in the history
  • Loading branch information
vearutop authored Jun 6, 2023
1 parent 891f549 commit b3fd3b6
Showing 1 changed file with 32 additions and 3 deletions.
35 changes: 32 additions & 3 deletions formatter.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"io"
"log"
"os"
"strconv"
"strings"
"sync"

Expand Down Expand Up @@ -56,8 +57,10 @@ type formatter struct {

*godog.BaseFmt

mu sync.Mutex
scenarios map[*godog.Scenario]*scenarioContext
mu sync.Mutex
threads int
busyThreads map[int]bool
scenarios map[*godog.Scenario]*scenarioContext
}

// TestRunStarted prepares test result directory.
Expand All @@ -73,6 +76,7 @@ type scenarioContext struct {
lastTime report.TimestampMs
totalSteps int
finishedSteps int
thread int
}

// Pickle receives scenario.
Expand Down Expand Up @@ -101,12 +105,36 @@ func (f *formatter) Pickle(scenario *godog.Scenario) {
}

now := report.GetTimestampMs()
f.scenarios[scenario] = &scenarioContext{
sc := &scenarioContext{
result: &res,
start: now,
lastTime: now,
totalSteps: len(scenario.Steps),
}

for thread, busy := range f.busyThreads {
if !busy {
f.busyThreads[thread] = true
sc.thread = thread

break
}
}

if sc.thread == 0 {
f.threads++
sc.thread = f.threads

if f.busyThreads == nil {
f.busyThreads = make(map[int]bool)
}

f.busyThreads[f.threads] = true
}

f.scenarios[scenario] = sc

sc.result.Labels = append(sc.result.Labels, report.Label{Name: "thread", Value: "routine " + strconv.Itoa(sc.thread)})
}

func (f *formatter) argumentAttachment(st *godog.Step) *report.Attachment {
Expand Down Expand Up @@ -159,6 +187,7 @@ func (f *formatter) step(sc *godog.Scenario, st *godog.Step, status report.Statu

if c.finishedSteps == c.totalSteps {
f.WriteResult(c.result)
f.busyThreads[c.thread] = false
}
}

Expand Down

0 comments on commit b3fd3b6

Please sign in to comment.