|
@@ -9,13 +9,6 @@ import (
|
|
|
func TestStateRunStop(t *testing.T) {
|
|
|
s := NewState()
|
|
|
for i := 1; i < 3; i++ { // full lifecycle two times
|
|
|
- started := make(chan struct{})
|
|
|
- var pid int64
|
|
|
- go func() {
|
|
|
- runPid, _ := s.WaitRunning(-1 * time.Second)
|
|
|
- atomic.StoreInt64(&pid, int64(runPid))
|
|
|
- close(started)
|
|
|
- }()
|
|
|
s.Lock()
|
|
|
s.SetRunning(i+100, false)
|
|
|
s.Unlock()
|
|
@@ -29,19 +22,6 @@ func TestStateRunStop(t *testing.T) {
|
|
|
if s.ExitCode != 0 {
|
|
|
t.Fatalf("ExitCode %v, expected 0", s.ExitCode)
|
|
|
}
|
|
|
- select {
|
|
|
- case <-time.After(100 * time.Millisecond):
|
|
|
- t.Fatal("Start callback doesn't fire in 100 milliseconds")
|
|
|
- case <-started:
|
|
|
- t.Log("Start callback fired")
|
|
|
- }
|
|
|
- runPid := int(atomic.LoadInt64(&pid))
|
|
|
- if runPid != i+100 {
|
|
|
- t.Fatalf("Pid %v, expected %v", runPid, i+100)
|
|
|
- }
|
|
|
- if pid, err := s.WaitRunning(-1 * time.Second); err != nil || pid != i+100 {
|
|
|
- t.Fatalf("WaitRunning returned pid: %v, err: %v, expected pid: %v, err: %v", pid, err, i+100, nil)
|
|
|
- }
|
|
|
|
|
|
stopped := make(chan struct{})
|
|
|
var exit int64
|
|
@@ -78,32 +58,30 @@ func TestStateRunStop(t *testing.T) {
|
|
|
|
|
|
func TestStateTimeoutWait(t *testing.T) {
|
|
|
s := NewState()
|
|
|
- started := make(chan struct{})
|
|
|
+ stopped := make(chan struct{})
|
|
|
go func() {
|
|
|
- s.WaitRunning(100 * time.Millisecond)
|
|
|
- close(started)
|
|
|
+ s.WaitStop(100 * time.Millisecond)
|
|
|
+ close(stopped)
|
|
|
}()
|
|
|
select {
|
|
|
case <-time.After(200 * time.Millisecond):
|
|
|
- t.Fatal("Start callback doesn't fire in 100 milliseconds")
|
|
|
- case <-started:
|
|
|
- t.Log("Start callback fired")
|
|
|
+ t.Fatal("Stop callback doesn't fire in 100 milliseconds")
|
|
|
+ case <-stopped:
|
|
|
+ t.Log("Stop callback fired")
|
|
|
}
|
|
|
|
|
|
- s.Lock()
|
|
|
- s.SetRunning(49, false)
|
|
|
- s.Unlock()
|
|
|
+ s.SetStoppedLocking(&ExitStatus{ExitCode: 1})
|
|
|
|
|
|
- stopped := make(chan struct{})
|
|
|
+ stopped = make(chan struct{})
|
|
|
go func() {
|
|
|
- s.WaitRunning(100 * time.Millisecond)
|
|
|
+ s.WaitStop(100 * time.Millisecond)
|
|
|
close(stopped)
|
|
|
}()
|
|
|
select {
|
|
|
case <-time.After(200 * time.Millisecond):
|
|
|
- t.Fatal("Start callback doesn't fire in 100 milliseconds")
|
|
|
+ t.Fatal("Stop callback doesn't fire in 100 milliseconds")
|
|
|
case <-stopped:
|
|
|
- t.Log("Start callback fired")
|
|
|
+ t.Log("Stop callback fired")
|
|
|
}
|
|
|
|
|
|
}
|