2023-06-25 20:20:59 -06:00
|
|
|
package graphvent
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
2023-06-25 22:19:05 -06:00
|
|
|
"time"
|
2023-07-01 13:06:39 -06:00
|
|
|
"fmt"
|
|
|
|
"encoding/json"
|
2023-06-25 20:20:59 -06:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestGQLThread(t * testing.T) {
|
2023-07-02 12:14:04 -06:00
|
|
|
ctx := logTestContext(t, []string{"thread"})
|
2023-07-01 13:03:28 -06:00
|
|
|
gql_thread, err := NewGQLThread(ctx, ":8080", []Lockable{})
|
2023-06-25 20:20:59 -06:00
|
|
|
fatalErr(t, err)
|
|
|
|
|
2023-07-02 12:14:04 -06:00
|
|
|
test_thread_1, err := NewSimpleThread(ctx, "Test thread 1", []Lockable{}, BaseThreadActions, BaseThreadHandlers)
|
2023-06-25 20:20:59 -06:00
|
|
|
fatalErr(t, err)
|
|
|
|
|
2023-07-02 12:14:04 -06:00
|
|
|
test_thread_2, err := NewSimpleThread(ctx, "Test thread 2", []Lockable{}, BaseThreadActions, BaseThreadHandlers)
|
2023-06-26 21:20:04 -06:00
|
|
|
fatalErr(t, err)
|
|
|
|
|
|
|
|
i1 := NewGQLThreadInfo(true)
|
|
|
|
err = LinkThreads(ctx, gql_thread, test_thread_1, &i1)
|
|
|
|
fatalErr(t, err)
|
|
|
|
|
|
|
|
i2 := NewGQLThreadInfo(false)
|
|
|
|
err = LinkThreads(ctx, gql_thread, test_thread_2, &i2)
|
2023-06-25 20:20:59 -06:00
|
|
|
fatalErr(t, err)
|
|
|
|
|
2023-06-25 22:19:05 -06:00
|
|
|
go func(thread Thread){
|
|
|
|
time.Sleep(10*time.Millisecond)
|
|
|
|
SendUpdate(ctx, thread, CancelSignal(nil))
|
|
|
|
}(gql_thread)
|
|
|
|
|
2023-06-25 20:20:59 -06:00
|
|
|
err = RunThread(ctx, gql_thread)
|
|
|
|
fatalErr(t, err)
|
|
|
|
}
|
2023-07-01 13:06:39 -06:00
|
|
|
|
|
|
|
func TestGQLDBLoad(t * testing.T) {
|
|
|
|
ctx := logTestContext(t, []string{})
|
2023-07-02 12:14:04 -06:00
|
|
|
l1, err := NewSimpleLockable(ctx, "Test Lockable 1", []Lockable{})
|
2023-07-01 13:06:39 -06:00
|
|
|
fatalErr(t, err)
|
|
|
|
|
|
|
|
t1, err := NewGQLThread(ctx, ":8080", []Lockable{l1})
|
|
|
|
fatalErr(t, err)
|
|
|
|
|
|
|
|
SendUpdate(ctx, t1, CancelSignal(nil))
|
|
|
|
err = RunThread(ctx, t1)
|
|
|
|
fatalErr(t, err)
|
|
|
|
|
|
|
|
err = UseStates(ctx, []GraphNode{t1}, func(states NodeStateMap) error {
|
|
|
|
ser, err := json.MarshalIndent(states[t1.ID()], "", " ")
|
|
|
|
fmt.Printf("\n%s\n\n", ser)
|
|
|
|
return err
|
|
|
|
})
|
|
|
|
|
|
|
|
t1_loaded, err := LoadNode(ctx, t1.ID())
|
|
|
|
fatalErr(t, err)
|
|
|
|
|
|
|
|
err = UseStates(ctx, []GraphNode{t1_loaded}, func(states NodeStateMap) error {
|
|
|
|
ser, err := json.MarshalIndent(states[t1_loaded.ID()], "", " ")
|
|
|
|
fmt.Printf("\n%s\n\n", ser)
|
|
|
|
return err
|
|
|
|
})
|
|
|
|
}
|