mirror of
https://github.com/jhillyerd/inbucket.git
synced 2025-12-18 10:07:02 +00:00
Fixes #61 - monitor.history=0 panic
This commit is contained in:
@@ -17,6 +17,7 @@ This project adheres to [Semantic Versioning](http://semver.org/).
|
|||||||
- `rest/client.NewV1` renamed to `New`
|
- `rest/client.NewV1` renamed to `New`
|
||||||
- `rest/client` package now embeds the shared `rest/model` structs into its own
|
- `rest/client` package now embeds the shared `rest/model` structs into its own
|
||||||
types
|
types
|
||||||
|
- Fixed panic when `monitor.history` set to 0
|
||||||
|
|
||||||
[1.2.0-rc1] - 2017-01-29
|
[1.2.0-rc1] - 2017-01-29
|
||||||
------------------------
|
------------------------
|
||||||
|
|||||||
@@ -63,13 +63,15 @@ func New(ctx context.Context, historyLen int) *Hub {
|
|||||||
// history buffer and then relayed to all registered listeners.
|
// history buffer and then relayed to all registered listeners.
|
||||||
func (hub *Hub) Dispatch(msg Message) {
|
func (hub *Hub) Dispatch(msg Message) {
|
||||||
hub.opChan <- func(h *Hub) {
|
hub.opChan <- func(h *Hub) {
|
||||||
// Add to history buffer
|
if h.history != nil {
|
||||||
h.history.Value = msg
|
// Add to history buffer
|
||||||
h.history = h.history.Next()
|
h.history.Value = msg
|
||||||
// Deliver message to all listeners, removing listeners if they return an error
|
h.history = h.history.Next()
|
||||||
for l := range h.listeners {
|
// Deliver message to all listeners, removing listeners if they return an error
|
||||||
if err := l.Receive(msg); err != nil {
|
for l := range h.listeners {
|
||||||
delete(h.listeners, l)
|
if err := l.Receive(msg); err != nil {
|
||||||
|
delete(h.listeners, l)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -60,6 +60,17 @@ func TestHubNew(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestHubZeroLen(t *testing.T) {
|
||||||
|
ctx, cancel := context.WithCancel(context.Background())
|
||||||
|
defer cancel()
|
||||||
|
hub := New(ctx, 0)
|
||||||
|
m := Message{}
|
||||||
|
for i := 0; i < 100; i++ {
|
||||||
|
hub.Dispatch(m)
|
||||||
|
}
|
||||||
|
// Just making sure Hub doesn't panic
|
||||||
|
}
|
||||||
|
|
||||||
func TestHubZeroListeners(t *testing.T) {
|
func TestHubZeroListeners(t *testing.T) {
|
||||||
ctx, cancel := context.WithCancel(context.Background())
|
ctx, cancel := context.WithCancel(context.Background())
|
||||||
defer cancel()
|
defer cancel()
|
||||||
|
|||||||
Reference in New Issue
Block a user