diff --git a/graph_test.go b/graph_test.go index b4be029..0562b1a 100644 --- a/graph_test.go +++ b/graph_test.go @@ -51,7 +51,7 @@ func (t * GraphTester) WaitForStatus(ctx * Context, listener *ListenerExt, statu ctx.Log.Logf("test", "SIGNAL_CHANNEL_CLOSED: %s", listener) t.Fatal(str) } - if signal.Type() == "status" { + if signal.Type() == StatusSignalType { sig, ok := signal.(StatusSignal) if ok == true { diff --git a/lockable.go b/lockable.go index 895eaab..2288bee 100644 --- a/lockable.go +++ b/lockable.go @@ -156,8 +156,20 @@ func (ext *LockableExt) HandleLinkSignal(ctx *Context, source NodeID, node *Node ctx.Log.Logf("lockable", "%s reset %s requirement state", node.ID, source) case "dep_linked": ctx.Log.Logf("lockable", "%s is a dependency of %s", node.ID, source) + req_state, exists := ext.Requirements[source] + if exists == true && req_state == "start" { + ext.Requirements[source] = "linked" + ctx.Send(node.ID, source, NewLinkSignal("req_linked")) + } + case "req_linked": ctx.Log.Logf("lockable", "%s is a requirement of %s", node.ID, source) + dep_state, exists := ext.Dependencies[source] + if exists == true && dep_state == "start" { + ext.Dependencies[source] = "linked" + ctx.Send(node.ID, source, NewLinkSignal("dep_linked")) + } + default: ctx.Log.Logf("lockable", "LINK_ERROR: unknown state %s", state) } diff --git a/lockable_test.go b/lockable_test.go index 6437efb..8f79047 100644 --- a/lockable_test.go +++ b/lockable_test.go @@ -16,7 +16,7 @@ func lockableTestContext(t *testing.T) *Context { } -var link_policy = NewAllNodesPolicy([]SignalType{LinkSignalType}) +var link_policy = NewAllNodesPolicy([]SignalType{LinkSignalType, StatusSignalType}) func TestLinkStatus(t *testing.T) { ctx := lockableTestContext(t) @@ -38,6 +38,12 @@ func TestLinkStatus(t *testing.T) { err := LinkRequirement(ctx, l1, l2.ID) fatalErr(t, err) - (*GraphTester)(t).WaitForLinkState(ctx, l1_listener, "dep_link", time.Millisecond*100, "No dep_link") + (*GraphTester)(t).WaitForLinkState(ctx, l1_listener, "dep_linked", time.Millisecond*100, "No dep_link") (*GraphTester)(t).WaitForLinkState(ctx, l2_listener, "req_linked", time.Millisecond*100, "No req_linked") + + err = ctx.Send(l2.ID, l2.ID, NewStatusSignal("TEST", l2.ID)) + fatalErr(t, err) + + (*GraphTester)(t).WaitForStatus(ctx, l1_listener, "TEST", time.Millisecond*100, "No TEST on l1") + (*GraphTester)(t).WaitForStatus(ctx, l2_listener, "TEST", time.Millisecond*100, "No TEST on l2") } diff --git a/signal.go b/signal.go index c63c95b..6d7c9a6 100644 --- a/signal.go +++ b/signal.go @@ -91,9 +91,10 @@ func (signal StatusSignal) String() string { return string(ser) } +const StatusSignalType = SignalType("STATUS") func NewStatusSignal(status string, source NodeID) StatusSignal { return StatusSignal{ - IDSignal: NewIDSignal("status", Up, source), + IDSignal: NewIDSignal(StatusSignalType, Up, source), Status: status, } }