Made default queue size 2, and not sure how that sped up the test to pre-change speeds

master
noah metz 2024-03-31 15:24:34 -07:00
parent d0d07d464d
commit 810e17990c
6 changed files with 19 additions and 18 deletions

@ -19,7 +19,7 @@ import (
func TestGQLSubscribe(t *testing.T) { func TestGQLSubscribe(t *testing.T) {
ctx := logTestContext(t, []string{"test", "gql"}) ctx := logTestContext(t, []string{"test", "gql"})
n1, err := NewNode(ctx, nil, "LockableNode", 10, NewLockableExt(nil)) n1, err := NewNode(ctx, nil, "LockableNode", NewLockableExt(nil))
fatalErr(t, err) fatalErr(t, err)
listener_ext := NewListenerExt(10) listener_ext := NewListenerExt(10)
@ -27,7 +27,7 @@ func TestGQLSubscribe(t *testing.T) {
gql_ext, err := NewGQLExt(ctx, ":0", nil, nil) gql_ext, err := NewGQLExt(ctx, ":0", nil, nil)
fatalErr(t, err) fatalErr(t, err)
gql, err := NewNode(ctx, nil, "LockableNode", 10, NewLockableExt([]NodeID{n1.ID}), gql_ext, listener_ext) gql, err := NewNode(ctx, nil, "LockableNode", NewLockableExt([]NodeID{n1.ID}), gql_ext, listener_ext)
fatalErr(t, err) fatalErr(t, err)
query := "subscription { Self { ID, Type ... on Lockable { LockableState } } }" query := "subscription { Self { ID, Type ... on Lockable { LockableState } } }"
@ -129,14 +129,14 @@ func TestGQLQuery(t *testing.T) {
ctx := logTestContext(t, []string{"test", "lockable"}) ctx := logTestContext(t, []string{"test", "lockable"})
n1_listener := NewListenerExt(10) n1_listener := NewListenerExt(10)
n1, err := NewNode(ctx, nil, "LockableNode", 10, NewLockableExt(nil), n1_listener) n1, err := NewNode(ctx, nil, "LockableNode", NewLockableExt(nil), n1_listener)
fatalErr(t, err) fatalErr(t, err)
gql_listener := NewListenerExt(10) gql_listener := NewListenerExt(10)
gql_ext, err := NewGQLExt(ctx, ":0", nil, nil) gql_ext, err := NewGQLExt(ctx, ":0", nil, nil)
fatalErr(t, err) fatalErr(t, err)
gql, err := NewNode(ctx, nil, "LockableNode", 10, NewLockableExt([]NodeID{n1.ID}), gql_ext, gql_listener) gql, err := NewNode(ctx, nil, "LockableNode", NewLockableExt([]NodeID{n1.ID}), gql_ext, gql_listener)
fatalErr(t, err) fatalErr(t, err)
ctx.Log.Logf("test", "GQL: %s", gql.ID) ctx.Log.Logf("test", "GQL: %s", gql.ID)
@ -208,7 +208,7 @@ func TestGQLDB(t *testing.T) {
fatalErr(t, err) fatalErr(t, err)
listener_ext := NewListenerExt(10) listener_ext := NewListenerExt(10)
gql, err := NewNode(ctx, nil, "Node", 10, gql_ext, listener_ext) gql, err := NewNode(ctx, nil, "Node", gql_ext, listener_ext)
fatalErr(t, err) fatalErr(t, err)
ctx.Log.Logf("test", "GQL_ID: %s", gql.ID) ctx.Log.Logf("test", "GQL_ID: %s", gql.ID)

@ -12,7 +12,6 @@ func NewSimpleListener(ctx *Context, buffer int) (*Node, *ListenerExt, error) {
listener, err := NewNode(ctx, listener, err := NewNode(ctx,
nil, nil,
"LockableNode", "LockableNode",
10,
nil, nil,
listener_extension, listener_extension,
NewLockableExt(nil)) NewLockableExt(nil))

@ -10,12 +10,12 @@ func TestLink(t *testing.T) {
l2_listener := NewListenerExt(10) l2_listener := NewListenerExt(10)
l2, err := NewNode(ctx, nil, "LockableNode", 10, l2_listener, NewLockableExt(nil)) l2, err := NewNode(ctx, nil, "LockableNode", l2_listener, NewLockableExt(nil))
fatalErr(t, err) fatalErr(t, err)
l1_lockable := NewLockableExt(nil) l1_lockable := NewLockableExt(nil)
l1_listener := NewListenerExt(10) l1_listener := NewListenerExt(10)
l1, err := NewNode(ctx, nil, "LockableNode", 10, l1_listener, l1_lockable) l1, err := NewNode(ctx, nil, "LockableNode", l1_listener, l1_lockable)
fatalErr(t, err) fatalErr(t, err)
link_signal := NewLinkSignal("add", l2.ID) link_signal := NewLinkSignal("add", l2.ID)
@ -62,7 +62,7 @@ func testLockN(t *testing.T, n int) {
ctx := logTestContext(t, []string{"test"}) ctx := logTestContext(t, []string{"test"})
NewLockable := func()(*Node) { NewLockable := func()(*Node) {
l, err := NewNode(ctx, nil, "LockableNode", 10, NewLockableExt(nil)) l, err := NewNode(ctx, nil, "LockableNode", NewLockableExt(nil))
fatalErr(t, err) fatalErr(t, err)
return l return l
} }
@ -75,7 +75,7 @@ func testLockN(t *testing.T, n int) {
ctx.Log.Logf("test", "CREATED_%d", n) ctx.Log.Logf("test", "CREATED_%d", n)
listener := NewListenerExt(50000) listener := NewListenerExt(50000)
node, err := NewNode(ctx, nil, "LockableNode", 500000, listener, NewLockableExt(reqs)) node, err := NewNode(ctx, nil, "LockableNode", listener, NewLockableExt(reqs))
fatalErr(t, err) fatalErr(t, err)
ctx.Log.Logf("test", "CREATED_LISTENER") ctx.Log.Logf("test", "CREATED_LISTENER")
@ -99,7 +99,7 @@ func TestLock(t *testing.T) {
NewLockable := func(reqs []NodeID)(*Node, *ListenerExt) { NewLockable := func(reqs []NodeID)(*Node, *ListenerExt) {
listener := NewListenerExt(10000) listener := NewListenerExt(10000)
l, err := NewNode(ctx, nil, "LockableNode", 10, listener, NewLockableExt(reqs)) l, err := NewNode(ctx, nil, "LockableNode", listener, NewLockableExt(reqs))
fatalErr(t, err) fatalErr(t, err)
return l, listener return l, listener
} }

@ -72,6 +72,8 @@ func (q QueuedSignal) String() string {
type WaitMap map[uuid.UUID]NodeID type WaitMap map[uuid.UUID]NodeID
const NODE_INITIAL_QUEUE_SIZE = 2
// Nodes represent a group of extensions that can be collectively addressed // Nodes represent a group of extensions that can be collectively addressed
type Node struct { type Node struct {
Key ed25519.PrivateKey `gv:"key"` Key ed25519.PrivateKey `gv:"key"`
@ -99,7 +101,7 @@ func (node *Node) PostDeserialize(ctx *Context) error {
public := node.Key.Public().(ed25519.PublicKey) public := node.Key.Public().(ed25519.PublicKey)
node.ID = KeyID(public) node.ID = KeyID(public)
node.SendChan, node.RecvChan = NewMessageQueue(1000) node.SendChan, node.RecvChan = NewMessageQueue(NODE_INITIAL_QUEUE_SIZE)
return nil return nil
} }
@ -398,7 +400,7 @@ func KeyID(pub ed25519.PublicKey) NodeID {
} }
// Create a new node in memory and start it's event loop // Create a new node in memory and start it's event loop
func NewNode(ctx *Context, key ed25519.PrivateKey, type_name string, buffer_size uint32, extensions ...Extension) (*Node, error) { func NewNode(ctx *Context, key ed25519.PrivateKey, type_name string, extensions ...Extension) (*Node, error) {
node_type := NodeTypeFor(type_name) node_type := NodeTypeFor(type_name)
node_info, known_type := ctx.NodeTypes[node_type] node_info, known_type := ctx.NodeTypes[node_type]
if known_type == false { if known_type == false {
@ -454,7 +456,7 @@ func NewNode(ctx *Context, key ed25519.PrivateKey, type_name string, buffer_size
writeSignalQueue: false, writeSignalQueue: false,
} }
node.SendChan, node.RecvChan = NewMessageQueue(1000) node.SendChan, node.RecvChan = NewMessageQueue(NODE_INITIAL_QUEUE_SIZE)
err = ctx.DB.WriteNodeInit(ctx, node) err = ctx.DB.WriteNodeInit(ctx, node)
if err != nil { if err != nil {

@ -12,7 +12,7 @@ func TestNodeDB(t *testing.T) {
ctx := logTestContext(t, []string{"test", "node", "db"}) ctx := logTestContext(t, []string{"test", "node", "db"})
node_listener := NewListenerExt(10) node_listener := NewListenerExt(10)
node, err := NewNode(ctx, nil, "Node", 10, NewLockableExt(nil), node_listener) node, err := NewNode(ctx, nil, "Node", NewLockableExt(nil), node_listener)
fatalErr(t, err) fatalErr(t, err)
_, err = WaitForSignal(node_listener.Chan, 10*time.Millisecond, func(sig *StatusSignal) bool { _, err = WaitForSignal(node_listener.Chan, 10*time.Millisecond, func(sig *StatusSignal) bool {
@ -41,10 +41,10 @@ func TestNodeRead(t *testing.T) {
ctx.Log.Logf("test", "N2: %s", n2_id) ctx.Log.Logf("test", "N2: %s", n2_id)
n2_listener := NewListenerExt(10) n2_listener := NewListenerExt(10)
n2, err := NewNode(ctx, n2_key, "Node", 10, n2_listener) n2, err := NewNode(ctx, n2_key, "Node", n2_listener)
fatalErr(t, err) fatalErr(t, err)
n1, err := NewNode(ctx, n1_key, "Node", 10, NewListenerExt(10)) n1, err := NewNode(ctx, n1_key, "Node", NewListenerExt(10))
fatalErr(t, err) fatalErr(t, err)
read_sig := NewReadSignal([]string{"buffer"}) read_sig := NewReadSignal([]string{"buffer"})

@ -170,7 +170,7 @@ func TestSerializeValues(t *testing.T) {
testSerialize(t, ctx, NewListenerExt(10)) testSerialize(t, ctx, NewListenerExt(10))
node, err := NewNode(ctx, nil, "Node", 100) node, err := NewNode(ctx, nil, "Node")
fatalErr(t, err) fatalErr(t, err)
testSerialize(t, ctx, node) testSerialize(t, ctx, node)
} }