ginkgo icon indicating copy to clipboard operation
ginkgo copied to clipboard

how to handle signal `SIGTERM`

Open AkiraXie opened this issue 2 years ago • 2 comments

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)
		})
	})
})

AkiraXie avatar Nov 02 '22 04:11 AkiraXie

Hey @AkiraXie

A couple of things:

  1. 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.

  2. 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.

onsi avatar Nov 02 '22 11:11 onsi

thank you @onsi

  1. 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
  2. I will try v2 to check clean-up later, thank u again

AkiraXie avatar Nov 02 '22 16:11 AkiraXie