...

Source file src/github.com/onsi/ginkgo/v2/integration/suite_setup_test.go

Documentation: github.com/onsi/ginkgo/v2/integration

     1  package integration_test
     2  
     3  import (
     4  	"strings"
     5  
     6  	. "github.com/onsi/ginkgo/v2"
     7  	. "github.com/onsi/gomega"
     8  	"github.com/onsi/gomega/gexec"
     9  )
    10  
    11  var _ = Describe("SuiteSetup", func() {
    12  	Context("With passing synchronized before and after suites", func() {
    13  		BeforeEach(func() {
    14  			fm.MountFixture("synchronized_setup_tests")
    15  		})
    16  
    17  		Context("when run with one proc", func() {
    18  			It("should do all the work on that one proc", func() {
    19  				session := startGinkgo(fm.PathTo("synchronized_setup_tests"), "--no-color")
    20  				Eventually(session).Should(gexec.Exit(0))
    21  				output := string(session.Out.Contents())
    22  
    23  				Ω(output).Should(ContainSubstring("BEFORE_A_1\nBEFORE_B_1: DATA"))
    24  				Ω(output).Should(ContainSubstring("AFTER_A_1\nAFTER_B_1"))
    25  			})
    26  		})
    27  
    28  		Context("when run across multiple procs", func() {
    29  			It("should run the first BeforeSuite function (BEFORE_A) on proc 1, the second (BEFORE_B) on all the procs, the first AfterSuite (AFTER_A) on all the procs, and then the second (AFTER_B) on Node 1 *after* everything else is finished", func() {
    30  				session := startGinkgo(fm.PathTo("synchronized_setup_tests"), "--no-color", "--procs=3")
    31  				Eventually(session).Should(gexec.Exit(0))
    32  				output := string(session.Out.Contents())
    33  
    34  				numOccurrences := 0
    35  				for _, line := range strings.Split(output, "\n") {
    36  					occurs, _ := ContainSubstring("BEFORE_A_1").Match(line)
    37  					if occurs {
    38  						numOccurrences += 1
    39  					}
    40  				}
    41  				Ω(numOccurrences).Should(Equal(2)) // once when it's emitted because it's in the synchronizedBeforeSuite proc.  And once again when it's captured in the spec report that includes the stdout output.
    42  
    43  				numOccurrences = 0
    44  				for _, line := range strings.Split(output, "\n") {
    45  					occurs, _ := ContainSubstring("AFTER_B_1").Match(line)
    46  					if occurs {
    47  						numOccurrences += 1
    48  					}
    49  				}
    50  				Ω(numOccurrences).Should(Equal(2)) // once when it's emitted because it's in the synchronizedAfterSuite proc.  And once again when it's captured in the spec report that includes the stdout output.
    51  
    52  				Ω(output).Should(ContainSubstring("BEFORE_A_1"))
    53  				Ω(output).Should(ContainSubstring("BEFORE_B_1: DATA"))
    54  				Ω(output).Should(ContainSubstring("BEFORE_B_2: DATA"))
    55  				Ω(output).Should(ContainSubstring("BEFORE_B_3: DATA"))
    56  
    57  				Ω(output).ShouldNot(ContainSubstring("BEFORE_A_2"))
    58  				Ω(output).ShouldNot(ContainSubstring("BEFORE_A_3"))
    59  
    60  				Ω(output).Should(ContainSubstring("AFTER_A_1"))
    61  				Ω(output).Should(ContainSubstring("AFTER_A_2"))
    62  				Ω(output).Should(ContainSubstring("AFTER_A_3"))
    63  				Ω(output).Should(ContainSubstring("AFTER_B_1"))
    64  
    65  				Ω(output).ShouldNot(ContainSubstring("AFTER_B_2"))
    66  				Ω(output).ShouldNot(ContainSubstring("AFTER_B_3"))
    67  			})
    68  		})
    69  	})
    70  
    71  	Context("With a failing synchronized before suite", func() {
    72  		BeforeEach(func() {
    73  			fm.MountFixture("exiting_synchronized_setup")
    74  		})
    75  
    76  		It("should fail and let the user know that proc 1 disappeared prematurely", func() {
    77  			session := startGinkgo(fm.PathTo("exiting_synchronized_setup"), "--no-color", "--procs=3")
    78  			Eventually(session).Should(gexec.Exit(1))
    79  			output := string(session.Out.Contents()) + string(session.Err.Contents())
    80  
    81  			Ω(output).Should(ContainSubstring("Process #1 disappeared before SynchronizedBeforeSuite could report back"))
    82  			Ω(output).Should(ContainSubstring("Ginkgo timed out waiting for all parallel procs to report back"))
    83  		})
    84  	})
    85  })
    86  

View as plain text