Added signalling to lockable test

gql_cataclysm
noah metz 2023-07-27 18:16:37 -06:00
parent 98893de442
commit 200e19eea7
4 changed files with 23 additions and 4 deletions

@ -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 {

@ -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)
}

@ -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")
}

@ -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,
}
}