Skip to content

tests: capture tarantool log tail in startup errors#587

Draft
bigbes wants to merge 2 commits intomasterfrom
bigbes/gh-147-capture-tarantool-log-tail
Draft

tests: capture tarantool log tail in startup errors#587
bigbes wants to merge 2 commits intomasterfrom
bigbes/gh-147-capture-tarantool-log-tail

Conversation

@bigbes
Copy link
Copy Markdown
Collaborator

@bigbes bigbes commented May 5, 2026

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.

  • New logTailBuffer ring of the last 50 lines, wired into Cmd.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 StartTarantool error 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:

    inst, err := test_helpers.StartTarantool(opts)
    require.NoError(t, err)
    defer test_helpers.StopTarantoolWithCleanup(inst)
    defer test_helpers.DumpLogsIfFailed(t, inst)

Closes #147.

bigbes added 2 commits May 5, 2026 12:02
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.
@bigbes bigbes force-pushed the bigbes/gh-147-fix-invalid-startup-panics branch from 6dba26a to 0b5c01f Compare May 5, 2026 09:07
@bigbes bigbes force-pushed the bigbes/gh-147-capture-tarantool-log-tail branch from e5cea2a to 009c5df Compare May 5, 2026 09:07
@oleg-jukovec oleg-jukovec force-pushed the bigbes/gh-147-fix-invalid-startup-panics branch from 0b5c01f to fe5c21d Compare May 5, 2026 21:46
Base automatically changed from bigbes/gh-147-fix-invalid-startup-panics to master May 5, 2026 22:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant