wrote embassy journal emissions
This commit is contained in:
+102
@@ -50,6 +50,8 @@ func TestEmbassyPoolEvents(t *testing.T) {
|
||||
})
|
||||
|
||||
t.Run("connected", func(t *testing.T) {
|
||||
e.Dispatch("wss://test")
|
||||
|
||||
eventsCh <- honeybee.OutboundPoolEvent{
|
||||
ID: "wss://test",
|
||||
Kind: honeybee.OutboundEventConnected,
|
||||
@@ -67,6 +69,8 @@ func TestEmbassyPoolEvents(t *testing.T) {
|
||||
})
|
||||
|
||||
t.Run("disconnected", func(t *testing.T) {
|
||||
e.Dispatch("wss://test")
|
||||
|
||||
eventsCh <- honeybee.OutboundPoolEvent{
|
||||
ID: "wss://test",
|
||||
Kind: honeybee.OutboundEventDisconnected,
|
||||
@@ -243,3 +247,101 @@ func TestEmbassyClose(t *testing.T) {
|
||||
return !ok1 && !ok2
|
||||
}, "subs should close")
|
||||
}
|
||||
|
||||
func TestEmbassyJournals(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
jc := NewJournalCollector()
|
||||
eventsCh := make(chan honeybee.OutboundPoolEvent, 1)
|
||||
|
||||
pool := EmbassyPlugin{
|
||||
Connect: func(id string) error { return nil },
|
||||
Remove: func(id string) error { return nil },
|
||||
Send: func(id string, data []byte) error { return nil },
|
||||
Events: eventsCh,
|
||||
}
|
||||
|
||||
e := NewEmbassy(ctx, pool, jc, nil)
|
||||
out := jc.Out()
|
||||
peer := "wss://test"
|
||||
|
||||
// added
|
||||
e.Dispatch(peer)
|
||||
Eventually(t, func() bool {
|
||||
select {
|
||||
case entry := <-out:
|
||||
_, ok := entry.(PeerAddedJournal)
|
||||
return ok
|
||||
default:
|
||||
return false
|
||||
}
|
||||
}, "expected PeerAddedJournal")
|
||||
|
||||
// connected
|
||||
eventsCh <- honeybee.OutboundPoolEvent{
|
||||
ID: peer,
|
||||
Kind: honeybee.OutboundEventConnected,
|
||||
At: time.Now(),
|
||||
}
|
||||
Eventually(t, func() bool {
|
||||
select {
|
||||
case entry := <-out:
|
||||
e, ok := entry.(PeerConnectedJournal)
|
||||
|
||||
// ensure fields are correct
|
||||
peerOk := e.PeerID() == "wss://test"
|
||||
modOk := e.Component().Module() == "prism"
|
||||
pathOk := e.Component().PathString() == "embassy"
|
||||
|
||||
return ok && peerOk && modOk && pathOk
|
||||
default:
|
||||
return false
|
||||
}
|
||||
}, "expected PeerConnectedJournal")
|
||||
|
||||
// disconnected
|
||||
eventsCh <- honeybee.OutboundPoolEvent{
|
||||
ID: peer,
|
||||
Kind: honeybee.OutboundEventDisconnected,
|
||||
At: time.Now(),
|
||||
}
|
||||
Eventually(t, func() bool {
|
||||
select {
|
||||
case entry := <-out:
|
||||
_, ok := entry.(PeerDisconnectedJournal)
|
||||
return ok
|
||||
default:
|
||||
return false
|
||||
}
|
||||
}, "expected PeerDisconnectedJournal")
|
||||
|
||||
// removed
|
||||
e.Dismiss(peer)
|
||||
Eventually(t, func() bool {
|
||||
select {
|
||||
case entry := <-out:
|
||||
_, ok := entry.(PeerRemovedJournal)
|
||||
return ok
|
||||
default:
|
||||
return false
|
||||
}
|
||||
}, "expected PeerRemovedJournal")
|
||||
|
||||
// close embassy: closes journal channel
|
||||
e.Close()
|
||||
|
||||
// Ensure jc can close now that embassy has closed its journal channel
|
||||
jcClosed := make(chan struct{})
|
||||
go func() {
|
||||
jc.Close()
|
||||
close(jcClosed)
|
||||
}()
|
||||
|
||||
Eventually(t, func() bool {
|
||||
select {
|
||||
case <-jcClosed:
|
||||
return true
|
||||
default:
|
||||
return false
|
||||
}
|
||||
}, "JournalCollector.Close() should return after Embassy.Close()")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user