Add a unit test for watch.Broadcaster DropIfChannelFull and a couple small fixes

This commit is contained in:
Alex Robinson
2015-01-14 04:36:29 +00:00
parent 3eaf362f8e
commit 90e1d58fa6
3 changed files with 62 additions and 5 deletions

View File

@@ -27,10 +27,15 @@ import (
type FullChannelBehavior int
const (
WaitIfChannelFull = iota
DropIfChannelFull = iota
WaitIfChannelFull FullChannelBehavior = iota
DropIfChannelFull
)
// Buffer the incoming queue a little bit even though it should rarely ever accumulate
// anything, just in case a few events are received in such a short window that
// Broadcaster can't move them onto the watchers' queues fast enough.
const incomingQueueLength = 25
// Broadcaster distributes event notifications among any number of watchers. Every event
// is delivered to every watcher.
type Broadcaster struct {
@@ -58,7 +63,7 @@ type Broadcaster struct {
func NewBroadcaster(queueLength int, fullChannelBehavior FullChannelBehavior) *Broadcaster {
m := &Broadcaster{
watchers: map[int64]*broadcasterWatcher{},
incoming: make(chan Event),
incoming: make(chan Event, incomingQueueLength),
watchQueueLength: queueLength,
fullChannelBehavior: fullChannelBehavior,
}