2023-07-27 16:21:27 -06:00
|
|
|
package graphvent
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
2023-07-27 18:08:43 -06:00
|
|
|
"time"
|
2023-07-27 16:21:27 -06:00
|
|
|
)
|
|
|
|
|
2023-07-27 16:48:39 -06:00
|
|
|
const TestLockableType = NodeType("TEST_LOCKABLE")
|
|
|
|
func lockableTestContext(t *testing.T) *Context {
|
2023-07-27 18:08:43 -06:00
|
|
|
ctx := logTestContext(t, []string{"lockable", "test"})
|
2023-07-27 16:48:39 -06:00
|
|
|
|
|
|
|
err := ctx.RegisterNodeType(TestLockableType, []ExtType{ACLExtType, LockableExtType, ListenerExtType})
|
2023-07-27 16:21:27 -06:00
|
|
|
fatalErr(t, err)
|
2023-07-27 16:48:39 -06:00
|
|
|
|
|
|
|
return ctx
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-07-27 18:08:43 -06:00
|
|
|
var link_policy = NewAllNodesPolicy([]SignalType{LinkSignalType})
|
2023-07-27 16:48:39 -06:00
|
|
|
|
2023-07-27 18:08:43 -06:00
|
|
|
func TestLinkStatus(t *testing.T) {
|
2023-07-27 16:48:39 -06:00
|
|
|
ctx := lockableTestContext(t)
|
|
|
|
|
|
|
|
l1_listener := NewListenerExt(10)
|
|
|
|
l1 := NewNode(ctx, RandID(), TestLockableType, nil,
|
|
|
|
l1_listener,
|
|
|
|
NewACLExt(&link_policy),
|
|
|
|
NewLockableExt(nil, nil, nil, nil),
|
|
|
|
)
|
|
|
|
l2_listener := NewListenerExt(10)
|
|
|
|
l2 := NewNode(ctx, RandID(), TestLockableType, nil,
|
|
|
|
l2_listener,
|
|
|
|
NewACLExt(&link_policy),
|
|
|
|
NewLockableExt(nil, nil, nil, nil),
|
|
|
|
)
|
|
|
|
|
2023-07-27 18:08:43 -06:00
|
|
|
// Link l2 as a requirement of l1
|
|
|
|
err := LinkRequirement(ctx, l1, l2.ID)
|
|
|
|
fatalErr(t, err)
|
2023-07-27 16:21:27 -06:00
|
|
|
|
2023-07-27 18:08:43 -06:00
|
|
|
(*GraphTester)(t).WaitForLinkState(ctx, l1_listener, "dep_link", time.Millisecond*100, "No dep_link")
|
|
|
|
(*GraphTester)(t).WaitForLinkState(ctx, l2_listener, "req_linked", time.Millisecond*100, "No req_linked")
|
|
|
|
}
|