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
|
package leafnodes_test
import (
. "github.com/onsi/ginkgo"
. "github.com/onsi/ginkgo/internal/leafnodes"
"github.com/onsi/ginkgo/types"
. "github.com/onsi/gomega"
"sync"
"github.com/onsi/gomega/ghttp"
"net/http"
"github.com/onsi/ginkgo/internal/codelocation"
Failer "github.com/onsi/ginkgo/internal/failer"
"time"
)
var _ = Describe("SynchronizedAfterSuiteNode", func() {
var failer *Failer.Failer
var node SuiteNode
var codeLocation types.CodeLocation
var innerCodeLocation types.CodeLocation
var outcome bool
var server *ghttp.Server
var things []string
var lock *sync.Mutex
BeforeEach(func() {
things = []string{}
server = ghttp.NewServer()
codeLocation = codelocation.New(0)
innerCodeLocation = codelocation.New(0)
failer = Failer.New()
lock = &sync.Mutex{}
})
AfterEach(func() {
server.Close()
})
newNode := func(bodyA interface{}, bodyB interface{}) SuiteNode {
return NewSynchronizedAfterSuiteNode(bodyA, bodyB, codeLocation, time.Millisecond, failer)
}
ranThing := func(thing string) {
lock.Lock()
defer lock.Unlock()
things = append(things, thing)
}
thingsThatRan := func() []string {
lock.Lock()
defer lock.Unlock()
return things
}
Context("when not running in parallel", func() {
Context("when all is well", func() {
BeforeEach(func() {
node = newNode(func() {
ranThing("A")
}, func() {
ranThing("B")
})
outcome = node.Run(1, 1, server.URL())
})
It("should run A, then B", func() {
Ω(thingsThatRan()).Should(Equal([]string{"A", "B"}))
})
It("should report success", func() {
Ω(outcome).Should(BeTrue())
Ω(node.Passed()).Should(BeTrue())
Ω(node.Summary().State).Should(Equal(types.SpecStatePassed))
})
})
Context("when A fails", func() {
BeforeEach(func() {
node = newNode(func() {
ranThing("A")
failer.Fail("bam", innerCodeLocation)
}, func() {
ranThing("B")
})
outcome = node.Run(1, 1, server.URL())
})
It("should still run B", func() {
Ω(thingsThatRan()).Should(Equal([]string{"A", "B"}))
})
It("should report failure", func() {
Ω(outcome).Should(BeFalse())
Ω(node.Passed()).Should(BeFalse())
Ω(node.Summary().State).Should(Equal(types.SpecStateFailed))
})
})
Context("when B fails", func() {
BeforeEach(func() {
node = newNode(func() {
ranThing("A")
}, func() {
ranThing("B")
failer.Fail("bam", innerCodeLocation)
})
outcome = node.Run(1, 1, server.URL())
})
It("should run all the things", func() {
Ω(thingsThatRan()).Should(Equal([]string{"A", "B"}))
})
It("should report failure", func() {
Ω(outcome).Should(BeFalse())
Ω(node.Passed()).Should(BeFalse())
Ω(node.Summary().State).Should(Equal(types.SpecStateFailed))
})
})
})
Context("when running in parallel", func() {
Context("as the first node", func() {
BeforeEach(func() {
server.AppendHandlers(ghttp.CombineHandlers(
ghttp.VerifyRequest("GET", "/RemoteAfterSuiteData"),
func(writer http.ResponseWriter, request *http.Request) {
ranThing("Request1")
},
ghttp.RespondWithJSONEncoded(200, types.RemoteAfterSuiteData{false}),
), ghttp.CombineHandlers(
ghttp.VerifyRequest("GET", "/RemoteAfterSuiteData"),
func(writer http.ResponseWriter, request *http.Request) {
ranThing("Request2")
},
ghttp.RespondWithJSONEncoded(200, types.RemoteAfterSuiteData{false}),
), ghttp.CombineHandlers(
ghttp.VerifyRequest("GET", "/RemoteAfterSuiteData"),
func(writer http.ResponseWriter, request *http.Request) {
ranThing("Request3")
},
ghttp.RespondWithJSONEncoded(200, types.RemoteAfterSuiteData{true}),
))
node = newNode(func() {
ranThing("A")
}, func() {
ranThing("B")
})
outcome = node.Run(1, 3, server.URL())
})
It("should run A and, when the server says its time, run B", func() {
Ω(thingsThatRan()).Should(Equal([]string{"A", "Request1", "Request2", "Request3", "B"}))
})
It("should report success", func() {
Ω(outcome).Should(BeTrue())
Ω(node.Passed()).Should(BeTrue())
Ω(node.Summary().State).Should(Equal(types.SpecStatePassed))
})
})
Context("as any other node", func() {
BeforeEach(func() {
node = newNode(func() {
ranThing("A")
}, func() {
ranThing("B")
})
outcome = node.Run(2, 3, server.URL())
})
It("should run A, and not run B", func() {
Ω(thingsThatRan()).Should(Equal([]string{"A"}))
})
It("should not talk to the server", func() {
Ω(server.ReceivedRequests()).Should(BeEmpty())
})
It("should report success", func() {
Ω(outcome).Should(BeTrue())
Ω(node.Passed()).Should(BeTrue())
Ω(node.Summary().State).Should(Equal(types.SpecStatePassed))
})
})
})
})
|