Skip to content

Commit

Permalink
test block
Browse files Browse the repository at this point in the history
  • Loading branch information
nbari committed Sep 14, 2016
1 parent 6232cd0 commit d790063
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
2 changes: 1 addition & 1 deletion block.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ func (e *Epazote) Block() {
runtime.ReadMemStats(&m)
start := time.Now().UTC()
block := make(chan os.Signal)
signal.Notify(block, os.Interrupt, os.Kill, syscall.SIGTERM, syscall.SIGUSR1, syscall.SIGUSR2)
signal.Notify(block, syscall.SIGUSR1, syscall.SIGUSR2)
for {
signalType := <-block
switch signalType {
Expand Down
32 changes: 32 additions & 0 deletions block_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package epazote

import (
"io/ioutil"
"log"
"os"
"regexp"
"syscall"
"testing"
"time"
)

func TestBlock(t *testing.T) {
tmpfile, err := ioutil.TempFile("", "TestBlock")
defer os.Remove(tmpfile.Name())
if err != nil {
t.Error(err)
}
log.SetOutput(tmpfile)
log.SetFlags(0)
e := &Epazote{}
go e.Block()

select {
case <-time.After(1 * time.Second):
syscall.Kill(syscall.Getpid(), syscall.SIGUSR1)
time.Sleep(time.Second)
b, _ := ioutil.ReadFile(tmpfile.Name())
re := regexp.MustCompile(`Gorutines.*`)
expect(t, true, re.Match(b))
}
}

0 comments on commit d790063

Please sign in to comment.