-
Notifications
You must be signed in to change notification settings - Fork 58
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Problems with setup and teardown Tarantool in tests #147
Comments
It may be helpful: |
I have found only one simple way: kill child processes . I works but this is OS-dependent code. It should be implemented after supporting of all target platforms on CI, after #157 at least. an example for Linuxdiff --git a/test_helpers/cmd.go b/test_helpers/cmd.go
new file mode 100644
index 0000000..94b62ff
--- /dev/null
+++ b/test_helpers/cmd.go
@@ -0,0 +1,14 @@
+//go:build !linux
+
+package test_helpers
+
+import (
+ "os/exec"
+)
+
+// CommandKillOnExit tries to create a commant that will killed after a parent,
+// see a problem: https://github.com/golang/go/issues/37206
+// The default implementation just call a exec.Comman.
+func CommandKillOnExit(name string, arg ...string) *exec.Cmd {
+ return exec.Command(name, arg...)
+}
diff --git a/test_helpers/cmd_linux.go b/test_helpers/cmd_linux.go
new file mode 100644
index 0000000..5721376
--- /dev/null
+++ b/test_helpers/cmd_linux.go
@@ -0,0 +1,18 @@
+//go:build linux
+
+package test_helpers
+
+import (
+ "os/exec"
+ "syscall"
+)
+
+// CommandKillOnExit tries to create a commant that will killed after a parent,
+// see a problem: https://github.com/golang/go/issues/37206
+func CommandKillOnExit(name string, arg ...string) *exec.Cmd {
+ cmd := exec.Command(name, arg...)
+ cmd.SysProcAttr = &syscall.SysProcAttr{
+ Pdeathsig: syscall.SIGTERM,
+ }
+ return cmd
+}
diff --git a/test_helpers/main.go b/test_helpers/main.go
index 5c9d513..1e4a6a5 100644
--- a/test_helpers/main.go
+++ b/test_helpers/main.go
@@ -184,7 +184,7 @@ func RestartTarantool(inst *TarantoolInstance) error {
func StartTarantool(startOpts StartOpts) (TarantoolInstance, error) {
// Prepare tarantool command.
var inst TarantoolInstance
- inst.Cmd = exec.Command("tarantool", startOpts.InitScript)
+ inst.Cmd = CommandKillOnExit("tarantool", startOpts.InitScript)
inst.Cmd.Env = append(
os.Environ(), Another way is to add guard code to each test case which will catch a panic. func catchPanic() {
if (recover() != nil) {
// stop Tarantool
}
}
func TestCase(t *testing.T) {
defer catchPanic()
// test code
} But there are may be issues with subtests. |
other solution is to use unix sockets |
Could you please explain how this can help? |
panic()
. I don't know why. The test has a linedefer test_helpers.StopTarantoolWithCleanup(instance)
, according to blog post Defer, Panic, and Recover deferred function should be executed eve in case ofpanic()
:StartTarantool()
is not failed when Tarantool is already run on the same TCP portVersion: d3b5696
The text was updated successfully, but these errors were encountered: