graphvent/gql_test.go

56 lines
1.6 KiB
Go

2023-06-25 20:20:59 -06:00
package graphvent
import (
"testing"
2023-06-25 22:19:05 -06:00
"time"
"crypto/rand"
"crypto/ecdh"
"crypto/ecdsa"
"crypto/elliptic"
2023-06-25 20:20:59 -06:00
)
2023-07-27 00:30:24 -06:00
func TestGQLDB(t * testing.T) {
ctx := logTestContext(t, []string{"loop", "node", "thread", "test", "signal", "policy", "db"})
2023-07-26 13:28:03 -06:00
TestUserNodeType := NodeType("TEST_USER")
2023-07-27 11:33:11 -06:00
err := ctx.RegisterNodeType(TestUserNodeType, []ExtType{})
2023-07-26 13:28:03 -06:00
fatalErr(t, err)
u1 := NewNode(ctx, RandID(), TestUserNodeType, nil)
2023-07-26 13:28:03 -06:00
ctx.Log.Logf("test", "U1_ID: %s", u1.ID)
2023-07-26 11:56:10 -06:00
key, err := ecdsa.GenerateKey(elliptic.P256(), rand.Reader)
fatalErr(t, err)
2023-07-26 11:56:10 -06:00
2023-07-27 11:33:11 -06:00
gql_ext := NewGQLExt(":0", ecdh.P256(), key, nil, nil)
listener_ext := NewListenerExt(10)
gql := NewNode(ctx, RandID(), GQLNodeType, nil,
2023-07-27 11:33:11 -06:00
gql_ext,
listener_ext,
NewACLExt(),
NewGroupExt(nil))
2023-07-26 11:56:10 -06:00
ctx.Log.Logf("test", "GQL_ID: %s", gql.ID)
err = ctx.Send(gql.ID, gql.ID, StopSignal)
2023-07-09 20:30:19 -06:00
fatalErr(t, err)
(*GraphTester)(t).WaitForStatus(ctx, listener_ext.Chan, "stopped", 100*time.Millisecond, "Didn't receive stopped on listener")
ser1, err := gql.Serialize()
ser2, err := u1.Serialize()
ctx.Log.Logf("test", "\n%s\n\n", ser1)
ctx.Log.Logf("test", "\n%s\n\n", ser2)
2023-07-26 11:56:10 -06:00
// Clear all loaded nodes from the context so it loads them from the database
ctx.Nodes = NodeMap{}
gql_loaded, err := LoadNode(ctx, gql.ID)
fatalErr(t, err)
listener_ext, err = GetExt[*ListenerExt](gql_loaded)
2023-07-27 12:20:49 -06:00
fatalErr(t, err)
err = ctx.Send(gql_loaded.ID, gql_loaded.ID, StopSignal)
fatalErr(t, err)
2023-07-26 11:56:10 -06:00
(*GraphTester)(t).WaitForStatus(ctx, listener_ext.Chan, "stopped", 100*time.Millisecond, "Didn't receive stopped on update_channel_2")
}