1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411
|
package internal_integration_test
import (
"time"
. "github.com/onsi/ginkgo/v2"
"github.com/onsi/ginkgo/v2/internal/interrupt_handler"
. "github.com/onsi/ginkgo/v2/internal/test_helpers"
"github.com/onsi/ginkgo/v2/types"
. "github.com/onsi/gomega"
)
var _ = Describe("Sending reports to ReportBeforeSuite and ReportAfterSuite nodes", func() {
var failInReportBeforeSuiteA, failInReportAfterSuiteA, interruptSuiteB bool
var fixture func()
BeforeEach(func() {
failInReportBeforeSuiteA = false
failInReportAfterSuiteA = false
interruptSuiteB = false
conf.RandomSeed = 17
fixture = func() {
BeforeSuite(rt.T("before-suite", func() {
outputInterceptor.AppendInterceptedOutput("out-before-suite")
}))
ReportBeforeSuite(func(report Report) {
rt.RunWithData("report-before-suite-A", "report", report)
writer.Print("gw-report-before-suite-A")
outputInterceptor.AppendInterceptedOutput("out-report-before-suite-A")
if failInReportBeforeSuiteA {
F("fail in report-before-suite-A")
}
})
ReportBeforeSuite(func(report Report) {
rt.RunWithData("report-before-suite-B", "report", report)
writer.Print("gw-report-before-suite-B")
outputInterceptor.AppendInterceptedOutput("out-report-before-suite-B")
})
Context("container", func() {
It("A", rt.T("A"))
It("B", rt.T("B", func() {
F("fail in B")
}))
It("C", rt.T("C"))
PIt("D", rt.T("D"))
})
ReportAfterSuite("Report A", func(report Report) {
rt.RunWithData("report-after-suite-A", "report", report)
writer.Print("gw-report-after-suite-A")
outputInterceptor.AppendInterceptedOutput("out-report-after-suite-A")
if failInReportAfterSuiteA {
F("fail in report-after-suite-A")
}
})
ReportAfterSuite("Report B", func(report Report) {
if interruptSuiteB {
interruptHandler.Interrupt(interrupt_handler.InterruptCauseSignal)
time.Sleep(time.Hour)
}
rt.RunWithData("report-after-suite-B", "report", report)
writer.Print("gw-report-after-suite-B")
outputInterceptor.AppendInterceptedOutput("out-report-after-suite-B")
})
AfterSuite(rt.T("after-suite", func() {
writer.Print("gw-after-suite")
F("fail in after-suite")
}))
}
})
Context("when running in series", func() {
BeforeEach(func() {
conf.ParallelTotal = 1
conf.ParallelProcess = 1
})
Context("the happy path", func() {
BeforeEach(func() {
success, _ := RunFixture("happy-path", fixture)
Ω(success).Should(BeFalse())
})
It("runs all the functions", func() {
Ω(rt).Should(HaveTracked(
"report-before-suite-A", "report-before-suite-B",
"before-suite",
"A", "B", "C",
"after-suite",
"report-after-suite-A", "report-after-suite-B",
))
})
It("reports on the report procs", func() {
Ω(reporter.Did.FindByLeafNodeType(types.NodeTypeReportBeforeSuite)).Should(HavePassed(
types.NodeTypeReportBeforeSuite,
CapturedGinkgoWriterOutput("gw-report-before-suite-A"),
CapturedStdOutput("out-report-before-suite-A"),
))
Ω(reporter.Did.Find("Report A")).Should(HavePassed(
types.NodeTypeReportAfterSuite,
CapturedGinkgoWriterOutput("gw-report-after-suite-A"),
CapturedStdOutput("out-report-after-suite-A"),
))
Ω(reporter.Did.Find("Report B")).Should(HavePassed(
types.NodeTypeReportAfterSuite,
CapturedGinkgoWriterOutput("gw-report-after-suite-B"),
CapturedStdOutput("out-report-after-suite-B"),
))
})
It("passes the report in to each ReportBeforeSuite", func() {
reportA := rt.DataFor("report-before-suite-A")["report"].(types.Report)
reportB := rt.DataFor("report-before-suite-B")["report"].(types.Report)
for _, report := range []types.Report{reportA, reportB} {
Ω(report.SuiteDescription).Should(Equal("happy-path"))
Ω(report.SuiteSucceeded).Should(BeTrue())
Ω(report.SuiteConfig.RandomSeed).Should(Equal(int64(17)))
Ω(report.PreRunStats.SpecsThatWillRun).Should(Equal(3))
Ω(report.PreRunStats.TotalSpecs).Should(Equal(4))
}
Ω(len(reportB.SpecReports)-len(reportA.SpecReports)).Should(Equal(1), "Report B includes the invocation of ReportAfterSuite A")
Ω(Reports(reportB.SpecReports).FindByLeafNodeType(types.NodeTypeReportBeforeSuite)).Should(Equal(reporter.Did.FindByLeafNodeType(types.NodeTypeReportBeforeSuite)))
})
It("passes the report in to each ReportAfterSuite", func() {
reportA := rt.DataFor("report-after-suite-A")["report"].(types.Report)
reportB := rt.DataFor("report-after-suite-B")["report"].(types.Report)
for _, report := range []types.Report{reportA, reportB} {
Ω(report.SuiteDescription).Should(Equal("happy-path"))
Ω(report.SuiteSucceeded).Should(BeFalse())
Ω(report.SuiteConfig.RandomSeed).Should(Equal(int64(17)))
reports := Reports(report.SpecReports)
Ω(reports.FindByLeafNodeType(types.NodeTypeBeforeSuite)).Should(HavePassed(CapturedStdOutput("out-before-suite")))
Ω(reports.Find("A")).Should(HavePassed())
Ω(reports.Find("B")).Should(HaveFailed("fail in B"))
Ω(reports.Find("C")).Should(HavePassed())
Ω(reports.Find("D")).Should(BePending())
Ω(reports.FindByLeafNodeType(types.NodeTypeAfterSuite)).Should(HaveFailed("fail in after-suite", CapturedGinkgoWriterOutput("gw-after-suite")))
}
Ω(len(reportB.SpecReports)-len(reportA.SpecReports)).Should(Equal(1), "Report B includes the invocation of ReportAfterSuite A")
Ω(Reports(reportB.SpecReports).Find("Report A")).Should(Equal(reporter.Did.Find("Report A")))
})
})
Context("when a ReportBeforeSuite node fails", func() {
BeforeEach(func() {
failInReportBeforeSuiteA = true
success, _ := RunFixture("report-before-suite-A-fails", fixture)
Ω(success).Should(BeFalse())
})
It("doesn't run any specs - just reporting functions", func() {
Ω(rt).Should(HaveTracked(
"report-before-suite-A", "report-before-suite-B",
"report-after-suite-A", "report-after-suite-B",
))
})
It("reports on the failure, to Ginkgo's reporter and any subsequent reporters", func() {
Ω(reporter.Did.FindByLeafNodeType(types.NodeTypeReportBeforeSuite)).Should(HaveFailed(
types.NodeTypeReportBeforeSuite,
"fail in report-before-suite-A",
CapturedGinkgoWriterOutput("gw-report-before-suite-A"),
CapturedStdOutput("out-report-before-suite-A"),
))
reportB := rt.DataFor("report-before-suite-B")["report"].(types.Report)
Ω(Reports(reportB.SpecReports).FindByLeafNodeType(types.NodeTypeReportBeforeSuite)).Should(Equal(reporter.Did.FindByLeafNodeType(types.NodeTypeReportBeforeSuite)))
})
})
Context("when a ReportAfterSuite node fails", func() {
BeforeEach(func() {
failInReportAfterSuiteA = true
success, _ := RunFixture("report-after-suite-A-fails", fixture)
Ω(success).Should(BeFalse())
})
It("keeps running subseuqent reporting functions", func() {
Ω(rt).Should(HaveTracked(
"report-before-suite-A", "report-before-suite-B",
"before-suite",
"A", "B", "C",
"after-suite",
"report-after-suite-A", "report-after-suite-B",
))
})
It("reports on the failure, to Ginkgo's reporter and any subsequent reporters", func() {
Ω(reporter.Did.Find("Report A")).Should(HaveFailed(
types.NodeTypeReportAfterSuite,
"fail in report-after-suite-A",
CapturedGinkgoWriterOutput("gw-report-after-suite-A"),
CapturedStdOutput("out-report-after-suite-A"),
))
reportB := rt.DataFor("report-after-suite-B")["report"].(types.Report)
Ω(Reports(reportB.SpecReports).Find("Report A")).Should(Equal(reporter.Did.Find("Report A")))
})
})
Context("when an interrupt is attempted in a ReportAfterSuiteNode", func() {
BeforeEach(func() {
interruptSuiteB = true
success, _ := RunFixture("report-after-suite-B-interrupted", fixture)
Ω(success).Should(BeFalse())
})
It("interrupts and bails", func() {
Ω(rt).Should(HaveTracked(
"report-before-suite-A", "report-before-suite-B",
"before-suite",
"A", "B", "C",
"after-suite",
"report-after-suite-A",
))
})
})
})
Context("when running in parallel", func() {
var otherNodeReport types.Report
BeforeEach(func() {
SetUpForParallel(2)
otherNodeReport = types.Report{
SpecReports: types.SpecReports{
types.SpecReport{LeafNodeText: "E", LeafNodeLocation: cl, State: types.SpecStatePassed, LeafNodeType: types.NodeTypeIt},
types.SpecReport{LeafNodeText: "F", LeafNodeLocation: cl, State: types.SpecStateSkipped, LeafNodeType: types.NodeTypeIt},
},
}
})
Context("on proc 1", func() {
BeforeEach(func() {
conf.ParallelProcess = 1
})
Context("the happy path", func() {
BeforeEach(func() {
// proc 2 has reported back and exited
client.PostSuiteDidEnd(otherNodeReport)
close(exitChannels[2])
success, _ := RunFixture("happy-path", fixture)
Ω(success).Should(BeFalse())
})
It("runs all the functions", func() {
Ω(rt).Should(HaveTracked(
"report-before-suite-A", "report-before-suite-B",
"before-suite",
"A", "B", "C",
"after-suite",
"report-after-suite-A", "report-after-suite-B",
))
})
It("passes the report in to each reporter, including information from other procs", func() {
reportA := rt.DataFor("report-after-suite-A")["report"].(types.Report)
reportB := rt.DataFor("report-after-suite-B")["report"].(types.Report)
for _, report := range []types.Report{reportA, reportB} {
Ω(report.SuiteDescription).Should(Equal("happy-path"))
Ω(report.SuiteSucceeded).Should(BeFalse())
reports := Reports(report.SpecReports)
Ω(reports.FindByLeafNodeType(types.NodeTypeBeforeSuite)).Should(HavePassed(CapturedStdOutput("out-before-suite")))
Ω(reports.Find("A")).Should(HavePassed())
Ω(reports.Find("B")).Should(HaveFailed("fail in B"))
Ω(reports.Find("C")).Should(HavePassed())
Ω(reports.Find("D")).Should(BePending())
Ω(reports.Find("E")).Should(HavePassed())
Ω(reports.Find("F")).Should(HaveBeenSkipped())
Ω(reports.FindByLeafNodeType(types.NodeTypeAfterSuite)).Should(HaveFailed("fail in after-suite", CapturedGinkgoWriterOutput("gw-after-suite")))
}
Ω(len(reportB.SpecReports)-len(reportA.SpecReports)).Should(Equal(1), "Report B includes the invocation of ReportAfterSuite A")
Ω(Reports(reportB.SpecReports).Find("Report A")).Should(Equal(reporter.Did.Find("Report A")))
})
It("tells the other procs that the ReportBeforeSuite has completed", func() {
Ω(client.BlockUntilReportBeforeSuiteCompleted()).Should(Equal(types.SpecStatePassed))
})
})
Describe("waiting for reports from other procs", func() {
It("blocks until the other procs have finished", func() {
done := make(chan interface{})
go func() {
defer GinkgoRecover()
success, _ := RunFixture("happy-path", fixture)
Ω(success).Should(BeFalse())
close(done)
}()
Consistently(done).ShouldNot(BeClosed())
client.PostSuiteDidEnd(otherNodeReport)
Consistently(done).ShouldNot(BeClosed())
close(exitChannels[2])
Eventually(done).Should(BeClosed())
})
})
Context("when a non-primary proc disappears before it reports", func() {
BeforeEach(func() {
close(exitChannels[2]) //proc 2 disappears before reporting
success, _ := RunFixture("disappearing-proc-2", fixture)
Ω(success).Should(BeFalse())
})
It("does not run the ReportAfterSuite procs", func() {
Ω(rt).Should(HaveTracked(
"report-before-suite-A", "report-before-suite-B",
"before-suite",
"A", "B", "C",
"after-suite",
))
})
It("reports all the ReportAfterSuite procs as failed", func() {
Ω(reporter.Did.Find("Report A")).Should(HaveFailed(types.GinkgoErrors.AggregatedReportUnavailableDueToNodeDisappearing().Error()))
Ω(reporter.Did.Find("Report B")).Should(HaveFailed(types.GinkgoErrors.AggregatedReportUnavailableDueToNodeDisappearing().Error()))
})
})
Context("when a ReportBeforeSuite fails", func() {
BeforeEach(func() {
// proc 2 has reported back and exited
client.PostSuiteDidEnd(otherNodeReport)
close(exitChannels[2])
failInReportBeforeSuiteA = true
success, _ := RunFixture("failure-in-report-before-suite-A", fixture)
Ω(success).Should(BeFalse())
})
It("only runs the reporting nodes", func() {
Ω(rt).Should(HaveTracked(
"report-before-suite-A", "report-before-suite-B",
"report-after-suite-A", "report-after-suite-B",
))
})
It("tells the other procs that the ReportBeforeSuite failed", func() {
Ω(client.BlockUntilReportBeforeSuiteCompleted()).Should(Equal(types.SpecStateFailed))
})
})
})
Context("on a non-primary proc", func() {
var done chan interface{}
BeforeEach(func() {
done = make(chan interface{})
go func() {
conf.ParallelProcess = 2
success, _ := RunFixture("non-primary proc", fixture)
Ω(success).Should(BeFalse())
close(done)
}()
Consistently(done).ShouldNot(BeClosed())
Ω(rt).Should(HaveTrackedNothing(), "Nothing should run until we are cleared to go by proc1")
})
Context("the happy path", func() {
BeforeEach(func() {
// proc1 signals that its ReportBeforeSuites succeeded
client.PostReportBeforeSuiteCompleted(types.SpecStatePassed)
Eventually(done).Should(BeClosed())
})
It("does not run anything until the primary node finishes running the BeforeSuite node, then it runs the specs", func() {
Ω(rt).Should(HaveTracked(
"before-suite",
"A", "B", "C",
"after-suite",
))
})
})
Context("when the ReportBeforeSuite node fails", func() {
BeforeEach(func() {
// proc1 signals that its ReportBeforeSuites failed
client.PostReportBeforeSuiteCompleted(types.SpecStateFailed)
Eventually(done).Should(BeClosed())
})
It("does not run anything until it is notified of the failure, then it just exits without running anything", func() {
Ω(rt).Should(HaveTrackedNothing())
})
})
Context("when proc1 exits before reporting", func() {
BeforeEach(func() {
// proc1 signals that its ReportBeforeSuites failed
close(exitChannels[1])
Eventually(done).Should(BeClosed())
})
It("does not run anything until it is notified of the failure, then it just exits without running anything", func() {
Ω(rt).Should(HaveTrackedNothing())
})
})
})
})
})
|