Cleaned up gql_test by putting the listener extension on gql

gql_cataclysm
noah metz 2023-07-27 12:03:39 -06:00
parent c34d717b52
commit 544264f06b
5 changed files with 12 additions and 32 deletions

@ -146,7 +146,7 @@ func NewContext(db * badger.DB, log Logger) (*Context, error) {
return nil, err return nil, err
} }
err = ctx.RegisterNodeType(GQLNodeType, []ExtType{ACLExtType, GroupExtType, GQLExtType, ThreadExtType, LockableExtType}) err = ctx.RegisterNodeType(GQLNodeType, []ExtType{ACLExtType, GroupExtType, GQLExtType, ThreadExtType})
if err != nil { if err != nil {
return nil, err return nil, err
} }

@ -60,7 +60,7 @@ func AddThreadInterfaceFields(gql *GQLInterface) {
} }
func addThreadInterfaceFields(gql *GQLInterface, gql_thread *GQLInterface) { func addThreadInterfaceFields(gql *GQLInterface, gql_thread *GQLInterface) {
AddLockableInterfaceFields(gql) AddNodeInterfaceFields(gql)
gql.Interface.AddFieldConfig("Children", &graphql.Field{ gql.Interface.AddFieldConfig("Children", &graphql.Field{
Type: gql_thread.List, Type: gql_thread.List,

@ -25,11 +25,8 @@ func TestGQLDB(t * testing.T) {
ctx.Log.Logf("test", "U1_ID: %s", u1.ID) ctx.Log.Logf("test", "U1_ID: %s", u1.ID)
l1, listener_ext := NewSimpleListener(ctx, 10)
ctx.Log.Logf("test", "L1_ID: %s", l1.ID)
TestThreadNodeType := NodeType("TEST_THREAD") TestThreadNodeType := NodeType("TEST_THREAD")
err = ctx.RegisterNodeType(TestThreadNodeType, []ExtType{ACLExtType, ThreadExtType, LockableExtType}) err = ctx.RegisterNodeType(TestThreadNodeType, []ExtType{ACLExtType, ThreadExtType})
fatalErr(t, err) fatalErr(t, err)
t1_policy_1 := NewParentOfPolicy(Actions{"signal.abort", "state.write"}) t1_policy_1 := NewParentOfPolicy(Actions{"signal.abort", "state.write"})
@ -42,8 +39,7 @@ func TestGQLDB(t * testing.T) {
RandID(), RandID(),
TestThreadNodeType, TestThreadNodeType,
NewACLExt(&t1_policy_1, &t1_policy_2), NewACLExt(&t1_policy_1, &t1_policy_2),
t1_thread, t1_thread)
NewLockableExt(nil, nil, nil, nil))
ctx.Log.Logf("test", "T1_ID: %s", t1.ID) ctx.Log.Logf("test", "T1_ID: %s", t1.ID)
key, err := ecdsa.GenerateKey(elliptic.P256(), rand.Reader) key, err := ecdsa.GenerateKey(elliptic.P256(), rand.Reader)
@ -58,24 +54,21 @@ func TestGQLDB(t * testing.T) {
fatalErr(t, err) fatalErr(t, err)
gql_ext := NewGQLExt(":0", ecdh.P256(), key, nil, nil) gql_ext := NewGQLExt(":0", ecdh.P256(), key, nil, nil)
listener_ext := NewListenerExt(10)
gql := NewNode(ctx, RandID(), GQLNodeType, gql := NewNode(ctx, RandID(), GQLNodeType,
gql_thread, gql_thread,
gql_ext, gql_ext,
listener_ext,
NewACLExt(&gql_p1, &gql_p2), NewACLExt(&gql_p1, &gql_p2),
NewGroupExt(nil), NewGroupExt(nil))
NewLockableExt(nil, nil, nil, 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", "restore"}
context := NewWriteContext(ctx) context := NewWriteContext(ctx)
err = UpdateStates(context, u1, ACLMap{}, func(context *StateContext) error { err = UpdateStates(context, u1, ACLMap{}, func(context *StateContext) error {
err := LinkThreads(context, u1, gql, ChildInfo{t1, map[InfoType]Info{ return LinkThreads(context, u1, gql, ChildInfo{t1, map[InfoType]Info{
ParentInfoType: &info, ParentInfoType: &info,
}}) }})
if err != nil {
return err
}
return LinkLockables(context, u1, l1, []*Node{gql})
}) })
fatalErr(t, err) fatalErr(t, err)
@ -109,13 +102,8 @@ func TestGQLDB(t * testing.T) {
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() ser, err := gql_loaded.Serialize()
lockable_ext, err := GetExt[*LockableExt](gql_loaded)
if err != nil {
return err
}
ctx.Log.Logf("test", "\n%s\n\n", ser) ctx.Log.Logf("test", "\n%s\n\n", ser)
dependency := lockable_ext.Dependencies[l1.ID] listener_ext, err = GetExt[*ListenerExt](gql_loaded)
listener_ext, err = GetExt[*ListenerExt](dependency)
if err != nil { if err != nil {
return err return err
} }

@ -43,7 +43,7 @@ func AddThreadFields(object *graphql.Object) {
} }
func addThreadFields(object *graphql.Object, thread_interface *graphql.Interface, thread_list *graphql.List) { func addThreadFields(object *graphql.Object, thread_interface *graphql.Interface, thread_list *graphql.List) {
AddLockableFields(object) AddNodeFields(object)
object.AddFieldConfig("State", &graphql.Field{ object.AddFieldConfig("State", &graphql.Field{
Type: graphql.String, Type: graphql.String,
@ -63,7 +63,7 @@ func addThreadFields(object *graphql.Object, thread_interface *graphql.Interface
var GQLNodeInterfaces = []*graphql.Interface{GQLInterfaceNode.Interface} var GQLNodeInterfaces = []*graphql.Interface{GQLInterfaceNode.Interface}
var GQLLockableInterfaces = append(GQLNodeInterfaces, GQLInterfaceLockable.Interface) var GQLLockableInterfaces = append(GQLNodeInterfaces, GQLInterfaceLockable.Interface)
var GQLThreadInterfaces = append(GQLLockableInterfaces, GQLInterfaceThread.Interface) var GQLThreadInterfaces = append(GQLNodeInterfaces, GQLInterfaceThread.Interface)
var GQLTypeGQLNode = NewGQLNodeType(GQLNodeType, GQLThreadInterfaces, func(gql *GQLType) { var GQLTypeGQLNode = NewGQLNodeType(GQLNodeType, GQLThreadInterfaces, func(gql *GQLType) {
AddThreadFields(gql.Type) AddThreadFields(gql.Type)

@ -648,10 +648,6 @@ func ThreadRestore(ctx * Context, thread *Node, thread_ext *ThreadExt, start boo
func ThreadStart(ctx * Context, thread *Node, thread_ext *ThreadExt) (string, error) { func ThreadStart(ctx * Context, thread *Node, thread_ext *ThreadExt) (string, error) {
context := NewWriteContext(ctx) context := NewWriteContext(ctx)
err := UpdateStates(context, thread, NewACLInfo(thread, []string{"state"}), func(context *StateContext) error { err := UpdateStates(context, thread, NewACLInfo(thread, []string{"state"}), func(context *StateContext) error {
err := LockLockables(context, map[NodeID]*Node{thread.ID: thread}, thread)
if err != nil {
return err
}
return thread_ext.SetState("started") return thread_ext.SetState("started")
}) })
if err != nil { if err != nil {
@ -695,11 +691,7 @@ func ThreadWait(ctx * Context, thread *Node, thread_ext *ThreadExt) (string, err
func ThreadFinish(ctx *Context, thread *Node, thread_ext *ThreadExt) (string, error) { func ThreadFinish(ctx *Context, thread *Node, thread_ext *ThreadExt) (string, error) {
context := NewWriteContext(ctx) context := NewWriteContext(ctx)
return "", UpdateStates(context, thread, NewACLInfo(thread, []string{"state"}), func(context *StateContext) error { return "", UpdateStates(context, thread, NewACLInfo(thread, []string{"state"}), func(context *StateContext) error {
err := thread_ext.SetState("finished") return thread_ext.SetState("finished")
if err != nil {
return err
}
return UnlockLockables(context, map[NodeID]*Node{thread.ID: thread}, thread)
}) })
} }