github.com/onsi/ginkgo@v1.16.6-0.20211118180735-4e1925ba4c95/internal/internal_integration/serial_test.go (about)

     1  package internal_integration_test
     2  
     3  import (
     4  	"time"
     5  
     6  	. "github.com/onsi/ginkgo"
     7  	. "github.com/onsi/ginkgo/internal/test_helpers"
     8  	. "github.com/onsi/gomega"
     9  )
    10  
    11  var _ = Describe("Serial", func() {
    12  	var fixture func()
    13  	BeforeEach(func() {
    14  		fixture = func() {
    15  			Context("container", func() {
    16  				It("A", rt.T("A", func() { time.Sleep(10 * time.Millisecond) }))
    17  				It("B", rt.T("B", func() { time.Sleep(10 * time.Millisecond) }))
    18  				It("C", Serial, rt.T("C", func() { time.Sleep(10 * time.Millisecond) }))
    19  				It("D", rt.T("D", func() { time.Sleep(10 * time.Millisecond) }))
    20  				It("E", rt.T("E", func() { time.Sleep(10 * time.Millisecond) }))
    21  				It("F", Serial, rt.T("F", func() { time.Sleep(10 * time.Millisecond) }))
    22  				It("G", rt.T("G", func() { time.Sleep(10 * time.Millisecond) }))
    23  				It("H", Serial, rt.T("H", func() { time.Sleep(10 * time.Millisecond) }))
    24  			})
    25  		}
    26  	})
    27  
    28  	Context("when running in series", func() {
    29  		BeforeEach(func() {
    30  			conf.ParallelTotal = 1
    31  			conf.ParallelProcess = 1
    32  			success, _ := RunFixture("in-series", fixture)
    33  			Ω(success).Should(BeTrue())
    34  		})
    35  
    36  		It("runs and reports on all the tests", func() {
    37  			Ω(rt).Should(HaveTracked("A", "B", "C", "D", "E", "F", "G", "H"))
    38  			Ω(reporter.Did.Names()).Should(Equal([]string{"A", "B", "C", "D", "E", "F", "G", "H"}))
    39  		})
    40  	})
    41  
    42  	Context("when running in parallel", func() {
    43  		BeforeEach(func() {
    44  			SetUpForParallel(2)
    45  		})
    46  
    47  		Describe("when running as proc 1", func() {
    48  			BeforeEach(func() {
    49  				conf.ParallelProcess = 1
    50  			})
    51  
    52  			It("participates in running parallel tests, then runs the serial tests after all other procs have finished", func() {
    53  				done := make(chan interface{})
    54  				go func() {
    55  					defer GinkgoRecover()
    56  					success, _ := RunFixture("happy-path", fixture)
    57  					Ω(success).Should(BeTrue())
    58  					close(done)
    59  				}()
    60  				Eventually(rt).Should(HaveTracked("A", "B", "D", "E", "G"))
    61  				Consistently(rt, 100*time.Millisecond).Should(HaveTracked("A", "B", "D", "E", "G"))
    62  				close(exitChannels[2])
    63  				Eventually(rt).Should(HaveTracked("A", "B", "D", "E", "G", "C", "F", "H"))
    64  				Eventually(done).Should(BeClosed())
    65  			})
    66  		})
    67  
    68  		Describe("when running as a non-primary proc", func() {
    69  			BeforeEach(func() {
    70  				conf.ParallelProcess = 2
    71  			})
    72  
    73  			It("participates in running parallel tests, but never runs the serial tests", func() {
    74  				close(exitChannels[1])
    75  				success, _ := RunFixture("happy-path", fixture)
    76  				Ω(success).Should(BeTrue())
    77  				Ω(rt).Should(HaveTracked("A", "B", "D", "E", "G"))
    78  			})
    79  		})
    80  	})
    81  })