-
-
Notifications
You must be signed in to change notification settings - Fork 667
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Ensure
CurrentSpecReport
and AddReportEntry
are thread-safe
- Loading branch information
Showing
2 changed files
with
90 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,92 @@ | ||
package internal_integration_test | ||
|
||
import ( | ||
"fmt" | ||
"time" | ||
|
||
. "github.com/onsi/ginkgo/v2" | ||
"github.com/onsi/ginkgo/v2/types" | ||
. "github.com/onsi/gomega" | ||
) | ||
|
||
var _ = Describe("ReportEntries", func() { | ||
BeforeEach(func() { | ||
success, _ := RunFixture("Report Entries", func() { | ||
BeforeSuite(func() { | ||
AddReportEntry("bridge", "engaged") | ||
}) | ||
Context("happy path", func() { | ||
BeforeEach(func() { | ||
success, _ := RunFixture("Report Entries", func() { | ||
BeforeSuite(func() { | ||
AddReportEntry("bridge", "engaged") | ||
}) | ||
|
||
It("adds-entries", func() { | ||
AddReportEntry("medical", "healthy") | ||
AddReportEntry("engineering", "on fire") | ||
}) | ||
|
||
It("adds-entries", func() { | ||
AddReportEntry("medical", "healthy") | ||
AddReportEntry("engineering", "on fire") | ||
It("adds-no-entries", func() {}) | ||
}) | ||
Ω(success).Should(BeTrue()) | ||
}) | ||
|
||
It("adds-no-entries", func() {}) | ||
It("attaches entries to the report", func() { | ||
Ω(reporter.Did.Find("adds-entries").ReportEntries[0].Name).Should(Equal("medical")) | ||
Ω(reporter.Did.Find("adds-entries").ReportEntries[0].Value.String()).Should(Equal("healthy")) | ||
Ω(reporter.Did.Find("adds-entries").ReportEntries[1].Name).Should(Equal("engineering")) | ||
Ω(reporter.Did.Find("adds-entries").ReportEntries[1].Value.String()).Should(Equal("on fire")) | ||
Ω(reporter.Did.Find("adds-no-entries").ReportEntries).Should(BeEmpty()) | ||
Ω(reporter.Did.FindByLeafNodeType(types.NodeTypeBeforeSuite).ReportEntries[0].Name).Should(Equal("bridge")) | ||
Ω(reporter.Did.FindByLeafNodeType(types.NodeTypeBeforeSuite).ReportEntries[0].Value.String()).Should(Equal("engaged")) | ||
}) | ||
Ω(success).Should(BeTrue()) | ||
}) | ||
|
||
It("attaches entries to the report", func() { | ||
Ω(reporter.Did.Find("adds-entries").ReportEntries[0].Name).Should(Equal("medical")) | ||
Ω(reporter.Did.Find("adds-entries").ReportEntries[0].Value.String()).Should(Equal("healthy")) | ||
Ω(reporter.Did.Find("adds-entries").ReportEntries[1].Name).Should(Equal("engineering")) | ||
Ω(reporter.Did.Find("adds-entries").ReportEntries[1].Value.String()).Should(Equal("on fire")) | ||
Ω(reporter.Did.Find("adds-no-entries").ReportEntries).Should(BeEmpty()) | ||
Ω(reporter.Did.FindByLeafNodeType(types.NodeTypeBeforeSuite).ReportEntries[0].Name).Should(Equal("bridge")) | ||
Ω(reporter.Did.FindByLeafNodeType(types.NodeTypeBeforeSuite).ReportEntries[0].Value.String()).Should(Equal("engaged")) | ||
Context("avoiding races", func() { | ||
BeforeEach(func() { | ||
success, _ := RunFixture("Report Entries - but no races", func() { | ||
BeforeEach(func() { | ||
stop := make(chan interface{}) | ||
done := make(chan interface{}) | ||
ticker := time.NewTicker(10 * time.Millisecond) | ||
i := 0 | ||
go func() { | ||
for { | ||
select { | ||
case <-ticker.C: | ||
AddReportEntry(fmt.Sprintf("report-%d", i)) | ||
i++ | ||
case <-stop: | ||
ticker.Stop() | ||
close(done) | ||
return | ||
} | ||
} | ||
}() | ||
DeferCleanup(func() { | ||
close(stop) | ||
<-done | ||
}) | ||
}) | ||
|
||
It("reporter", func() { | ||
for i := 0; i < 5; i++ { | ||
time.Sleep(20 * time.Millisecond) | ||
AddReportEntry(fmt.Sprintf("waiting... %d", i)) | ||
Ω(len(CurrentSpecReport().ReportEntries)).Should(BeNumerically("<", (i+1)*10)) | ||
} | ||
}) | ||
|
||
ReportAfterEach(func(report SpecReport) { | ||
//no races here, either | ||
Ω(len(report.ReportEntries)).Should(BeNumerically(">", 5)) | ||
}) | ||
|
||
}) | ||
Ω(success).Should(BeTrue()) | ||
}) | ||
|
||
It("attaches entries without racing", func() { | ||
Ω(reporter.Did.Find("reporter").ReportEntries).Should(ContainElement(HaveField("Name", "report-0"))) | ||
Ω(reporter.Did.Find("reporter").ReportEntries).Should(ContainElement(HaveField("Name", "report-2"))) | ||
Ω(reporter.Did.Find("reporter").ReportEntries).Should(ContainElement(HaveField("Name", "waiting... 1"))) | ||
Ω(reporter.Did.Find("reporter").ReportEntries).Should(ContainElement(HaveField("Name", "waiting... 3"))) | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters