From 5f49dad1c4a2e31783f7c67dde7fcdda9cb7a595 Mon Sep 17 00:00:00 2001 From: Eloy Coto Date: Fri, 13 Oct 2017 13:15:44 +0200 Subject: [PATCH 1/3] Added Duration on GinkgoTestDescription Signed-off-by: Eloy Coto --- ginkgo_dsl.go | 4 +++- internal/spec/spec.go | 7 ++++--- internal/suite/suite_test.go | 1 + 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/ginkgo_dsl.go b/ginkgo_dsl.go index 8befd35ad..a6143a0f6 100644 --- a/ginkgo_dsl.go +++ b/ginkgo_dsl.go @@ -149,7 +149,8 @@ type GinkgoTestDescription struct { FileName string LineNumber int - Failed bool + Failed bool + Duration time.Duration } //CurrentGinkgoTestDescripton returns information about the current running test. @@ -169,6 +170,7 @@ func CurrentGinkgoTestDescription() GinkgoTestDescription { FileName: subjectCodeLocation.FileName, LineNumber: subjectCodeLocation.LineNumber, Failed: summary.HasFailureState(), + Duration: summary.RunTime, } } diff --git a/internal/spec/spec.go b/internal/spec/spec.go index d32dec699..96b779036 100644 --- a/internal/spec/spec.go +++ b/internal/spec/spec.go @@ -19,6 +19,7 @@ type Spec struct { state types.SpecState runTime time.Duration + startTime time.Time failure types.SpecFailure previousFailures bool } @@ -97,7 +98,7 @@ func (spec *Spec) Summary(suiteID string) *types.SpecSummary { ComponentTexts: componentTexts, ComponentCodeLocations: componentCodeLocations, State: spec.state, - RunTime: spec.runTime, + RunTime: time.Since(spec.startTime), Failure: spec.failure, Measurements: spec.measurementsReport(), SuiteID: suiteID, @@ -118,9 +119,9 @@ func (spec *Spec) Run(writer io.Writer) { spec.previousFailures = true } - startTime := time.Now() + spec.startTime = time.Now() defer func() { - spec.runTime = time.Since(startTime) + spec.runTime = time.Since(spec.startTime) }() for sample := 0; sample < spec.subject.Samples(); sample++ { diff --git a/internal/suite/suite_test.go b/internal/suite/suite_test.go index b7bcdbd2e..24f70cae2 100644 --- a/internal/suite/suite_test.go +++ b/internal/suite/suite_test.go @@ -121,6 +121,7 @@ var _ = Describe("Suite", func() { Ω(description.LineNumber).Should(BeNumerically(">", 50)) Ω(description.LineNumber).Should(BeNumerically("<", 150)) Ω(description.Failed).Should(BeFalse()) + Ω(description.Duration).Should(BeNumerically(">", 0)) }) Measure("should run measurements", func(b Benchmarker) { From 329d7ed7ad37afffdd35bbfd8bf86915e60ab6a5 Mon Sep 17 00:00:00 2001 From: Eloy Coto Date: Fri, 22 Dec 2017 16:47:33 +0100 Subject: [PATCH 2/3] Fix comments on Spec Duration Signed-off-by: Eloy Coto --- internal/spec/spec.go | 7 ++++++- internal/spec/spec_test.go | 7 +++++++ internal/suite/suite_test.go | 13 +++++++++++++ 3 files changed, 26 insertions(+), 1 deletion(-) diff --git a/internal/spec/spec.go b/internal/spec/spec.go index 96b779036..530f32bd6 100644 --- a/internal/spec/spec.go +++ b/internal/spec/spec.go @@ -92,13 +92,18 @@ func (spec *Spec) Summary(suiteID string) *types.SpecSummary { componentTexts[len(spec.containers)] = spec.subject.Text() componentCodeLocations[len(spec.containers)] = spec.subject.CodeLocation() + runTime := spec.runTime + if runTime == 0 { + runTime = time.Since(spec.startTime) + } + return &types.SpecSummary{ IsMeasurement: spec.IsMeasurement(), NumberOfSamples: spec.subject.Samples(), ComponentTexts: componentTexts, ComponentCodeLocations: componentCodeLocations, State: spec.state, - RunTime: time.Since(spec.startTime), + RunTime: runTime, Failure: spec.failure, Measurements: spec.measurementsReport(), SuiteID: suiteID, diff --git a/internal/spec/spec_test.go b/internal/spec/spec_test.go index 3bab8887c..7011a42eb 100644 --- a/internal/spec/spec_test.go +++ b/internal/spec/spec_test.go @@ -569,6 +569,13 @@ var _ = Describe("Spec", func() { Ω(summary.RunTime).Should(BeNumerically(">=", 10*time.Millisecond)) }) + It("should have a runtime which remains consistent after spec run", func() { + totalRunTime := summary.RunTime + Ω(totalRunTime).Should(BeNumerically(">=", 10*time.Millisecond)) + + Consistently(func() time.Duration { return spec.Summary("suite id").RunTime }).Should(Equal(totalRunTime)) + }) + It("should not be a measurement, or have a measurement summary", func() { Ω(summary.IsMeasurement).Should(BeFalse()) Ω(summary.Measurements).Should(BeEmpty()) diff --git a/internal/suite/suite_test.go b/internal/suite/suite_test.go index 24f70cae2..6626dcd26 100644 --- a/internal/suite/suite_test.go +++ b/internal/suite/suite_test.go @@ -153,6 +153,19 @@ var _ = Describe("Suite", func() { "AfterSuite", })) }) + Context("When afterEach info is needed", func() { + AfterEach(func() { + description := CurrentGinkgoTestDescription() + Ω(description.IsMeasurement).Should(BeFalse()) + Ω(description.FileName).Should(ContainSubstring("suite_test.go")) + Ω(description.Failed).Should(BeFalse()) + Ω(description.Duration).Should(BeNumerically(">", 0)) + }) + + It("provides information about the current test", func() { + Ω(true).To(BeTrue()) + }) + }) Context("when told to randomize all specs", func() { BeforeEach(func() { From 074740825d9ad9783a8bb4844706a9255b65a743 Mon Sep 17 00:00:00 2001 From: Eloy Coto Date: Tue, 16 Jan 2018 09:48:21 +0100 Subject: [PATCH 3/3] Changed test names Signed-off-by: Eloy Coto --- internal/suite/suite_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/internal/suite/suite_test.go b/internal/suite/suite_test.go index 6626dcd26..fd2d11dc3 100644 --- a/internal/suite/suite_test.go +++ b/internal/suite/suite_test.go @@ -153,7 +153,7 @@ var _ = Describe("Suite", func() { "AfterSuite", })) }) - Context("When afterEach info is needed", func() { + Context("when in an AfterEach block", func() { AfterEach(func() { description := CurrentGinkgoTestDescription() Ω(description.IsMeasurement).Should(BeFalse()) @@ -162,7 +162,7 @@ var _ = Describe("Suite", func() { Ω(description.Duration).Should(BeNumerically(">", 0)) }) - It("provides information about the current test", func() { + It("still provides information about the current test", func() { Ω(true).To(BeTrue()) }) })