enhance tests for race conditions

graph-rework-2
noah metz 2023-07-05 23:54:11 -06:00
parent ff46af585d
commit 0e2b6ccb2a
2 changed files with 12 additions and 11 deletions

@ -9,7 +9,7 @@ import (
func TestGQLThread(t * testing.T) { func TestGQLThread(t * testing.T) {
ctx := logTestContext(t, []string{}) ctx := logTestContext(t, []string{})
gql_thread, err := NewGQLThread(ctx, ":8080", []Lockable{}) gql_thread, err := NewGQLThread(ctx, ":0", []Lockable{})
fatalErr(t, err) fatalErr(t, err)
test_thread_1, err := NewSimpleThread(ctx, "Test thread 1", []Lockable{}, BaseThreadActions, BaseThreadHandlers) test_thread_1, err := NewSimpleThread(ctx, "Test thread 1", []Lockable{}, BaseThreadActions, BaseThreadHandlers)
@ -28,10 +28,11 @@ func TestGQLThread(t * testing.T) {
go func(thread Thread){ go func(thread Thread){
time.Sleep(10*time.Millisecond) time.Sleep(10*time.Millisecond)
err = UseStates(ctx, []GraphNode{thread}, func(states NodeStateMap) error { err := UseStates(ctx, []GraphNode{thread}, func(states NodeStateMap) error {
SendUpdate(ctx, thread, CancelSignal(nil), states) SendUpdate(ctx, thread, CancelSignal(nil), states)
return nil return nil
}) })
fatalErr(t, err)
}(gql_thread) }(gql_thread)
err = RunThread(ctx, gql_thread, "start") err = RunThread(ctx, gql_thread, "start")
@ -47,7 +48,7 @@ func TestGQLDBLoad(t * testing.T) {
fatalErr(t, err) fatalErr(t, err)
update_channel := t1.UpdateChannel(10) update_channel := t1.UpdateChannel(10)
gql, err := NewGQLThread(ctx, ":8080", []Lockable{l1}) gql, err := NewGQLThread(ctx, ":0", []Lockable{l1})
fatalErr(t, err) fatalErr(t, err)
info := NewGQLThreadInfo(true, "start", "restore") info := NewGQLThreadInfo(true, "start", "restore")

@ -271,12 +271,12 @@ func TestLockableLockTieredConflict(t * testing.T) {
} }
func TestLockableSimpleUpdate(t * testing.T) { func TestLockableSimpleUpdate(t * testing.T) {
ctx := testContext(t) ctx := logTestContext(t, []string{"test", "update", "lockable"})
l1, err := NewSimpleLockable(ctx, "Test Lockable 1", []Lockable{}) l1, err := NewSimpleLockable(ctx, "Test Lockable 1", []Lockable{})
fatalErr(t, err) fatalErr(t, err)
update_channel := l1.UpdateChannel(0) update_channel := l1.UpdateChannel(1)
go func() { go func() {
UseStates(ctx, []GraphNode{l1}, func(states NodeStateMap) error { UseStates(ctx, []GraphNode{l1}, func(states NodeStateMap) error {
@ -289,7 +289,7 @@ func TestLockableSimpleUpdate(t * testing.T) {
} }
func TestLockableDownUpdate(t * testing.T) { func TestLockableDownUpdate(t * testing.T) {
ctx := testContext(t) ctx := logTestContext(t, []string{"test", "update", "lockable"})
l1, err := NewSimpleLockable(ctx, "Test Lockable 1", []Lockable{}) l1, err := NewSimpleLockable(ctx, "Test Lockable 1", []Lockable{})
fatalErr(t, err) fatalErr(t, err)
@ -300,7 +300,7 @@ func TestLockableDownUpdate(t * testing.T) {
_, err = NewSimpleLockable(ctx, "Test Lockable 3", []Lockable{l2}) _, err = NewSimpleLockable(ctx, "Test Lockable 3", []Lockable{l2})
fatalErr(t, err) fatalErr(t, err)
update_channel := l1.UpdateChannel(0) update_channel := l1.UpdateChannel(1)
go func() { go func() {
UseStates(ctx, []GraphNode{l2}, func(states NodeStateMap) error { UseStates(ctx, []GraphNode{l2}, func(states NodeStateMap) error {
@ -313,7 +313,7 @@ func TestLockableDownUpdate(t * testing.T) {
} }
func TestLockableUpUpdate(t * testing.T) { func TestLockableUpUpdate(t * testing.T) {
ctx := logTestContext(t, []string{"test", "update"}) ctx := logTestContext(t, []string{"test", "update", "lockable"})
l1, err := NewSimpleLockable(ctx, "Test Lockable 1", []Lockable{}) l1, err := NewSimpleLockable(ctx, "Test Lockable 1", []Lockable{})
fatalErr(t, err) fatalErr(t, err)
@ -324,7 +324,7 @@ func TestLockableUpUpdate(t * testing.T) {
l3, err := NewSimpleLockable(ctx, "Test Lockable 3", []Lockable{l2}) l3, err := NewSimpleLockable(ctx, "Test Lockable 3", []Lockable{l2})
fatalErr(t, err) fatalErr(t, err)
update_channel := l3.UpdateChannel(0) update_channel := l3.UpdateChannel(1)
go func() { go func() {
UseStates(ctx, []GraphNode{l2}, func(states NodeStateMap) error { UseStates(ctx, []GraphNode{l2}, func(states NodeStateMap) error {
@ -337,7 +337,7 @@ func TestLockableUpUpdate(t * testing.T) {
} }
func TestOwnerNotUpdatedTwice(t * testing.T) { func TestOwnerNotUpdatedTwice(t * testing.T) {
ctx := testContext(t) ctx := logTestContext(t, []string{"test", "update", "lockable"})
l1, err := NewSimpleLockable(ctx, "Test Lockable 1", []Lockable{}) l1, err := NewSimpleLockable(ctx, "Test Lockable 1", []Lockable{})
fatalErr(t, err) fatalErr(t, err)
@ -345,7 +345,7 @@ func TestOwnerNotUpdatedTwice(t * testing.T) {
l2, err := NewSimpleLockable(ctx, "Test Lockable 2", []Lockable{l1}) l2, err := NewSimpleLockable(ctx, "Test Lockable 2", []Lockable{l1})
fatalErr(t, err) fatalErr(t, err)
update_channel := l2.UpdateChannel(0) update_channel := l2.UpdateChannel(1)
go func() { go func() {
UseStates(ctx, []GraphNode{l1}, func(states NodeStateMap) error { UseStates(ctx, []GraphNode{l1}, func(states NodeStateMap) error {