-
Notifications
You must be signed in to change notification settings - Fork 5
/
event_stream_test.go
67 lines (56 loc) · 1.78 KB
/
event_stream_test.go
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
package vizzini_test
import (
"sync"
"code.cloudfoundry.org/bbs/events"
"code.cloudfoundry.org/bbs/models"
. "code.cloudfoundry.org/vizzini/matchers"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
)
var _ = Describe("EventStream", func() {
var desiredLRP *models.DesiredLRP
var eventSource events.EventSource
var done chan struct{}
var lock *sync.Mutex
var events []models.Event
getEvents := func() []models.Event {
lock.Lock()
defer lock.Unlock()
return events
}
BeforeEach(func() {
var err error
desiredLRP = DesiredLRPWithGuid(guid)
eventSource, err = bbsClient.SubscribeToInstanceEvents(logger)
Expect(err).NotTo(HaveOccurred())
done = make(chan struct{})
lock = &sync.Mutex{}
events = []models.Event{}
go func() {
for {
event, err := eventSource.Next()
if err != nil {
close(done)
return
}
lock.Lock()
events = append(events, event)
lock.Unlock()
}
}()
})
AfterEach(func() {
eventSource.Close()
Eventually(done).Should(BeClosed())
})
It("should receive events as the LRP goes through its lifecycle", func() {
bbsClient.DesireLRP(logger, traceID, desiredLRP)
Eventually(getEvents).Should(ContainElement(MatchDesiredLRPCreatedEvent(guid)))
Eventually(getEvents).Should(ContainElement(MatchActualLRPInstanceCreatedEvent(guid, 0)))
Eventually(getEvents).Should(ContainElement(MatchActualLRPInstanceChangedEvent(guid, 0, models.ActualLRPStateClaimed)))
Eventually(getEvents).Should(ContainElement(MatchActualLRPInstanceChangedEvent(guid, 0, models.ActualLRPStateRunning)))
bbsClient.RemoveDesiredLRP(logger, traceID, guid)
Eventually(getEvents).Should(ContainElement(MatchDesiredLRPRemovedEvent(guid)))
Eventually(getEvents).Should(ContainElement(MatchActualLRPInstanceRemovedEvent(guid, 0)))
})
})