Fixed gql_test.go

gql_cataclysm
noah metz 2023-07-27 12:20:49 -06:00
parent c62ef57fe7
commit 7a7a9c95a3
3 changed files with 45 additions and 57 deletions

@ -16,7 +16,7 @@ func TestGQL(t *testing.T) {
}
func TestGQLDB(t * testing.T) {
ctx := logTestContext(t, []string{"test", "signal", "policy", "db"})
ctx := logTestContext(t, []string{"thread", "test", "signal", "policy", "db"})
TestUserNodeType := NodeType("TEST_USER")
err := ctx.RegisterNodeType(TestUserNodeType, []ExtType{})
@ -29,8 +29,8 @@ func TestGQLDB(t * testing.T) {
err = ctx.RegisterNodeType(TestThreadNodeType, []ExtType{ACLExtType, ThreadExtType})
fatalErr(t, err)
t1_policy_1 := NewParentOfPolicy(Actions{"signal.abort", "state.write"})
t1_policy_2 := NewPerNodePolicy(NodeActions{
t1_p1 := NewParentOfPolicy(Actions{"signal.abort", "signal.stop", "state.write"})
t1_p2 := NewPerNodePolicy(NodeActions{
u1.ID: Actions{"parent.write"},
})
t1_thread, err := NewThreadExt(ctx, BaseThreadType, nil,nil, "init", nil)
@ -38,7 +38,7 @@ func TestGQLDB(t * testing.T) {
t1 := NewNode(ctx,
RandID(),
TestThreadNodeType,
NewACLExt(&t1_policy_1, &t1_policy_2),
NewACLExt(&t1_p1, &t1_p2),
t1_thread)
ctx.Log.Logf("test", "T1_ID: %s", t1.ID)
@ -63,7 +63,7 @@ func TestGQLDB(t * testing.T) {
NewGroupExt(nil))
ctx.Log.Logf("test", "GQL_ID: %s", gql.ID)
info := ParentInfo{true, "start", "restore"}
info := ParentInfo{true, "start", "start"}
context := NewWriteContext(ctx)
err = UpdateStates(context, u1, ACLMap{}, func(context *StateContext) error {
return LinkThreads(context, u1, gql, ChildInfo{t1, map[InfoType]Info{
@ -101,17 +101,16 @@ func TestGQLDB(t * testing.T) {
fatalErr(t, err)
context = NewReadContext(ctx)
err = UseStates(context, gql_loaded, NewACLInfo(gql_loaded, []string{"users", "children", "requirements"}), func(context *StateContext) error {
ser, err := gql_loaded.Serialize()
ctx.Log.Logf("test", "\n%s\n\n", ser)
var err error
listener_ext, err = GetExt[*ListenerExt](gql_loaded)
if err != nil {
return err
}
gql_loaded.Process(context, gql_loaded.ID, StopSignal)
return err
return gql_loaded.Process(context, gql_loaded.ID, StopSignal)
})
fatalErr(t, err)
err = ThreadLoop(ctx, gql_loaded, "start")
err = ThreadLoop(ctx, gql_loaded, "restore")
fatalErr(t, err)
(*GraphTester)(t).WaitForStatus(ctx, listener_ext.Chan, "stopped", 100*time.Millisecond, "Didn't receive stopped on update_channel_2")

@ -131,46 +131,40 @@ func LoadLockableExt(ctx *Context, data []byte) (Extension, error) {
func (ext *LockableExt) Process(context *StateContext, node *Node, signal Signal) error {
context.Graph.Log.Logf("signal", "LOCKABLE_PROCESS: %s", node.ID)
var err error
switch signal.Direction() {
case Up:
err = UseStates(context, node,
NewACLInfo(node, []string{"dependencies", "owner"}), func(context *StateContext) error {
owner_sent := false
for _, dependency := range(ext.Dependencies) {
context.Graph.Log.Logf("signal", "SENDING_TO_DEPENDENCY: %s -> %s", node.ID, dependency.ID)
dependency.Process(context, node.ID, signal)
if ext.Owner != nil {
if dependency.ID == ext.Owner.ID {
owner_sent = true
}
}
owner_sent := false
for _, dependency := range(ext.Dependencies) {
context.Graph.Log.Logf("signal", "SENDING_TO_DEPENDENCY: %s -> %s", node.ID, dependency.ID)
err := dependency.Process(context, node.ID, signal)
if err != nil {
return err
}
if ext.Owner != nil && owner_sent == false {
if ext.Owner.ID != node.ID {
context.Graph.Log.Logf("signal", "SENDING_TO_OWNER: %s -> %s", node.ID, ext.Owner.ID)
return ext.Owner.Process(context, node.ID, signal)
if ext.Owner != nil {
if dependency.ID == ext.Owner.ID {
owner_sent = true
}
}
return nil
})
case Down:
err = UseStates(context, node, NewACLInfo(node, []string{"requirements"}), func(context *StateContext) error {
for _, requirement := range(ext.Requirements) {
err := requirement.Process(context, node.ID, signal)
}
if ext.Owner != nil && owner_sent == false {
if ext.Owner.ID != node.ID {
context.Graph.Log.Logf("signal", "SENDING_TO_OWNER: %s -> %s", node.ID, ext.Owner.ID)
err := ext.Owner.Process(context, node.ID, signal)
if err != nil {
return err
}
}
return nil
})
}
case Down:
for _, requirement := range(ext.Requirements) {
err := requirement.Process(context, node.ID, signal)
if err != nil {
return err
}
}
case Direct:
err = nil
default:
err = fmt.Errorf("invalid signal direction %d", signal.Direction())
}
if err != nil {
return err
return fmt.Errorf("invalid signal direction %d", signal.Direction())
}
return nil
}

@ -298,36 +298,31 @@ func (ext *ThreadExt) ChildList() []*Node {
// Assumed that thread is already locked for signal
func (ext *ThreadExt) Process(context *StateContext, node *Node, signal Signal) error {
context.Graph.Log.Logf("signal", "THREAD_PROCESS: %s", node.ID)
context.Graph.Log.Logf("signal", "THREAD_PROCESS: %s - %+v", node.ID, signal)
var err error
switch signal.Direction() {
case Up:
err = UseStates(context, node, NewACLInfo(node, []string{"parent"}), func(context *StateContext) error {
if ext.Parent != nil {
if ext.Parent.ID != node.ID {
return ext.Parent.Process(context, node.ID, signal)
}
}
return nil
})
case Down:
err = UseStates(context, node, NewACLInfo(node, []string{"children"}), func(context *StateContext) error {
for _, info := range(ext.Children) {
err := info.Child.Process(context, node.ID, signal)
if ext.Parent != nil {
if ext.Parent.ID != node.ID {
err := ext.Parent.Process(context, node.ID, signal)
if err != nil {
return err
}
}
return nil
})
}
case Down:
for _, info := range(ext.Children) {
err := info.Child.Process(context, node.ID, signal)
if err != nil {
return err
}
}
case Direct:
err = nil
default:
return fmt.Errorf("Invalid signal direction %d", signal.Direction())
}
ext.SignalChan <- signal
return err
return nil
}
func UnlinkThreads(context *StateContext, principal *Node, thread *Node, child *Node) error {