tests: capture tarantool log tail in startup errors#587
Draft
tests: capture tarantool log tail in startup errors#587
Conversation
Two related issues from #147 made test failures painful to diagnose: 1. When a test panicked, the spawned tarantool process was left running and kept its TCP port bound, so the next run failed with "address already in use" instead of the original test failure. 2. The defer/require ordering used in many tests was inst, err := test_helpers.StartTarantool(opts) defer test_helpers.StopTarantoolWithCleanup(inst) require.NoError(t, err) When StartTarantool returned a nil instance on error (the connect failure path returns nil after stopping the half-started process), the deferred cleanup ran on a nil pointer and panicked, hiding the real "Unable to start Tarantool" failure under a nil-deref stack. Fix the first by setting Pdeathsig=SIGTERM on the tarantool command on Linux via a new test_helpers.commandKillOnExit helper, with a no-op fallback for other platforms (darwin has no Pdeathsig equivalent — see the comment in cmd_other.go). Fix the second by reordering every offending test site to assert StartTarantool succeeded before deferring the cleanup. This is the standard Go idiom and avoids growing a nil-guard inside the helper that would mask further StartTarantool bugs. Part of #147.
When StartTarantool fails, the returned error gives only the connection
or exit reason ("exit status 1", "context deadline exceeded"), so a CI
failure required re-running the test locally to see why tarantool
actually refused to come up. Tarantool's own diagnostics — bad config,
port conflicts, missing modules, Lua errors during init — were written
to the child's stdout/stderr and silently dropped on the floor.
Wire a small ring buffer into Cmd.Stdout/Stderr that retains the last
50 lines, append it to the StartTarantool error on the two failure
paths (unexpected exit and connect failure), and expose the same tail
on TarantoolInstance for live tests.
Add test_helpers.DumpLogsIfFailed so a passing StartTarantool followed
by a later assertion failure can surface the captured log via t.Logf.
Intended idiom:
inst, err := test_helpers.StartTarantool(opts)
require.NoError(t, err)
defer test_helpers.StopTarantoolWithCleanup(inst)
defer test_helpers.DumpLogsIfFailed(t, inst)
Buffer is safe for concurrent writes from exec.Cmd's two copy goroutines
and preserves a partial trailing line if the process exits without
flushing a newline.
Closes #147.
6dba26a to
0b5c01f
Compare
e5cea2a to
009c5df
Compare
0b5c01f to
fe5c21d
Compare
Base automatically changed from
bigbes/gh-147-fix-invalid-startup-panics
to
master
May 5, 2026 22:00
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
When
StartTarantoolfails, the returned error gives only the connection or exit reason (exit status 1,context deadline exceeded), so a CI failure required re-running the test locally to see why tarantool actually refused to come up. Tarantool's own diagnostics — bad config, port conflicts, missing modules, Lua errors during init — were written to the child's stdout/stderr and silently dropped on the floor.New
logTailBufferring of the last 50 lines, wired intoCmd.Stdout/Cmd.Stderr. Safe for concurrent writes from the two copy goroutines; preserves a partial trailing line if the process exits without flushing a newline.Append the captured tail to the
StartTarantoolerror on both failure paths (unexpected exit, connect failure).New
(*TarantoolInstance).LogTail()exposing the same buffer for live tests.New
test_helpers.DumpLogsIfFailed(t, inst)helper for the idiom:Closes #147.