|
|
|
@ -3,7 +3,7 @@ package main
|
|
|
|
|
import (
|
|
|
|
|
"testing"
|
|
|
|
|
"time"
|
|
|
|
|
"context"
|
|
|
|
|
"fmt"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
type graph_tester testing.T
|
|
|
|
@ -51,7 +51,7 @@ func TestNewResourceAdd(t *testing.T) {
|
|
|
|
|
description := "A resource for testing"
|
|
|
|
|
children := []Resource{}
|
|
|
|
|
|
|
|
|
|
root_event, _ := NewEvent("", "", []Resource{})
|
|
|
|
|
root_event := NewEvent("", "", []Resource{})
|
|
|
|
|
test_resource := NewResource(name, description, children)
|
|
|
|
|
event_manager := NewEventManager(root_event, []Resource{test_resource})
|
|
|
|
|
res := event_manager.FindResource(test_resource.ID())
|
|
|
|
@ -66,7 +66,7 @@ func TestNewResourceAdd(t *testing.T) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestDoubleResourceAdd(t * testing.T) {
|
|
|
|
|
root_event, _ := NewEvent("", "", []Resource{})
|
|
|
|
|
root_event := NewEvent("", "", []Resource{})
|
|
|
|
|
test_resource := NewResource("", "", []Resource{})
|
|
|
|
|
event_manager := NewEventManager(root_event, []Resource{test_resource})
|
|
|
|
|
err := event_manager.AddResource(test_resource)
|
|
|
|
@ -77,7 +77,7 @@ func TestDoubleResourceAdd(t * testing.T) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestMissingResourceAdd(t * testing.T) {
|
|
|
|
|
root_event, _ := NewEvent("", "", []Resource{})
|
|
|
|
|
root_event := NewEvent("", "", []Resource{})
|
|
|
|
|
r1 := NewResource("r1", "", []Resource{})
|
|
|
|
|
r2 := NewResource("r2", "", []Resource{r1})
|
|
|
|
|
|
|
|
|
@ -89,7 +89,7 @@ func TestMissingResourceAdd(t * testing.T) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestTieredResource(t * testing.T) {
|
|
|
|
|
root_event, _ := NewEvent("", "", []Resource{})
|
|
|
|
|
root_event := NewEvent("", "", []Resource{})
|
|
|
|
|
r1 := NewResource("r1", "", []Resource{})
|
|
|
|
|
r2 := NewResource("r2", "", []Resource{r1})
|
|
|
|
|
|
|
|
|
@ -100,7 +100,7 @@ func TestTieredResource(t * testing.T) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestResourceUpdate(t * testing.T) {
|
|
|
|
|
root_event, _ := NewEvent("", "", []Resource{})
|
|
|
|
|
root_event := NewEvent("", "", []Resource{})
|
|
|
|
|
r1 := NewResource("r1", "", []Resource{})
|
|
|
|
|
r2 := NewResource("r2", "", []Resource{})
|
|
|
|
|
r3 := NewResource("r3", "", []Resource{r1, r2})
|
|
|
|
@ -139,14 +139,14 @@ func TestResourceUpdate(t * testing.T) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestAddEvent(t * testing.T) {
|
|
|
|
|
root_event, _ := NewEvent("", "", []Resource{})
|
|
|
|
|
root_event := NewEvent("", "", []Resource{})
|
|
|
|
|
r1 := NewResource("r1", "", []Resource{})
|
|
|
|
|
r2 := NewResource("r2", "", []Resource{r1})
|
|
|
|
|
|
|
|
|
|
name := "Test Event"
|
|
|
|
|
description := "A test event"
|
|
|
|
|
resources := []Resource{r2}
|
|
|
|
|
new_event, _ := NewEvent(name, description, resources)
|
|
|
|
|
new_event := NewEvent(name, description, resources)
|
|
|
|
|
|
|
|
|
|
event_manager := NewEventManager(root_event, []Resource{r1})
|
|
|
|
|
err := event_manager.AddResource(r2)
|
|
|
|
@ -177,8 +177,8 @@ func TestAddEvent(t * testing.T) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestLockResource(t * testing.T) {
|
|
|
|
|
root_event, _ := NewEvent("", "", []Resource{})
|
|
|
|
|
test_event, _ := NewEvent("", "", []Resource{})
|
|
|
|
|
root_event := NewEvent("", "", []Resource{})
|
|
|
|
|
test_event := NewEvent("", "", []Resource{})
|
|
|
|
|
r1 := NewResource("r1", "", []Resource{})
|
|
|
|
|
r2 := NewResource("r2", "", []Resource{})
|
|
|
|
|
r3 := NewResource("r3", "", []Resource{r1, r2})
|
|
|
|
@ -243,9 +243,9 @@ func TestLockResource(t * testing.T) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestAddToEventQueue(t * testing.T) {
|
|
|
|
|
queue, _ := NewEventQueue("q", "", []Resource{})
|
|
|
|
|
event_1, _ := NewEvent("1", "", []Resource{})
|
|
|
|
|
event_2, _ := NewEvent("2", "", []Resource{})
|
|
|
|
|
queue := NewEventQueue("q", "", []Resource{})
|
|
|
|
|
event_1 := NewEvent("1", "", []Resource{})
|
|
|
|
|
event_2 := NewEvent("2", "", []Resource{})
|
|
|
|
|
|
|
|
|
|
err := queue.AddChild(event_1, nil)
|
|
|
|
|
if err == nil {
|
|
|
|
@ -264,7 +264,8 @@ func TestAddToEventQueue(t * testing.T) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestStartBaseEvent(t * testing.T) {
|
|
|
|
|
event_1, r := NewEvent("1", "", []Resource{})
|
|
|
|
|
event_1 := NewEvent("1", "", []Resource{})
|
|
|
|
|
r := event_1.DoneResource()
|
|
|
|
|
manager := NewEventManager(event_1, []Resource{})
|
|
|
|
|
|
|
|
|
|
e_l := event_1.UpdateChannel()
|
|
|
|
@ -276,7 +277,7 @@ func TestStartBaseEvent(t * testing.T) {
|
|
|
|
|
t.Fatal("r is not owned by event_1")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
err := manager.Run(context.Background())
|
|
|
|
|
err := manager.Run()
|
|
|
|
|
if err != nil {
|
|
|
|
|
t.Fatal(err)
|
|
|
|
|
}
|
|
|
|
@ -289,12 +290,50 @@ func TestStartBaseEvent(t * testing.T) {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestAbortEventQueue(t * testing.T) {
|
|
|
|
|
root_event := NewEventQueue("", "", []Resource{})
|
|
|
|
|
r := root_event.DoneResource()
|
|
|
|
|
manager := NewEventManager(root_event, []Resource{})
|
|
|
|
|
|
|
|
|
|
r1 := NewResource("r1", "", []Resource{})
|
|
|
|
|
err := manager.AddResource(r1)
|
|
|
|
|
if err != nil {
|
|
|
|
|
t.Fatal(err)
|
|
|
|
|
}
|
|
|
|
|
r1.Lock(root_event)
|
|
|
|
|
e1 := NewEvent("1", "", []Resource{r1})
|
|
|
|
|
e1_info := NewEventQueueInfo(1)
|
|
|
|
|
// Add an event so that the queue doesn't auto complete
|
|
|
|
|
err = manager.AddEvent(root_event, e1, e1_info)
|
|
|
|
|
if err != nil {
|
|
|
|
|
t.Fatal(err)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Now that an event manager is constructed with a queue and 3 basic events
|
|
|
|
|
// start the queue and check that all the events are executed
|
|
|
|
|
go func() {
|
|
|
|
|
time.Sleep(time.Second)
|
|
|
|
|
root_event.Abort()
|
|
|
|
|
}()
|
|
|
|
|
|
|
|
|
|
err = manager.Run()
|
|
|
|
|
if err == nil {
|
|
|
|
|
t.Fatal("event manager completed without error")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if r.Owner() == nil {
|
|
|
|
|
t.Fatal("root event was finished after starting")
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestStartEventQueue(t * testing.T) {
|
|
|
|
|
root_event, r := NewEventQueue("", "", []Resource{})
|
|
|
|
|
root_event := NewEventQueue("", "", []Resource{})
|
|
|
|
|
r := root_event.DoneResource()
|
|
|
|
|
rel := root_event.UpdateChannel();
|
|
|
|
|
manager := NewEventManager(root_event, []Resource{})
|
|
|
|
|
|
|
|
|
|
e1, e1_r := NewEvent("1", "", []Resource{})
|
|
|
|
|
e1:= NewEvent("1", "", []Resource{})
|
|
|
|
|
e1_r := e1.DoneResource()
|
|
|
|
|
e1_info := NewEventQueueInfo(1)
|
|
|
|
|
err := manager.AddEvent(root_event, e1, e1_info)
|
|
|
|
|
if err != nil {
|
|
|
|
@ -302,7 +341,8 @@ func TestStartEventQueue(t * testing.T) {
|
|
|
|
|
}
|
|
|
|
|
(*graph_tester)(t).CheckForNil(rel)
|
|
|
|
|
|
|
|
|
|
e2, e2_r := NewEvent("1", "", []Resource{})
|
|
|
|
|
e2 := NewEvent("1", "", []Resource{})
|
|
|
|
|
e2_r := e2.DoneResource()
|
|
|
|
|
e2_info := NewEventQueueInfo(2)
|
|
|
|
|
err = manager.AddEvent(root_event, e2, e2_info)
|
|
|
|
|
if err != nil {
|
|
|
|
@ -310,7 +350,8 @@ func TestStartEventQueue(t * testing.T) {
|
|
|
|
|
}
|
|
|
|
|
(*graph_tester)(t).CheckForNil(rel)
|
|
|
|
|
|
|
|
|
|
e3, e3_r := NewEvent("1", "", []Resource{})
|
|
|
|
|
e3 := NewEvent("1", "", []Resource{})
|
|
|
|
|
e3_r := e3.DoneResource()
|
|
|
|
|
e3_info := NewEventQueueInfo(3)
|
|
|
|
|
err = manager.AddEvent(root_event, e3, e3_info)
|
|
|
|
|
if err != nil {
|
|
|
|
@ -322,16 +363,21 @@ func TestStartEventQueue(t * testing.T) {
|
|
|
|
|
e2_l := e2.UpdateChannel();
|
|
|
|
|
e3_l := e3.UpdateChannel();
|
|
|
|
|
|
|
|
|
|
// Abort the event after 5 seconds just in case
|
|
|
|
|
go func() {
|
|
|
|
|
time.Sleep(5 * time.Second)
|
|
|
|
|
root_event.Abort()
|
|
|
|
|
}()
|
|
|
|
|
|
|
|
|
|
// Now that an event manager is constructed with a queue and 3 basic events
|
|
|
|
|
// start the queue and check that all the events are executed
|
|
|
|
|
err = manager.Run(context.Background())
|
|
|
|
|
err = manager.Run()
|
|
|
|
|
if err != nil {
|
|
|
|
|
t.Fatal(err)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
time.Sleep( 5 * time.Second)
|
|
|
|
|
|
|
|
|
|
if r.Owner() != nil {
|
|
|
|
|
fmt.Printf("root_event.DoneResource(): %p", root_event.DoneResource())
|
|
|
|
|
t.Fatal("root event was not finished after starting")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|