github.com/futurehomeno/fimpgo@v1.14.0/edgeapp/lifecycle_test.go (about) 1 package edgeapp 2 3 import ( 4 "testing" 5 "time" 6 ) 7 8 func TestLifecycle_WaitForState(t *testing.T) { 9 lf := NewAppLifecycle() 10 lf.SetAppState(AppStateRunning,nil) 11 lf.WaitForState("test-1",SystemEventTypeState,AppStateRunning) 12 lf.SetConfigState(ConfigStateConfigured) 13 lf.WaitForState("test-1",SystemEventTypeConfigState,ConfigStateConfigured) 14 lf.SetConfigState(ConfigStateConfigured) 15 lf.WaitForState("test-1",SystemEventTypeConfigState,ConfigStateConfigured) 16 17 go func() { 18 time.Sleep(time.Second*3) 19 lf.SetAuthState(AuthStateAuthenticated) 20 }() 21 lf.WaitForState("test-1",SystemEventTypeAuthState,AuthStateAuthenticated) 22 23 go func() { 24 time.Sleep(time.Second*2) 25 lf.PublishSystemEvent("testEvent","unitTest",nil) 26 }() 27 28 for evt := range lf.Subscribe("test-id",2) { 29 if evt.Type == SystemEventTypeEvent && evt.Name == "testEvent"{ 30 break 31 } 32 } 33 34 t.Log("OK") 35 36 }