github.com/niedbalski/juju@v0.0.0-20190215020005-8ff100488e47/worker/terminationworker/worker_test.go (about) 1 // Copyright 2014 Canonical Ltd. 2 // Licensed under the AGPLv3, see LICENCE file for details. 3 4 package terminationworker_test 5 6 import ( 7 "os" 8 "runtime" 9 "testing" 10 11 jc "github.com/juju/testing/checkers" 12 gc "gopkg.in/check.v1" 13 14 "github.com/juju/juju/worker" 15 "github.com/juju/juju/worker/terminationworker" 16 ) 17 18 func TestPackage(t *testing.T) { 19 gc.TestingT(t) 20 } 21 22 var _ = gc.Suite(&TerminationWorkerSuite{}) 23 24 type TerminationWorkerSuite struct { 25 // c is a channel that will wait for the termination 26 // signal, to prevent signals terminating the process. 27 c chan os.Signal 28 } 29 30 func (s *TerminationWorkerSuite) TestStartStop(c *gc.C) { 31 w := terminationworker.NewWorker() 32 w.Kill() 33 err := w.Wait() 34 c.Assert(err, jc.ErrorIsNil) 35 } 36 37 func (s *TerminationWorkerSuite) TestSignal(c *gc.C) { 38 //TODO(bogdanteleaga): Inspect this further on windows 39 if runtime.GOOS == "windows" { 40 c.Skip("bug 1403084: sending this signal is not supported on windows") 41 } 42 w := terminationworker.NewWorker() 43 proc, err := os.FindProcess(os.Getpid()) 44 c.Assert(err, jc.ErrorIsNil) 45 defer proc.Release() 46 err = proc.Signal(terminationworker.TerminationSignal) 47 c.Assert(err, jc.ErrorIsNil) 48 err = w.Wait() 49 c.Assert(err, gc.Equals, worker.ErrTerminateAgent) 50 }