2023-07-26 00:42:12 -06:00
|
|
|
package graphvent
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
2023-07-28 11:59:01 -06:00
|
|
|
"time"
|
2023-07-28 15:07:38 -06:00
|
|
|
"crypto/rand"
|
2023-08-06 12:47:47 -06:00
|
|
|
"crypto/ed25519"
|
2023-10-10 11:23:44 -06:00
|
|
|
"slices"
|
2023-07-26 00:42:12 -06:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestNodeDB(t *testing.T) {
|
2024-03-28 20:28:07 -06:00
|
|
|
ctx := logTestContext(t, []string{"test", "node", "db"})
|
2023-07-27 01:30:32 -06:00
|
|
|
|
2023-09-02 17:30:52 -06:00
|
|
|
node_listener := NewListenerExt(10)
|
2024-03-28 20:28:07 -06:00
|
|
|
node, err := NewNode(ctx, nil, "Node", 10, NewLockableExt(nil), node_listener)
|
2023-09-02 17:30:52 -06:00
|
|
|
fatalErr(t, err)
|
|
|
|
|
|
|
|
_, err = WaitForSignal(node_listener.Chan, 10*time.Millisecond, func(sig *StatusSignal) bool {
|
2024-03-28 20:28:07 -06:00
|
|
|
return slices.Contains(sig.Fields, "state") && sig.Source == node.ID
|
2023-09-02 17:30:52 -06:00
|
|
|
})
|
|
|
|
|
2024-03-03 16:37:03 -07:00
|
|
|
err = ctx.Unload(node.ID)
|
2023-08-31 22:31:29 -06:00
|
|
|
fatalErr(t, err)
|
2023-07-26 00:42:12 -06:00
|
|
|
|
2024-03-28 20:28:07 -06:00
|
|
|
ctx.nodes = map[NodeID]*Node{}
|
2023-08-31 19:50:32 -06:00
|
|
|
_, err = ctx.getNode(node.ID)
|
2023-07-26 00:42:12 -06:00
|
|
|
fatalErr(t, err)
|
|
|
|
}
|
2023-07-28 11:59:01 -06:00
|
|
|
|
|
|
|
func TestNodeRead(t *testing.T) {
|
2023-08-28 14:52:28 -06:00
|
|
|
ctx := logTestContext(t, []string{"test"})
|
2023-07-28 11:59:01 -06:00
|
|
|
|
2023-08-06 12:47:47 -06:00
|
|
|
n1_pub, n1_key, err := ed25519.GenerateKey(rand.Reader)
|
2023-07-28 15:07:38 -06:00
|
|
|
fatalErr(t, err)
|
2023-08-06 12:47:47 -06:00
|
|
|
n2_pub, n2_key, err := ed25519.GenerateKey(rand.Reader)
|
2023-07-28 15:07:38 -06:00
|
|
|
fatalErr(t, err)
|
|
|
|
|
2023-08-06 12:47:47 -06:00
|
|
|
n1_id := KeyID(n1_pub)
|
|
|
|
n2_id := KeyID(n2_pub)
|
2023-07-28 11:59:01 -06:00
|
|
|
|
|
|
|
ctx.Log.Logf("test", "N1: %s", n1_id)
|
|
|
|
ctx.Log.Logf("test", "N2: %s", n2_id)
|
|
|
|
|
|
|
|
n2_listener := NewListenerExt(10)
|
2024-03-28 20:28:07 -06:00
|
|
|
n2, err := NewNode(ctx, n2_key, "Node", 10, n2_listener)
|
2023-08-31 22:31:29 -06:00
|
|
|
fatalErr(t, err)
|
2023-07-28 11:59:01 -06:00
|
|
|
|
2024-03-28 20:28:07 -06:00
|
|
|
n1, err := NewNode(ctx, n1_key, "Node", 10, NewListenerExt(10))
|
2023-08-31 22:31:29 -06:00
|
|
|
fatalErr(t, err)
|
2023-07-28 11:59:01 -06:00
|
|
|
|
2024-03-28 20:28:07 -06:00
|
|
|
read_sig := NewReadSignal([]string{"buffer"})
|
2024-03-04 17:30:42 -07:00
|
|
|
msgs := []SendMsg{{n1.ID, read_sig}}
|
|
|
|
err = ctx.Send(n2, msgs)
|
2023-08-08 14:00:17 -06:00
|
|
|
fatalErr(t, err)
|
2023-07-28 11:59:01 -06:00
|
|
|
|
2023-08-31 19:50:32 -06:00
|
|
|
res, err := WaitForSignal(n2_listener.Chan, 10*time.Millisecond, func(sig *ReadResultSignal) bool {
|
2023-07-28 19:32:27 -06:00
|
|
|
return true
|
|
|
|
})
|
|
|
|
fatalErr(t, err)
|
2023-07-28 11:59:01 -06:00
|
|
|
ctx.Log.Logf("test", "READ_RESULT: %+v", res)
|
|
|
|
}
|