mirror of
https://github.com/jhillyerd/inbucket.git
synced 2025-12-17 17:47:03 +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,6 +63,7 @@ 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) {
|
||||||
|
if h.history != nil {
|
||||||
// Add to history buffer
|
// Add to history buffer
|
||||||
h.history.Value = msg
|
h.history.Value = msg
|
||||||
h.history = h.history.Next()
|
h.history = h.history.Next()
|
||||||
@@ -74,6 +75,7 @@ func (hub *Hub) Dispatch(msg Message) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// AddListener registers a listener to receive broadcasted messages.
|
// AddListener registers a listener to receive broadcasted messages.
|
||||||
func (hub *Hub) AddListener(l Listener) {
|
func (hub *Hub) AddListener(l Listener) {
|
||||||
|
|||||||
@@ -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