ginkgo
ginkgo copied to clipboard
how to handle signal `SIGTERM`
https://onsi.github.io/ginkgo/#interrupting-aborting-and-timing-out-suites shows that if SIGTERM
is sent to ginkgo process,
Ginkgo will then run any clean-up and reporting nodes (AfterEach, JustAfterEach, AfterAll, DeferCleanup, ReportAfterEach code, etc.) for the current spec...
.
But the code as below will not run AfterEach
when using kill -15 <PID>
. how can I handle SIGTERM
in ginkgo
?
package mmy
import (
"fmt"
"testing"
"time"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
)
func TestMy(t *testing.T) {
RegisterFailHandler(Fail)
RunSpecs(t, "test my")
}
var _ = Describe("test my", func() {
AfterEach(func() {
fmt.Println("test over")
})
Context("test my", func() {
It("test my 01", func() {
time.Sleep(2 * time.Minute)
})
})
})
Hey @AkiraXie
A couple of things:
-
If you are sending the kill signal via
kill
you need to send the signal to the actual test process - not the Ginkgo CLI. Look for a*.test
process and send the signal to it's PID, not the PID of the Ginkgo CLI. Normally, if I want to interrupt the test, I just hit^C
on the console. That will send the interrupt signal to the foreground process tree which will include the CLI and the running test suite. -
You're using Ginkgo v1 which is no longer supported. If possible, please upgrade to v2. There is substantially better support for handling interrupts and cleaning up in v2.
thank you @onsi
- I used to building a binary by
ginkgo build
to run test. So <PID> I killed belongs to the x.test process, neither x_test.go nor ginkgo cli - I will try v2 to check clean-up later, thank u again