feat(wshub): per-task event hub with non-blocking publish
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
package wshub
|
||||
|
||||
import (
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
func TestPublishReachesSubscriber(t *testing.T) {
|
||||
h := New()
|
||||
_, ch := h.Subscribe(7)
|
||||
h.Publish(Event{Type: "progress", TaskID: 7, Data: map[string]int{"copied": 3}})
|
||||
select {
|
||||
case ev := <-ch:
|
||||
if ev.Type != "progress" || ev.TaskID != 7 {
|
||||
t.Fatalf("bad event %+v", ev)
|
||||
}
|
||||
case <-time.After(time.Second):
|
||||
t.Fatal("no event received")
|
||||
}
|
||||
}
|
||||
|
||||
func TestPublishIsolatedByTask(t *testing.T) {
|
||||
h := New()
|
||||
_, ch := h.Subscribe(1)
|
||||
h.Publish(Event{Type: "x", TaskID: 2})
|
||||
select {
|
||||
case <-ch:
|
||||
t.Fatal("subscriber for task 1 must not get task 2 event")
|
||||
case <-time.After(100 * time.Millisecond):
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user