Skip to content

Commit 5f49dad

Browse files
committed
Added Duration on GinkgoTestDescription
Signed-off-by: Eloy Coto <[email protected]>
1 parent 11459a8 commit 5f49dad

File tree

3 files changed

+8
-4
lines changed

3 files changed

+8
-4
lines changed

ginkgo_dsl.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,8 @@ type GinkgoTestDescription struct {
149149
FileName string
150150
LineNumber int
151151

152-
Failed bool
152+
Failed bool
153+
Duration time.Duration
153154
}
154155

155156
//CurrentGinkgoTestDescripton returns information about the current running test.
@@ -169,6 +170,7 @@ func CurrentGinkgoTestDescription() GinkgoTestDescription {
169170
FileName: subjectCodeLocation.FileName,
170171
LineNumber: subjectCodeLocation.LineNumber,
171172
Failed: summary.HasFailureState(),
173+
Duration: summary.RunTime,
172174
}
173175
}
174176

internal/spec/spec.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ type Spec struct {
1919

2020
state types.SpecState
2121
runTime time.Duration
22+
startTime time.Time
2223
failure types.SpecFailure
2324
previousFailures bool
2425
}
@@ -97,7 +98,7 @@ func (spec *Spec) Summary(suiteID string) *types.SpecSummary {
9798
ComponentTexts: componentTexts,
9899
ComponentCodeLocations: componentCodeLocations,
99100
State: spec.state,
100-
RunTime: spec.runTime,
101+
RunTime: time.Since(spec.startTime),
101102
Failure: spec.failure,
102103
Measurements: spec.measurementsReport(),
103104
SuiteID: suiteID,
@@ -118,9 +119,9 @@ func (spec *Spec) Run(writer io.Writer) {
118119
spec.previousFailures = true
119120
}
120121

121-
startTime := time.Now()
122+
spec.startTime = time.Now()
122123
defer func() {
123-
spec.runTime = time.Since(startTime)
124+
spec.runTime = time.Since(spec.startTime)
124125
}()
125126

126127
for sample := 0; sample < spec.subject.Samples(); sample++ {

internal/suite/suite_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ var _ = Describe("Suite", func() {
121121
Ω(description.LineNumber).Should(BeNumerically(">", 50))
122122
Ω(description.LineNumber).Should(BeNumerically("<", 150))
123123
Ω(description.Failed).Should(BeFalse())
124+
Ω(description.Duration).Should(BeNumerically(">", 0))
124125
})
125126

126127
Measure("should run measurements", func(b Benchmarker) {

0 commit comments

Comments
 (0)