From 7a7a9c95a33caad4c5fecec524cc226d41cd2e91 Mon Sep 17 00:00:00 2001 From: Noah Metz Date: Thu, 27 Jul 2023 12:20:49 -0600 Subject: [PATCH] Fixed gql_test.go --- gql_test.go | 19 +++++++++---------- lockable.go | 52 +++++++++++++++++++++++----------------------------- thread.go | 31 +++++++++++++------------------ 3 files changed, 45 insertions(+), 57 deletions(-) diff --git a/gql_test.go b/gql_test.go index a491d7d..71df628 100644 --- a/gql_test.go +++ b/gql_test.go @@ -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") diff --git a/lockable.go b/lockable.go index 654b048..02fa8d0 100644 --- a/lockable.go +++ b/lockable.go @@ -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 } diff --git a/thread.go b/thread.go index 875285b..f3a6b6b 100644 --- a/thread.go +++ b/thread.go @@ -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 {