- Add console emitter interface for event-driven console output - Implement persistent cancel reason and explicit completion tracking - Add profile proto message definitions - Update edge and node transport layers with adapter execution terminology - Add new packages/events module - Update architecture documentation and README files
62 lines
1.5 KiB
Go
62 lines
1.5 KiB
Go
package events_test
|
|
|
|
import (
|
|
"testing"
|
|
|
|
edgeevents "iop/apps/edge/internal/events"
|
|
iop "iop/proto/gen/iop"
|
|
)
|
|
|
|
func TestBusPublishesRunToSpecificAndAllSubscribers(t *testing.T) {
|
|
bus := edgeevents.NewBus()
|
|
specific, unsubscribeSpecific := bus.SubscribeRun("run-1", 1)
|
|
defer unsubscribeSpecific()
|
|
all, unsubscribeAll := bus.SubscribeAllRuns(1)
|
|
defer unsubscribeAll()
|
|
|
|
bus.PublishRun(&iop.RunEvent{RunId: "run-1", Type: "start"})
|
|
|
|
select {
|
|
case event := <-specific:
|
|
if event.GetRunId() != "run-1" {
|
|
t.Fatalf("specific run id: %q", event.GetRunId())
|
|
}
|
|
default:
|
|
t.Fatal("expected specific run subscriber event")
|
|
}
|
|
select {
|
|
case event := <-all:
|
|
if event.GetRunId() != "run-1" {
|
|
t.Fatalf("all run id: %q", event.GetRunId())
|
|
}
|
|
default:
|
|
t.Fatal("expected all run subscriber event")
|
|
}
|
|
}
|
|
|
|
func TestBusPublishesNodeToSpecificAndAllSubscribers(t *testing.T) {
|
|
bus := edgeevents.NewBus()
|
|
specific, unsubscribeSpecific := bus.SubscribeNode("node-1", 1)
|
|
defer unsubscribeSpecific()
|
|
all, unsubscribeAll := bus.SubscribeAllNodes(1)
|
|
defer unsubscribeAll()
|
|
|
|
bus.PublishNode(&iop.EdgeNodeEvent{NodeId: "node-1", Type: "node.disconnected"})
|
|
|
|
select {
|
|
case event := <-specific:
|
|
if event.GetNodeId() != "node-1" {
|
|
t.Fatalf("specific node id: %q", event.GetNodeId())
|
|
}
|
|
default:
|
|
t.Fatal("expected specific node subscriber event")
|
|
}
|
|
select {
|
|
case event := <-all:
|
|
if event.GetNodeId() != "node-1" {
|
|
t.Fatalf("all node id: %q", event.GetNodeId())
|
|
}
|
|
default:
|
|
t.Fatal("expected all node subscriber event")
|
|
}
|
|
}
|