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

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

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