Skip to content

Commit

Permalink
Provide details about which timeout expired
Browse files Browse the repository at this point in the history
  • Loading branch information
onsi committed Oct 27, 2022
1 parent bb3b4e2 commit 0f2fa27
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 15 deletions.
4 changes: 2 additions & 2 deletions integration/reporting_test.go
Expand Up @@ -140,7 +140,7 @@ var _ = Describe("Reporting", func() {
Ω(specReports.Find("panics")).Should(HavePanicked("boom"))
Ω(specReports.Find("is pending")).Should(BePending())
Ω(specReports.Find("is skipped").State).Should(Equal(types.SpecStateSkipped))
Ω(specReports.Find("times out and fails during cleanup")).Should(HaveTimedOut("This spec timed out and reported the following failure after the timeout:\n\nfailure-after-timeout"))
Ω(specReports.Find("times out and fails during cleanup")).Should(HaveTimedOut("A node timeout occurred and the following failure was recorded after the timeout:\n\nfailure-after-timeout"))

Ω(specReports.Find("times out and fails during cleanup").AdditionalFailures[0].Failure.Message).Should(Equal("double-whammy"))
Ω(specReports.Find("times out and fails during cleanup").AdditionalFailures[0].Failure.FailureNodeType).Should(Equal(types.NodeTypeCleanupAfterEach))
Expand Down Expand Up @@ -230,7 +230,7 @@ var _ = Describe("Reporting", func() {
Ω(getTestCase("[It] reporting test is skipped", suite.TestCases).Skipped.Message).Should(Equal("skipped - skip"))

Ω(getTestCase("[It] reporting test times out and fails during cleanup", suite.TestCases).Status).Should(Equal("timedout"))
Ω(getTestCase("[It] reporting test times out and fails during cleanup", suite.TestCases).Failure.Message).Should(Equal("This spec timed out and reported the following failure after the timeout:\n\nfailure-after-timeout"))
Ω(getTestCase("[It] reporting test times out and fails during cleanup", suite.TestCases).Failure.Message).Should(Equal("A node timeout occurred and the following failure was recorded after the timeout:\n\nfailure-after-timeout"))
Ω(getTestCase("[It] reporting test times out and fails during cleanup", suite.TestCases).Failure.Description).Should(ContainSubstring("<-ctx.Done()"))
Ω(getTestCase("[It] reporting test times out and fails during cleanup", suite.TestCases).Failure.Description).Should(ContainSubstring("There were additional failures detected after the initial failure:\n[FAILED]\ndouble-whammy\nIn [DeferCleanup (Each)] at:"))

Expand Down
2 changes: 1 addition & 1 deletion internal/internal_integration/fail_test.go
Expand Up @@ -340,7 +340,7 @@ var _ = Describe("handling test failures", func() {
Ω(specReport.AdditionalFailures[0].Failure.FailureNodeType).Should(Equal(types.NodeTypeAfterEach))

Ω(specReport.AdditionalFailures[1].State).Should(Equal(types.SpecStateTimedout))
Ω(specReport.AdditionalFailures[1].Failure.Message).Should(Equal("This spec timed out and reported the following failure after the timeout:\n\nfail-DC"))
Ω(specReport.AdditionalFailures[1].Failure.Message).Should(Equal("A node timeout occurred and the following failure was recorded after the timeout:\n\nfail-DC"))
Ω(specReport.AdditionalFailures[1].Failure.FailureNodeType).Should(Equal(types.NodeTypeCleanupAfterEach))
})
})
Expand Down
Expand Up @@ -14,9 +14,11 @@ import (
. "github.com/onsi/ginkgo/v2/internal/test_helpers"
"github.com/onsi/ginkgo/v2/types"
. "github.com/onsi/gomega"
"github.com/onsi/gomega/format"
)

func TestSuiteTests(t *testing.T) {
format.TruncatedDiff = false
RegisterFailHandler(Fail)
suiteConfig, _ := GinkgoConfiguration()
suiteConfig.GracePeriod = time.Second
Expand Down
16 changes: 8 additions & 8 deletions internal/internal_integration/interrupt_and_timeout_test.go
Expand Up @@ -663,7 +663,7 @@ var _ = Describe("Interrupts and Timeouts", func() {
"bef", "E", "aft",
))

Ω(reporter.Did.Find("A")).Should(HaveTimedOut("This spec timed out and reported the following failure after the timeout:\n\nsubsequent failure message"))
Ω(reporter.Did.Find("A")).Should(HaveTimedOut("A node timeout occurred and the following failure was recorded after the timeout:\n\nsubsequent failure message"))
Ω(reporter.Did.Find("B")).Should(HaveTimedOut())
Ω(reporter.Did.Find("C")).Should(HaveTimedOut())
Ω(reporter.Did.Find("D")).Should(HavePassed())
Expand All @@ -681,7 +681,7 @@ var _ = Describe("Interrupts and Timeouts", func() {

It("attaches progress reports to the timout failures", func() {
Ω(reporter.Did.Find("A").Failure.ProgressReport.LeafNodeText).Should(Equal("A"))
Ω(reporter.Did.Find("A").Failure.ProgressReport.Message).Should(Equal("{{bold}}This is the Progress Report generated when the timeout occurred:{{/}}"))
Ω(reporter.Did.Find("A").Failure.ProgressReport.Message).Should(Equal("{{bold}}This is the Progress Report generated when the node timeout occurred:{{/}}"))
Ω(reporter.Did.Find("B").Failure.ProgressReport.LeafNodeText).Should(Equal("B"))
Ω(reporter.Did.Find("C").Failure.ProgressReport.LeafNodeText).Should(Equal("C"))
Ω(reporter.Did.Find("D").Failure.ProgressReport).Should(BeZero())
Expand Down Expand Up @@ -807,7 +807,7 @@ var _ = Describe("Interrupts and Timeouts", func() {
Ω(times.Get("aft-3-out")).Should(BeNumerically("~", times.Get("aft-3-cancel")+50*time.Millisecond, dt))
Ω(times.Get("aft-4-out")).Should(BeNumerically("~", times.Get("aft-3-out")+gracePeriod, dt))

Ω(reporter.Did.Find("A")).Should(HaveTimedOut())
Ω(reporter.Did.Find("A")).Should(HaveTimedOut("A suite timeout occurred"))
Ω(reporter.Did.Find("A").Failure.ProgressReport.LeafNodeText).Should(Equal("A"))

Ω(reporter.ProgressReports).Should(HaveLen(3))
Expand Down Expand Up @@ -867,9 +867,9 @@ var _ = Describe("Interrupts and Timeouts", func() {

It("should always favor the shorter timeout", func() {
Ω(rt).Should(HaveTracked("bef-A", "bef-B", "bef-C"))
Ω(reporter.Did.Find("A")).Should(HaveTimedOut())
Ω(reporter.Did.Find("B")).Should(HaveTimedOut())
Ω(reporter.Did.Find("C")).Should(HaveTimedOut())
Ω(reporter.Did.Find("A")).Should(HaveTimedOut("A node timeout occurred"))
Ω(reporter.Did.Find("B")).Should(HaveTimedOut("A spec timeout occurred"))
Ω(reporter.Did.Find("C")).Should(HaveTimedOut("A suite timeout occurred"))

Ω(times.Get("bef-A")).Should(BeNumerically("~", time.Millisecond*100, 50*time.Millisecond))
Ω(times.Get("bef-B")).Should(BeNumerically("~", time.Millisecond*150, 50*time.Millisecond))
Expand All @@ -896,8 +896,8 @@ var _ = Describe("Interrupts and Timeouts", func() {
It("doesn't get stuck because Eventually will exit and it includes the additional report provided by eventually", func() {
Ω(rt).Should(HaveTracked("A"))
Ω(reporter.Did.Find("A")).Should(HaveTimedOut(clLine(1)))
Ω(reporter.Did.Find("A").Failure.Message).Should(MatchRegexp(`This spec timed out and reported the following failure after the timeout:\n\nContext was cancelled after .*\nExpected\n <string>: foo\nto equal\n <string>: bar`))
Ω(reporter.Did.Find("A").Failure.ProgressReport.Message).Should(Equal("{{bold}}This is the Progress Report generated when the timeout occurred:{{/}}"))
Ω(reporter.Did.Find("A").Failure.Message).Should(MatchRegexp(`A spec timeout occurred and the following failure was recorded after the timeout:\n\nContext was cancelled after .*\nExpected\n <string>: foo\nto equal\n <string>: bar`))
Ω(reporter.Did.Find("A").Failure.ProgressReport.Message).Should(Equal("{{bold}}This is the Progress Report generated when the spec timeout occurred:{{/}}"))
Ω(reporter.Did.Find("A").Failure.ProgressReport.AdditionalReports).Should(ConsistOf("Expected\n <string>: foo\nto equal\n <string>: bar"))
})
})
Expand Down
13 changes: 9 additions & 4 deletions internal/suite.go
Expand Up @@ -248,7 +248,7 @@ func (suite *Suite) SetProgressStepCursor(cursor ProgressStepCursor) {
}

/*
Spec Running methods - used during PhaseRun
Spec Running methods - used during PhaseRun
*/
func (suite *Suite) CurrentSpecReport() types.SpecReport {
suite.selectiveLock.Lock()
Expand Down Expand Up @@ -697,18 +697,23 @@ func (suite *Suite) runNode(node Node, specDeadline time.Time, text string) (typ

now := time.Now()
deadline := suite.deadline
timeoutInPlay := "suite"
if deadline.IsZero() || (!specDeadline.IsZero() && specDeadline.Before(deadline)) {
deadline = specDeadline
timeoutInPlay = "spec"
}
if node.NodeTimeout > 0 && (deadline.IsZero() || deadline.Sub(now) > node.NodeTimeout) {
deadline = now.Add(node.NodeTimeout)
timeoutInPlay = "node"
}
if (!deadline.IsZero() && deadline.Before(now)) || interruptStatus.Interrupted() {
//we're out of time already. let's wait for a NodeTimeout if we have it, or GracePeriod if we don't
if node.NodeTimeout > 0 {
deadline = now.Add(node.NodeTimeout)
timeoutInPlay = "node"
} else {
deadline = now.Add(gracePeriod)
timeoutInPlay = "grace period"
}
}

Expand Down Expand Up @@ -781,7 +786,7 @@ func (suite *Suite) runNode(node Node, specDeadline time.Time, text string) (typ
// before the grace period elapsed. if we have a failure message we should include it
if outcomeFromRun != types.SpecStatePassed {
failure.Location, failure.ForwardedPanic = failureFromRun.Location, failureFromRun.ForwardedPanic
failure.Message = "This spec timed out and reported the following failure after the timeout:\n\n" + failureFromRun.Message
failure.Message = fmt.Sprintf("A %s timeout occurred and the following failure was recorded after the timeout:\n\n%s", timeoutInPlay, failureFromRun.Message)
}
return outcome, failure
}
Expand All @@ -801,9 +806,9 @@ func (suite *Suite) runNode(node Node, specDeadline time.Time, text string) (typ
case <-deadlineChannel:
// we're out of time - the outcome is a timeout and we capture the failure and progress report
outcome = types.SpecStateTimedout
failure.Message, failure.Location = "Timedout", node.CodeLocation
failure.Message, failure.Location = fmt.Sprintf("A %s timeout occurred", timeoutInPlay), node.CodeLocation
failure.ProgressReport = suite.generateProgressReport(false).WithoutCapturedGinkgoWriterOutput()
failure.ProgressReport.Message = "{{bold}}This is the Progress Report generated when the timeout occurred:{{/}}"
failure.ProgressReport.Message = fmt.Sprintf("{{bold}}This is the Progress Report generated when the %s timeout occurred:{{/}}", timeoutInPlay)
deadlineChannel = nil
// tell the spec to stop. it's important we generate the progress report first to make sure we capture where
// the spec is actually stuck
Expand Down

0 comments on commit 0f2fa27

Please sign in to comment.