File: serial_test.go

package info (click to toggle)
golang-github-onsi-ginkgo-v2 2.15.0-1~bpo12%2B1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm-backports
  • size: 4,112 kB
  • sloc: javascript: 59; sh: 14; makefile: 7
file content (81 lines) | stat: -rw-r--r-- 2,537 bytes parent folder | download | duplicates (2)
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
package internal_integration_test

import (
	"time"

	. "github.com/onsi/ginkgo/v2"
	. "github.com/onsi/ginkgo/v2/internal/test_helpers"
	. "github.com/onsi/gomega"
)

var _ = Describe("Serial", func() {
	var fixture func()
	BeforeEach(func() {
		fixture = func() {
			Context("container", func() {
				It("A", rt.T("A", func() { time.Sleep(10 * time.Millisecond) }))
				It("B", rt.T("B", func() { time.Sleep(10 * time.Millisecond) }))
				It("C", Serial, rt.T("C", func() { time.Sleep(10 * time.Millisecond) }))
				It("D", rt.T("D", func() { time.Sleep(10 * time.Millisecond) }))
				It("E", rt.T("E", func() { time.Sleep(10 * time.Millisecond) }))
				It("F", Serial, rt.T("F", func() { time.Sleep(10 * time.Millisecond) }))
				It("G", rt.T("G", func() { time.Sleep(10 * time.Millisecond) }))
				It("H", Serial, rt.T("H", func() { time.Sleep(10 * time.Millisecond) }))
			})
		}
	})

	Context("when running in series", func() {
		BeforeEach(func() {
			conf.ParallelTotal = 1
			conf.ParallelProcess = 1
			success, _ := RunFixture("in-series", fixture)
			Ω(success).Should(BeTrue())
		})

		It("runs and reports on all the tests", func() {
			Ω(rt).Should(HaveTracked("A", "B", "C", "D", "E", "F", "G", "H"))
			Ω(reporter.Did.Names()).Should(Equal([]string{"A", "B", "C", "D", "E", "F", "G", "H"}))
		})
	})

	Context("when running in parallel", func() {
		BeforeEach(func() {
			SetUpForParallel(2)
		})

		Describe("when running as proc 1", func() {
			BeforeEach(func() {
				conf.ParallelProcess = 1
			})

			It("participates in running parallel tests, then runs the serial tests after all other procs have finished", func() {
				done := make(chan interface{})
				go func() {
					defer GinkgoRecover()
					success, _ := RunFixture("happy-path", fixture)
					Ω(success).Should(BeTrue())
					close(done)
				}()
				Eventually(rt).Should(HaveTracked("A", "B", "D", "E", "G"))
				Consistently(rt, 100*time.Millisecond).Should(HaveTracked("A", "B", "D", "E", "G"))
				close(exitChannels[2])
				Eventually(rt).Should(HaveTracked("A", "B", "D", "E", "G", "C", "F", "H"))
				Eventually(done).Should(BeClosed())
			})
		})

		Describe("when running as a non-primary proc", func() {
			BeforeEach(func() {
				conf.ParallelProcess = 2
			})

			It("participates in running parallel tests, but never runs the serial tests", func() {
				close(exitChannels[1])
				success, _ := RunFixture("happy-path", fixture)
				Ω(success).Should(BeTrue())
				Ω(rt).Should(HaveTracked("A", "B", "D", "E", "G"))
			})
		})
	})
})