|
|
@ -7,16 +7,16 @@ import (
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
func TestEvent(t *testing.T) {
|
|
|
|
func TestEvent(t *testing.T) {
|
|
|
|
ctx := logTestContext(t, []string{"event", "listener"})
|
|
|
|
ctx := logTestContext(t, []string{"event", "listener", "listener_debug"})
|
|
|
|
err := ctx.RegisterExtension(reflect.TypeOf(&TestEventExt{}), NewExtType("TEST_EVENT"), nil)
|
|
|
|
err := ctx.RegisterExtension(reflect.TypeOf(&TestEventExt{}), NewExtType("TEST_EVENT"), nil)
|
|
|
|
fatalErr(t, err)
|
|
|
|
fatalErr(t, err)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
event_listener := NewListenerExt(100)
|
|
|
|
event_listener := NewListenerExt(100)
|
|
|
|
event, err := NewNode(ctx, nil, BaseNodeType, 100, nil, NewEventExt(nil, "Test Event"), &TestEventExt{}, event_listener)
|
|
|
|
event, err := NewNode(ctx, nil, BaseNodeType, 100, nil, NewEventExt(nil, "Test Event"), &TestEventExt{time.Second}, event_listener)
|
|
|
|
fatalErr(t, err)
|
|
|
|
fatalErr(t, err)
|
|
|
|
|
|
|
|
|
|
|
|
response, signals := testSend(t, ctx, NewEventControlSignal("start"), event, event)
|
|
|
|
response, signals := testSend(t, ctx, NewEventControlSignal("ready?"), event, event)
|
|
|
|
switch resp := response.(type) {
|
|
|
|
switch resp := response.(type) {
|
|
|
|
case *SuccessSignal:
|
|
|
|
case *SuccessSignal:
|
|
|
|
case *ErrorSignal:
|
|
|
|
case *ErrorSignal:
|
|
|
@ -28,7 +28,7 @@ func TestEvent(t *testing.T) {
|
|
|
|
var state_signal *EventStateSignal = nil
|
|
|
|
var state_signal *EventStateSignal = nil
|
|
|
|
for _, signal := range(signals) {
|
|
|
|
for _, signal := range(signals) {
|
|
|
|
event_state, is_event_state := signal.(*EventStateSignal)
|
|
|
|
event_state, is_event_state := signal.(*EventStateSignal)
|
|
|
|
if is_event_state == true && event_state.Source == event.ID && event_state.State == "running" {
|
|
|
|
if is_event_state == true && event_state.Source == event.ID && event_state.State == "ready" {
|
|
|
|
state_signal = event_state
|
|
|
|
state_signal = event_state
|
|
|
|
break
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -36,12 +36,12 @@ func TestEvent(t *testing.T) {
|
|
|
|
|
|
|
|
|
|
|
|
if state_signal == nil {
|
|
|
|
if state_signal == nil {
|
|
|
|
state_signal, err = WaitForSignal(event_listener.Chan, 10*time.Millisecond, func(sig *EventStateSignal) bool {
|
|
|
|
state_signal, err = WaitForSignal(event_listener.Chan, 10*time.Millisecond, func(sig *EventStateSignal) bool {
|
|
|
|
return sig.Source == event.ID && sig.State == "running"
|
|
|
|
return sig.Source == event.ID && sig.State == "ready"
|
|
|
|
})
|
|
|
|
})
|
|
|
|
fatalErr(t, err)
|
|
|
|
fatalErr(t, err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
response, signals = testSend(t, ctx, NewEventControlSignal("finish"), event, event)
|
|
|
|
response, signals = testSend(t, ctx, NewEventControlSignal("start"), event, event)
|
|
|
|
switch resp := response.(type) {
|
|
|
|
switch resp := response.(type) {
|
|
|
|
case *SuccessSignal:
|
|
|
|
case *SuccessSignal:
|
|
|
|
case *ErrorSignal:
|
|
|
|
case *ErrorSignal:
|
|
|
@ -53,7 +53,7 @@ func TestEvent(t *testing.T) {
|
|
|
|
state_signal = nil
|
|
|
|
state_signal = nil
|
|
|
|
for _, signal := range(signals) {
|
|
|
|
for _, signal := range(signals) {
|
|
|
|
event_state, is_event_state := signal.(*EventStateSignal)
|
|
|
|
event_state, is_event_state := signal.(*EventStateSignal)
|
|
|
|
if is_event_state == true && event_state.Source == event.ID && event_state.State == "done" {
|
|
|
|
if is_event_state == true && event_state.Source == event.ID && event_state.State == "running" {
|
|
|
|
state_signal = event_state
|
|
|
|
state_signal = event_state
|
|
|
|
break
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -61,11 +61,16 @@ func TestEvent(t *testing.T) {
|
|
|
|
|
|
|
|
|
|
|
|
if state_signal == nil {
|
|
|
|
if state_signal == nil {
|
|
|
|
state_signal, err = WaitForSignal(event_listener.Chan, 10*time.Millisecond, func(sig *EventStateSignal) bool {
|
|
|
|
state_signal, err = WaitForSignal(event_listener.Chan, 10*time.Millisecond, func(sig *EventStateSignal) bool {
|
|
|
|
return sig.Source == event.ID && sig.State == "done"
|
|
|
|
return sig.Source == event.ID && sig.State == "running"
|
|
|
|
})
|
|
|
|
})
|
|
|
|
fatalErr(t, err)
|
|
|
|
fatalErr(t, err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
_, err = WaitForSignal(event_listener.Chan, time.Second * 2, func(sig *EventStateSignal) bool {
|
|
|
|
|
|
|
|
return sig.Source == event.ID && sig.State == "done"
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
fatalErr(t, err)
|
|
|
|
|
|
|
|
|
|
|
|
response, signals = testSend(t, ctx, NewEventControlSignal("start"), event, event)
|
|
|
|
response, signals = testSend(t, ctx, NewEventControlSignal("start"), event, event)
|
|
|
|
switch resp := response.(type) {
|
|
|
|
switch resp := response.(type) {
|
|
|
|
case *SuccessSignal:
|
|
|
|
case *SuccessSignal:
|
|
|
|