From 30b888c3ece8aa4b8d67bfdb96e650a96a87ba14 Mon Sep 17 00:00:00 2001 From: Dominic Della Valle Date: Fri, 14 May 2021 08:53:08 -0400 Subject: [PATCH] fix: signal test calls must be in same goroutine --- service_test.go | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/service_test.go b/service_test.go index 886b0cfb..e60367a6 100644 --- a/service_test.go +++ b/service_test.go @@ -5,6 +5,7 @@ package service_test import ( + "fmt" "os" "testing" "time" @@ -22,22 +23,27 @@ func TestRunInterrupt(t *testing.T) { t.Fatalf("New err: %s", err) } + retChan := make(chan error) + go func() { + if err = s.Run(); err != nil { + retChan <- fmt.Errorf("Run() err: %w", err) + } + }() go func() { <-time.After(1 * time.Second) interruptProcess(t) - }() - go func() { for i := 0; i < 25 && p.numStopped == 0; i++ { <-time.After(200 * time.Millisecond) } if p.numStopped == 0 { - t.Fatal("Run() hasn't been stopped") + retChan <- fmt.Errorf("Run() hasn't been stopped") } + retChan <- nil }() - if err = s.Run(); err != nil { - t.Fatalf("Run() err: %s", err) + if err = <-retChan; err != nil { + t.Fatal(err) } }