Skip to content
This repository has been archived by the owner on Feb 3, 2018. It is now read-only.

Commit

Permalink
chan insstead of real sigs in TestSignalHandling
Browse files Browse the repository at this point in the history
Using actual signals was far too flaky in tests.
  • Loading branch information
sdboyer committed Apr 3, 2017
1 parent 564fe67 commit 8847ade
Showing 1 changed file with 21 additions and 42 deletions.
63 changes: 21 additions & 42 deletions manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -717,11 +717,6 @@ func TestSignalHandling(t *testing.T) {
}

sm, clean := mkNaiveSM(t)
//get self proc
proc, err := os.FindProcess(os.Getpid())
if err != nil {
t.Fatal("cannot find self proc")
}

sigch := make(chan os.Signal)
sm.HandleSignals(sigch)
Expand All @@ -739,24 +734,18 @@ func TestSignalHandling(t *testing.T) {
}
clean()

// Test again, this time with a running call
sm, clean = mkNaiveSM(t)
sm.UseDefaultSignalHandling()
sm.HandleSignals(sigch)

errchan := make(chan error)
go func() {
_, callerr := sm.DeduceProjectRoot("rsc.io/pdf")
_, callerr := sm.DeduceProjectRoot("k8s.io/kubernetes")
errchan <- callerr
}()
go func() { sigch <- os.Interrupt }()
runtime.Gosched()

// signal the process and call release right afterward
now := time.Now()
proc.Signal(os.Interrupt)
sigdur := time.Since(now)
t.Logf("time to send signal: %v", sigdur)
sm.Release()
reldur := time.Since(now) - sigdur
t.Logf("time to return from Release(): %v", reldur)

callerr := <-errchan
if callerr == nil {
t.Error("network call could not have completed before cancellation, should have gotten an error")
Expand All @@ -771,40 +760,30 @@ func TestSignalHandling(t *testing.T) {
}
clean()

// proc.Signal(os.Interrupt) does nothing on windows, so skip this part
if runtime.GOOS == "windows" {
return
}

sm, clean = mkNaiveSM(t)
// Ensure that handling also works after stopping and restarting itself,
// and that Release happens only once.
sm.UseDefaultSignalHandling()
sm.StopSignalHandling()
sm.UseDefaultSignalHandling()
sm.HandleSignals(sigch)

go sm.DeduceProjectRoot("rsc.io/pdf")
go sm.DeduceProjectRoot("k8s.io/kubernetes")
go func() {
_, callerr := sm.DeduceProjectRoot("k8s.io/kubernetes")
errchan <- callerr
}()
go func() {
sigch <- os.Interrupt
sm.Release()
}()
runtime.Gosched()

// Ensure that it all works after teardown and re-set up
proc.Signal(os.Interrupt)

after := time.After(3 * time.Second)
tick := time.NewTicker(25 * time.Microsecond)
loop:
for {
select {
case <-tick.C:
if atomic.LoadInt32(&sm.releasing) == 1 {
tick.Stop()
break loop
}
case <-after:
tick.Stop()
t.Fatalf("did not receive signal in reasonable time")
}
after := time.After(2 * time.Second)
select {
case <-sm.qch:
case <-after:
t.Fatalf("did not shut down in reasonable time")
}

<-sm.qch
clean()
}

Expand Down

0 comments on commit 8847ade

Please sign in to comment.