Skip to content

ginkgo: report through gorp.Session - #54

Draft
DzmitryHumianiuk wants to merge 18 commits into
feat/sessionfrom
feat/session-ginkgo
Draft

DzmitryHumianiuk wants to merge 18 commits into
feat/sessionfrom
feat/session-ginkgo

Conversation

@DzmitryHumianiuk

Copy link
Copy Markdown
Member

Summary

Part of #27. Refs #52.

#52 says L6 merges only together with a second consumer of gorp.Session. This is that consumer: the Ginkgo agent from #15 now reports through the session.

This PR is based on feat/session (the L6 PR). It also stacks on #15: head 923718e is merged in as 0f6fafa. Until #15 is merged, the diff against feat/session shows #15 as well. Review the commits on top of 0f6fafa:

  • 7377b08 Add Launch.AbortItems: abort without the launch finish (pkg/gorp). Superseded: AbortItems now lives on feat/session (9aca770), and the merge 12b984b takes pkg/gorp from there.
  • 15959b7 ginkgo: report through gorp.Session (pkg/ginkgo)
  • 12b984b Merge feat/session into feat/session-ginkgo (the L6 review fixes and AbortItems)
  • 3548ead ginkgo: follow the session's abort rules (pkg/ginkgo)
  • 8055c7e Merge feat/session into feat/session-ginkgo (round 2 of the L6 review: 8da3e4d)
  • fff248d ginkgo: reuse a container start that outlived its wait; bound waits by the retry budget (pkg/ginkgo)

pkg/ginkgo does not build on its own yet. pkg/ginkgo/go.mod still requires the released goRP v5.2.2, which has no Session. It needs a goRP release that includes L6, then a bump of the require. Until then the module builds only through a workspace (task ginkgo:workspace, or GOWORK pointing to a go.work with . and ./pkg/ginkgo). The require is left alone on purpose.

For the same reason these fail on this branch, locally and in .github/workflows/build.yml:

  • task ginkgo:build, ginkgo:vet and ginkgo:test, so root task test too;
  • task ginkgo:lint (Docker);
  • the CI steps "golangci-lint (pkg/ginkgo)" and "go.mod and go.sum are tidy (pkg/ginkgo)".

Only the CI step task ginkgo:workspace can pass. See Open questions for the merge order.

The areas that #15 round 5 asked its author to change (cmd/ginkgo-rp/proc_unix.go and the job-control tests) are not touched.

Changes

Merge of feat/session (12b984b)

  • Conflicts in pkg/gorp/session.go, pkg/gorp/session_test.go and AGENTS.md (7377b08 against the L6 review fixes), resolved in favour of feat/session. After the merge git diff feat/session -- pkg/gorp README.md AGENTS.md .claude internal e2e is empty: the only differences from feat/session are Add Ginkgo v2 agent and ginkgo-rp wrapper (pkg/ginkgo) #15 and pkg/ginkgo.
  • Launch.AbortItems is documented in the L6 PR: Abort without the launch finish, same endMu, drop, 2 s log wait; a later Finish returns ErrSessionClosed; its error never matches ErrLaunchNotFinished.

Adapting to the session's rules (3548ead)

  • rpagent.FinalizeLaunch (launch_coordinator.go) took any Finish error that did not match ErrLaunchNotFinished for success and printed SUCCESS. After the merge, Finish after or during an abort returns ErrSessionClosed and sends nothing. It now goes by the answer: rs == nil means this call did not finish the launch. The error then matches ErrLaunchNotFinished (plus ErrSessionClosed after an abort), and the wrapper stops the launch. A non-nil rs with item errors is still success. New case in TestFinalizeLaunchClosesTheLaunchAndPrintsTheServersLink: AbortItems, then FinalizeLaunch returns ErrLaunchNotFinished + ErrSessionClosed, sends no finish and prints no SUCCESS. It fails on 12b984b (err=<nil>, "SUCCESS: launch L1 finalized").
  • rpLaunch.abort (cmd/ginkgo-rp/main.go) needed no code change, only a comment. It prints the AbortItems error as a warning and always sends the STOPPED launch finish itself, with the client and its own third of stopLaunchTimeout. It never tests for ErrLaunchNotFinished, so "N logs were not sent" from AbortItems can't be taken for a finished launch.
  • Checked, no change needed:
    • StartLaunch / AttachLaunch returning ErrSessionClosed: neither session can be closed while those calls run. The wrapper calls StartLaunch (main.go, initLaunch) before anything can close it. NewTestListener (test_listener.go:79) attaches before the listener is returned. A failed attach leaves tl.launch nil, and Start, finishItem, QueueLog and SendAttachmentLog all check for nil first.
    • Item.Wait → ErrBreakerOpen / ErrSessionClosed: both callers (main.go suite creation, StartAndWait) handle any error.
    • The 2 s log limit: the only log of the wrapper's own session is the "not run" note of a suite (finishSuitesFromResults). Finish drains it without the limit; only an abort after a failed finalization can cut it.

Round 2 of the review (8055c7e, fff248d)

  • Merge of feat/session 8da3e4d. No conflicts. Abort/AbortItems now try every open item after a transient failure and give up after the breaker threshold of failures in a row (3) or when ctx ends; ctx bounds the wait between Finish and Abort; Flush fails when what it waited for was dropped; an unreadable attachment loses only its log; same-named attachments go in separate requests. See the L6 PR.
  • Container start that outlives its wait (B3). ProcessSpecWithHierarchyAndReturnIDs used StartAndWait with httpTimeout (30 s), the same as one HTTP attempt. A first attempt that timed out ended the wait while retries 2 and 3 were still to come: GetOrCreate got "", the spec fell back to the suite, and the next spec under the same container started a second "Describe X". The first one, stored by a retry, was in no spec status, so the wrapper never finished it.
    • The wait is now containerStartWait = requestBudget(): 3 attempts × httpTimeout + 2 × MaxWait (10 s, a Retry-After may ask for it) = 110 s. workerRetryPolicy spells out MaxWait (gorp's default) for that.
    • The wait can still end first (the start queues behind other operations of the session). New TestListener.StartShared(key, wait, item): when the wait ends first it returns "" (so GetOrCreate publishes nothing and other workers get no UUID the server may not have yet) but keeps the item as pending under the cache key, on the listener (not package state). PendingShared(key) gives it to the caller, which reports the spec under it: this process's session sends the children after the container, and the spec status carries the UUID to the wrapper, which finishes the container with the results. The next spec's StartShared for that key waits for the pending item again instead of starting a new one, and publishes it once it is answered.
    • Limit, not changed: GetOrCreate removes its lock file when createFunc returns, so while the container is pending another worker process can take the lock and start its own "Describe X" (its losers still wait 10 s first). Reworking the lock protocol is out of scope.
  • Last Flush of a worker (plausible finding, confirmed). flushReports was bounded by 30 s = one HTTP attempt. A worker that is not process 1 exits after its last spec's ReportAfterEach, so a request whose first attempt hung lost its retries and everything queued behind it. The bound is now requestBudget() (110 s). It applies per hook, i.e. per spec; the total stall before the breaker opens is at most 3 such requests (each failing all attempts), as before, because the session kept sending in the background anyway.
  • httpTimeout never applied. NewReportingClient set it only when the client's timeout was 0, but the client of gorp.WithApiKeyAuth always has gorp's 30 s. Same value, so no behaviour change; it is set unconditionally now (and is a variable, so tests can shorten it).
  • pkg/ginkgo/README.md: the per-spec wait is "up to 110 s, one request with all its retries" (was 30 s).
  • Wrapper abort (B2). rpLaunch.abort keeps its 2/3 + 1/3 budget and its own STOPPED launch finish. With the new AbortItems a 503 on one suite no longer leaves the other suites open. The wrapper client has no retries, so a hanging server costs at most the 20 s items budget (one 30 s attempt is cut by ctx), and 3 fast 5xx in a row stop the suites; the launch finish is tried in either case. Comment updated.
  • Tests: TestHierarchyReusesAContainerStartThatOutlivedItsWait (container_cache_test.go; 100 ms wait, first start answered after 300 ms: one stored "Describe X", both specs under it; a third spec after the answer publishes the UUID to the cache file, which a fresh process then reads without starting it again; before: started twice), TestFlushReportsWaitsForTheRetriesOfAHungRequest (flush_budget_test.go; httpTimeout 100 ms, first attempt hangs, the retry is answered: stored after flushReports; with the old bound, reportFlushTimeout = httpTimeout, nothing was stored, 1 attempt), TestAbortTriesEverySuiteAfterATransientFailure (cmd/ginkgo-rp/main_test.go, ported from the reviewer: suite-c:503, suite-b:200, suite-a:200, launch:STOPPED; on 3548ead's pkg/gorp it fails).

pkg/ginkgo/rpagent: workers

  • TestListener now only builds requests. It holds a session attached to the wrapper's launch (AttachLaunch, no I/O in init()) and keeps a UUID → *gorp.Item map of the items this process started. Any other ID is reported to as a handle (Launch.Item): the wrapper's suite, a container another worker created, or spec-item in tests.
    • Start returns the client UUID at once.
    • Shared containers: the lock-file winner publishes the UUID in rp_cache_* only after the start was answered. Since round 2 this is StartShared (wait bounded by the 110 s retry budget, pending reuse; see Round 2); before, StartAndWait bounded by the 30 s HTTP timeout. GetOrCreate and the cache files are unchanged.
    • FinishTest/FinishTestNotIssue, QueueLog and SendAttachmentLog queue into the session.
    • New: Flush and Close.
  • Removed from the agent:
    • isRetriableError and retry (3 attempts with sleeps; this loop replayed log batches);
    • the pending queue, QueueLog's own batching, FlushLogs, maxBatchLogs/maxBatchBytes and per-log UUIDs;
    • SendLog;
    • the dead FinishSuite and SendLaunchLog, which no code called. A worker must not finish a wrapper-owned suite anyway;
    • limits.go (boundedName, boundedID, utf16Len) and its test. Names and uniqueIds are now shortened by the session, and testCaseId uses gorp.BoundedID(id, gorp.MaxTestCaseIDLength);
    • globalClient, and the unused client parameter of ProcessSpecWithHierarchyAndReturnIDs.
  • Retries: worker clients use gorp.WithRetry(RetryPolicy{MaxRetries: 2, MinWait: 200ms}). Starts and finishes get 3 attempts, as before. Logs are sent once.
  • Flush per spec: ReportAfterEach ends with Flush (30 s bound). ReportAfterSuite calls Close (same bound) after finishOpenHierarchies and before CleanupAttachments and the done flag. The design (§7.2) put only Close in ReportAfterSuite. That is not enough: in a parallel run only one process runs ReportAfterSuite (Investigation log 4).
  • Attachments:
    • The file is opened, its content type sniffed and the file closed again.
    • It is then queued as a gorp.ReaderMultipart named after the original file. Its reader (stagedFile) opens the temp copy when the session sends the log, and closes and removes it at the end.
    • A log that is dropped (breaker open, item not started) never opens its file, so an outage can't use up the test process's file descriptors.
    • The temp copy is still removed after it is sent, but no longer only after a successful upload.
  • FinalizeLaunch(ctx, launch, forceFailed) takes the wrapper's *gorp.Launch and calls Launch.Finish.
    • It returns an error only when the launch was not finished (ErrLaunchNotFinished, shortened to ErrBreakerOpen when the breaker opened).
    • Errors of items (a 4xx on a container) were already printed by the error handler. They don't fail finalization, as before.
  • NewReportingClient(endpoint, project, apiKey, debug, opts ...gorp.Option): the new variadic opts are passed through.

pkg/ginkgo/cmd/ginkgo-rp: the wrapper

  • createRPLaunchAndSaveState returns an *rpLaunch (client, *gorp.Launch, suite items by directory) instead of the launch ID and the suite cache.
    • The launch is started with Session.StartLaunch, so the UUID is the one in the response.
    • All suites are queued, then each is waited for (Item.Wait) before it goes into the suite cache.
    • Any later error calls rl.abort, as stopLaunch did before.
  • finishSuitesFromResults and finishContainers only queue now: launch.Item(c.ID).Finish for containers, and suite.Log/suite.Finish for suites. They no longer return errors, read the state and config files again or build a client.
  • rpLaunch.abort(ctx) replaces abortLaunch and stopLaunch. It runs AbortItems within 2/3 of stopLaunchTimeout, then client.FinishLaunch(STOPPED) within the last 1/3. Failures are printed as warnings.
  • Removed: failureStreak, maxConsecutiveFinishFailures, errReportPortalNotResponding, abortLaunch and stopLaunch. The 3-in-a-row rule is now the session breaker.
  • The wrapper calls AbortItems and then FinishLaunch(STOPPED) itself, not Abort. That is a deviation from design §7.2; Investigation log 3 explains why.
  • The wrapper's session prints each reporting error as WARNING: … when it happens, which matches the old per-item warnings. The wrapper's client still has no WithRetry. Its calls are single attempts, as before, and as the attempt-count assertions require.
  • Exit codes and messages are unchanged:
    • Ginkgo's exit code;
    • 2 in strict mode when finalizing failed;
    • 128+signal;
    • "finalizing took longer than …", "Stopping the launch instead.", the launch link.

Tests

  • Fakes now echo the request uuid, as ReportPortal does: fakeRP (e2e_test.go), flowServer and echoID.
    • Where assertions named the fakes' own IDs (step-1, id-1), a small aliases helper maps the client UUIDs back to those names in start order (outputHarness, TestFinishSpecHierarchyUsesGinkgoTimeline, recordingRP). The assertions themselves are unchanged.
    • Harnesses flush the listener in their getters or right after the call under test.
  • Replaced:
    • TestIsRetriableError, TestFlushLogsBatchesAndSplitsBySize, TestFailureStreak* and TestFinishContainersStopsWhenCancelled: the session's own tests cover this behaviour.
    • TestStartTest{Retries…,DoesNotRetry…} became TestWorker{RetriesServerErrorWithSameUUID,DoesNotRetryClientError}, through workerRetry.
    • New TestWorkerNeverSendsALogTwice: a log batch that gets a 503 is sent once.
    • New TestSendAttachmentLogOpensTheFileOnlyToSendIt: with the breaker open, 5 attachments leave their files unread. A stagedFile is opened only by Read, then closed and removed at EOF.
    • TestFinishContainersGivesUpAfterConsecutiveFailures now checks that the session breaker stops after 3 requests out of 20.
    • TestFinalizeLaunch… now uses a launch started by a session.
  • Removed with their code: TestFinishSuiteAndLaunchLog, TestSendAttachmentLogUploadRejectedKeepsMessage (see Behaviour change) and limits_test.go.
  • TestHierarchySurvivesContainerStartFailure now asserts that the spec falls back under the suite. A spec item always has a UUID now, so the old check (StepID empty) no longer applies.
  • The wrapper's e2e tests (cmd/ginkgo-rp/e2e_test.go, real ginkgo against fakeRP) are unchanged except for the uuid echo. That includes the round 4/5 guarantees:
    • TestWrapperFinalizeFailureKeepsGinkgoExitCode: [PASSED STOPPED], and exit 2 in strict mode;
    • TestWrapperGivesUpOnItemsAfterThreeFailuresInARow: level3, level2, level1, Fixture Suite and launch [STOPPED];
    • TestWrapperKeepsFinishingItemsWhenTheyAreRejected: a 4xx doesn't count;
    • TestWrapperAbortFinishesSuitesThenLaunchAsStopped;
    • the deadline, signal and second-signal tests.

Behaviour change

  • Logs are no longer duplicated. A log batch that failed after the server stored it used to be sent up to 3 times (retry around SaveLogs/SaveLogMultipart). Logs are now sent once. Starts and finishes are still retried, with the same client UUID.
  • Worker requests are asynchronous within a spec. A spec's starts, logs and finishes are sent in order in the background, and the hook waits once at the end of ReportAfterEach (bounded by one request's retry budget, 110 s; 30 s before round 2). Before, it waited for every request. Logs are no longer guaranteed to arrive before the item finish; the server accepts logs for a finished item.
  • A process stops reporting after 3 transient failures in a row (session breaker). Before, every request was tried 3 times until the end of the run.
  • Failed starts.
    • A spec or By() step whose start fails no longer falls back: its logs used to be re-routed to the parent. The session now skips its logs, finish and children and logs ErrNotStarted as a warning. A failed start is not known when the hook runs.
    • A failed container start still falls back to the parent, because the winner waits for it. A container start that is still under way when the wait (110 s) ends is used by this process and published to the others once answered (round 2). Trade-off: if that start finally fails, the specs already reported under it are skipped by the session (ErrNotStarted, logged); before, they fell back to the suite.
  • Attachment upload failures are logged as warnings in the worker. They no longer produce a replacement text log "[attachment … could not be uploaded]" on the item.
    • Attachments now share batch requests with other logs: 10 logs per request, attachments included.
    • The size of a ReaderMultipart is unknown to the batcher's MaxBytes. With the default 10 MB attachment limit, one request carries at most 100 MB, under the server's 128 MB.
  • Log batching follows the session defaults: 10 logs per request, at most 4 requests at a time, and a 5 s timer. Before, it was 200 logs or 2 MB per request, sent at the end of the spec. README "Network Resilience" is updated.
  • Item names are shortened by gorp.Truncate, which, like boundedName, counts UTF-16 units and ends in .... testCaseId uses gorp.BoundedID, which equals the old boundedID for ASCII IDs: TestOverLongIdentityKeepsUniqueIDOfTheFullID still gets exactly 1024 characters ending in ~c7fca14d35e62afd. For non-ASCII IDs over the limit the cut differs: boundedID counted bytes, BoundedID counts UTF-16 units. Add Ginkgo v2 agent and ginkgo-rp wrapper (pkg/ginkgo) #15 is unreleased, so no history depends on the old form.
  • Attributes are shortened by TruncateAttributes, to 128 characters per key and value.
  • Wrapper: the "launch created but returned empty ID" message is now the session's "the response has no launch UUID".

Verification

All pkg/ginkgo commands run through a temporary workspace: go work init <l6g> <l6g>/pkg/ginkgo in a scratch directory, with GOWORK pointing to it. No go.work is committed.

  • cd pkg/ginkgo && go build ./... && go vet ./... && GOOS=windows go vet ./... && go vet -tags sanity ./examples/...: OK.

  • go test -race -count=1 -cover ./... in pkg/ginkgo:

    Package Result Coverage
    cmd/ginkgo-rp (includes the wrapper e2e tests, 46.7 s) ok 90.1% (baseline 923718e: 89.2%)
    rpagent ok 87.5% (baseline 88.4%)

    go test -race -count=3 ./rpagent/ also passes.

  • Root module (GOWORK=off go test -race -count=1 ./...): OK. go test -race -count=5 -run TestSession_ ./pkg/gorp/: OK.

  • Lint, golangci-lint v2.15.0:

  • Live, local ReportPortal 6.0.0 (docker-compose gorp-local, not demo). Fixtures were copied from scratchpad/live to scratchpad/live-l6g, with replaces to this branch's pkg/ginkgo and root. The baseline used the same copy pointed at pr15-wt (923718e) and a wrapper built from it.

    • Sequential run: ginkgo-rp -r --keep-going.
    • Parallel run: ginkgo-rp -r -p --procs=3 --keep-going --skip-package=slow.
    • The trees were dumped with scratchpad/l6g-tools/rptree.py (each item's path, type, status, hasStats, retries, issue and log count) and diffed: they are identical except for the launch name.
    Run Launch Tests (P/F/S) To Investigate Items Retries Logs In Progress
    baseline sequential FAILED 19 (14/3/2) 4 44 3 31 0
    migrated sequential FAILED 19 (14/3/2) 4 44 3 31 0
    baseline parallel FAILED 16 (11/3/2) 4 38 3 31 0
    migrated parallel FAILED 16 (11/3/2) 4 38 3 31 0
    • The attachment of "writing evidence" arrived as text/plain; charset=utf-8 in the baseline and in both migrated runs.
    • After the attachment fix (final binary), the parallel run was repeated: identical tree, and the attachment again arrived as text/plain.
    • Abort path, live: PATH=<go bin>:/usr/bin:/bin ginkgo-rp-l6 -r --keep-going, so there is no ginkgo on the PATH. The output shows "ginkgo not found", exit 1. All 3 suites ended STOPPED and the launch STOPPED (not FAILED); nothing is In Progress. This runs AbortItems plus the direct FinishLaunch against the real server.
    • Ctrl-C, live: ginkgo-rp ./slow, with SIGINT to the wrapper after 20 s, run with the baseline and the migrated binary.
      • Both exit 130 with identical trees: "finishes fast" PASSED, "is interrupted" and its By step INTERRUPTED (2 logs), "never runs" SKIPPED, container and suite FAILED, launch FAILED.
    • No WARNING lines appeared in any run.
    • All 8 launches (gorp-wave-l6g-*) were deleted afterwards. A filter.cnt.name=gorp-wave-l6g query returns none.

After the merge of feat/session (3548ead)

  • Root: go build ./... && go vet ./... && go vet -tags e2e ./e2e/ OK; go test -race -count=1 ./... OK; go test -race -count=20 ./pkg/gorp/ ./internal/commands/ OK; golangci-lint v2.15.0 run --build-tags e2e ./...: 0 issues.

  • pkg/ginkgo (temporary workspace): go build ./..., go vet ./..., go vet -tags sanity ./examples/..., GOOS=windows go vet ./... OK; go test -race -count=1 -cover ./...: cmd/ginkgo-rp ok 90.1%, rpagent ok 87.5%; golangci-lint v2.15.0 run ./... (with GOWORK): 0 issues. The --- FAIL: TestFixture lines in -v output come from the fixture subprocesses, not from the suite.

  • The round 4/5 guarantees still hold (all pass): launch never left In Progress (TestWrapperAbortFinishesSuitesThenLaunchAsStopped, TestWrapperRunsTestsWhenReportPortalIsDown); 4xx is not an outage (TestWrapperKeepsFinishingItemsWhenTheyAreRejected); TestWrapperFinalizeFailureKeepsGinkgoExitCode asserts [PASSED STOPPED], also in strict mode; three failures in a row (TestWrapperGivesUpOnItemsAfterThreeFailuresInARow); finalize deadline (TestWrapperGivesUpFinalizingAfterTheDeadline); signal during finalization (TestWrapperSignalDuringFinalizationStopsTheLaunch, TestWrapperSecondSignalDuringFinalizationGivesUpAtOnce).

  • e2e of the root module on the local ReportPortal: 21 passed (62.2 s).

  • Live Ginkgo comparison, repeated on the local ReportPortal 6.0.0 with scratchpad/bin/ginkgo-rp-l6 rebuilt from 3548ead (workspace build, vcs.revision=3548ead) and the baseline binary of 923718e. Tools: scratchpad/l6g-tools/run.sh, rptree.py. The trees are identical item by item, apart from the launch name:

    Run Launch Tests (P/F/S) To Investigate Items Retries Logs In Progress
    baseline sequential FAILED 19 (14/3/2) 4 44 3 31 0
    migrated sequential FAILED 19 (14/3/2) 4 44 3 31 0
    baseline parallel FAILED 16 (11/3/2) 4 38 3 31 0
    migrated parallel FAILED 16 (11/3/2) 4 38 3 31 0
    abort (no ginkgo on PATH), migrated STOPPED – – 3 suites, STOPPED – 0 0
    Ctrl-C on ./slow, baseline / migrated FAILED, exit 130 3 (1/1/1) – 6 – 2 0

    In the Ctrl-C runs, "is interrupted" and its By step are INTERRUPTED in both, "never runs" is SKIPPED, and the trees are identical. No WARNING lines appeared in any run. The 7 gorp-wave-l6g2-* launches were deleted. The e2e suite leaves one …-TestLaunchListAndMerge-merged launch per run (ids 387 and 408). The server answers 500 to the DELETE of a merged launch, and the older leftovers on the server are the same kind.

Round 2 (fff248d)

  • Root (GOWORK=off): go build ./... && go vet ./... && go vet -tags e2e ./e2e/ OK; go test -race -count=1 ./... OK; go test -race -count=20 ./pkg/gorp/ ./internal/commands/ OK; golangci-lint v2.15.0 run --build-tags e2e ./...: 0 issues.

  • pkg/ginkgo (temporary workspace): go build ./..., go vet ./..., GOOS=windows go vet ./..., go vet -tags sanity ./examples/... OK; go test -race -count=1 -cover ./...: cmd/ginkgo-rp ok 90.1%, rpagent ok 88.0%; go test -race -count=3 ./rpagent/ OK; golangci-lint v2.15.0 run ./...: 0 issues.

  • Pre-existing, not fixed (from Add Ginkgo v2 agent and ginkgo-rp wrapper (pkg/ginkgo) #15, 923718e): go test -count=2 -run TestCleanupRemovesExactlyOneSessionsFiles ./cmd/ginkgo-rp/ fails at main_test.go:450 ("the test must create files for both sessions, got 8 and 8"), because the process-wide inMemoryContainerCache survives the first iteration. -count=1 passes.

  • Round 4/5 guarantees: all wrapper tests pass unchanged (TestWrapperAbortFinishesSuitesThenLaunchAsStopped, …RunsTestsWhenReportPortalIsDown, …KeepsFinishingItemsWhenTheyAreRejected, …FinalizeFailureKeepsGinkgoExitCode, …GivesUpOnItemsAfterThreeFailuresInARow, …GivesUpFinalizingAfterTheDeadline, …SignalDuringFinalizationStopsTheLaunch, …SecondSignalDuringFinalizationGivesUpAtOnce).

  • e2e of the root module on the local ReportPortal 6.0.0: 22 passed (58.9 s, at 8055c7e/fff248d).

  • Live Ginkgo comparison on the local ReportPortal 6.0.0, scratchpad/bin/ginkgo-rp-l6 rebuilt from fff248d (vcs.revision=fff248d; the migrated runs were repeated after the last LogBatcher change, with the same result; the baseline runs are from the first pass), baseline ginkgo-rp-base (923718e), fixtures scratchpad/live-l6g / scratchpad/live-base, scratchpad/l6g-tools/run.sh + rptree.py, logs and trees in scratchpad/live-r6/. Trees identical item by item (diff of the dumps without the launch line is empty):

    Run Launch Tests (P/F/S) To Investigate Items Retries Logs In Progress
    baseline sequential FAILED 19 (14/3/2) 4 44 3 31 0
    migrated sequential FAILED 19 (14/3/2) 4 44 3 31 0
    baseline parallel FAILED 16 (11/3/2) 4 38 3 31 0
    migrated parallel FAILED 16 (11/3/2) 4 38 3 31 0
    abort (no ginkgo on PATH), migrated STOPPED – – 3 suites, STOPPED – 0 0

    No WARNING line in any run. The 8 gorp-wave-l6g3-*/gorp-wave-l6g4-* launches were deleted. The e2e runs left …-TestLaunchListAndMerge-merged launches (438, 463, 485, 512, 537): the server answers 500 TransientObjectException to the DELETE of a merged launch, like the older leftovers.

Investigation log

  1. Baseline. At 0f6fafa (workspace), go test -race -count=1 -cover ./... in pkg/ginkgo gave ok with 89.2% and 88.4%. The live baseline above matches the task's numbers (19 / TI 4 and 16 / TI 4).

  2. Where the agent reported. The requests were in:

    • rpagent/test_listener.go (923718e): retry around every call, including SaveLogs in FlushLogs and SaveLogMultipart. A retried batch is a new POST, and the server has no key for logs, so this is the "log replay ×3".
    • cmd/ginkgo-rp/main.go: failureStreak, abortLaunch and stopLaunch.
    • FinalizeLaunch, which built its own client from the state and config files.
  3. Abort alone could not keep the wrapper's guarantees. Launch.Abort (pkg/gorp/session.go, before 7377b08) stops at the first transient item failure, before the launch finish, and uses one ctx. In the wrapper's session the suites are in the open set. Traced against cmd/ginkgo-rp/e2e_test.go:

    • TestWrapperGivesUpOnItemsAfterThreeFailuresInARow (:448): the breaker opens on level3/2/1. Abort then gets a 500 on "Fixture Suite" and returns, but the test wants launch [STOPPED].
    • TestWrapperGivesUpFinalizingAfterTheDeadline (:931) and …SignalDuringFinalizationStopsTheLaunch (:953): the hanging suite finish uses up Abort's whole ctx, so stopAttempts() stays 0. The old stopLaunch kept 1/3 of the time for the launch.
    • TestWrapperFinalizeFailureKeepsGinkgoExitCode (:419) wants exactly [PASSED STOPPED]. An extra direct FinishLaunch after every failed Abort would make 3 attempts.

    Both Abort outcomes match ErrLaunchNotFinished, so the wrapper can't tell them apart. Changing Abort would break L6's "Abort against a dead server sends one request" (session_test.go:320). Decision: add AbortItems, and have the wrapper send the launch finish itself in the reserved third (rpLaunch.abort, main.go:481). All four tests pass unchanged.

  4. Flush per spec. Ginkgo v2.26.0 reporting_dsl.go:165 says: "When running in parallel, Ginkgo ensures that only one of the parallel nodes runs the ReportAfterSuite". The agent's own comment at rpagent/attachment.go:49 says the same. So a Session.Close only in ReportAfterSuite (design §7.2) would drain process 1 only, and the other processes would exit with their queue unsent. Decision: a bounded Flush at the end of ReportAfterEach (reporting_node.go:208). This answers design open question 6. The parallel live run (3 procs) shows the same 38 items and 31 logs as the baseline.

  5. Shared containers. The winner must not publish a UUID whose start isn't answered, because the losers would report children under it at once. So StartAndWait is used in GetOrCreate's createFunc (ginkgo_helpers.go:67), bounded by httpTimeout. Losers still wait up to RP_LOCK_RETRY_COUNT × SLEEP (10 s) as before.

  6. The wrapper client stays without WithRetry. The old wrapper sent single attempts, and the attempt-count assertions (finalizeAttempts, launchFinishAttempts) depend on that. Only the worker clients get workerRetry (reporting_node.go:273), which matches the old worker retry(3, 200ms) for starts and finishes.

  7. boundedID → gorp.BoundedID. Same separator (~), same 16 hex digits of SHA-256, same 1024 limit (pkg/gorp/limits.go BoundedID, removed rpagent/limits.go). For ASCII the cut is identical: TestOverLongIdentityKeepsUniqueIDOfTheFullID (identity_test.go) asserts exactly 1024 characters ending in ~c7fca14d35e62afd, and it passes unchanged.

  8. Attachments.

    • FileMultipart.Load names the part after the temp file (rp-attachment-*.txt), but the e2e test wants evidence.txt. So it is a ReaderMultipart with the original name.
    • The batcher reads it once when it sends the request, so the file must stay open past the hook. A stagedFile (test_listener.go) opens it at the first Read and closes and removes it at EOF, so a dropped log never holds a file descriptor (found in review: the first version opened the file up front and leaked it when the log was dropped).
    • Its size is unknown to logSize (pkg/gorp/log_batcher.go), so only the 10-entry limit bounds a request (Behaviour change).
  9. Fakes. The session ignores the id of an item start and uses the client UUID (L6 Investigation log 5). The fakes that answered with their own IDs were changed to echo uuid, or to map it through aliases. Assertions were changed only where they compared against the fake's IDs.

  10. Errors in the wrapper. Launch.Finish can return a non-nil rs and an error together: the session reports item errors such as 4xx on containers and still finishes the launch. FinalizeLaunch treats that as success, because the handler already printed each error. Only ErrLaunchNotFinished leads to abort and to exit 2 in strict mode (TestWrapperKeepsFinishingItemsWhenTheyAreRejected, e2e_test.go:1197).

  11. Merge with the L6 review fixes. Launch.Finish after or during Abort/AbortItems now returns ErrSessionClosed instead of ErrLaunchNotFinished (pkg/gorp/session.go, Finish, case aborted). FinalizeLaunch tested only for ErrLaunchNotFinished, so this would have printed SUCCESS for a launch it did not finish. It was fixed to go by rs == nil, and the new test case proves the old code wrong. The wrapper never calls Finish after its own abort, but the check no longer depends on that order.

  12. B3. Reviewer's TestReview_StartAndWaitTimeoutOrphansTheContainer, ported as TestHierarchyReusesAContainerStartThatOutlivedItsWait through ProcessSpecWithHierarchyAndReturnIDs (the reviewer called GetOrCreate directly). On 0cf6414 + the injectable wait: "Describe X started 2 times". Both waits end before the 300 ms answer, so the test asserts one stored start and both specs under it, not that the second call returns the UUID from the cache. Who finishes the container: the wrapper (AggregateContainers, containers.go), from the ContainerIDs of the spec statuses; so the pending UUID must reach the spec status, which PendingShared does. The pending state lives on the TestListener, not in the package-level inMemoryContainerCache (the cause of the -count≥2 failure above).

  13. Retry budget. gorp.WithRetry configures Resty's retry (pkg/gorp/retry.go configureResty), which calls http.Client.Do per attempt, so Timeout is per attempt. Pauses: MinWait doubling up to MaxWait, a Retry-After up to MaxWait. Hence attempts × timeout + retries × MaxWait. While writing the flush test the client turned out to ignore httpTimeout: oauth2.NewClient copies the base client's Timeout, and getClient (pkg/gorp/client.go) gives 30 s, so c.Timeout == 0 was never true. The first version of the test passed for the wrong reason (the hung handler returned an empty 200 after 1 s); with the timeout set it fails on the old bound and passes on the new one.

  14. Final Flush. flushReports (reporting_node.go) serves every ReportAfterEach (Flush) and ReportAfterSuite (Close); only process 1 runs ReportAfterSuite in a parallel run (Investigation 4). So the last ReportAfterEach of processes 2…n is their final send. A 30 s bound equal to one attempt let one hung attempt use it up.

  15. Wrapper and B2. The wrapper client is built without WithRetry (main.go:726), unlike the workers (reporting_node.go:104-110). Reviewer's TestReview_AbortStopsAtFirstSuiteFailure logged [item:suite-c:503 launch:STOPPED]; ported with assertions as TestAbortTriesEverySuiteAfterATransientFailure, it fails with 3548ead's pkg/gorp (checked by git checkout 3548ead -- pkg/gorp, then restored) and passes after the merge.

Not verified

  • Standalone builds and task ginkgo:test/ginkgo:lint, which use Docker and no workspace. They need a goRP release with Session.
  • The breaker, and the wrapper's abort after a failed finalization, against a live server. A 5xx or a hang can't be provoked on the real server, so they are covered by fakeRP (real ginkgo processes) and the session's unit tests. The abort before the run (no ginkgo) was checked live.
  • That a parallel run without the per-spec Flush would actually lose reports. This rests on the Ginkgo documentation; the change was not reverted to check.
  • Log duplication of the old agent on the live server. It needs a batch that is stored but not answered; TestWorkerNeverSendsALogTwice covers the new behaviour.
  • Windows. Only GOOS=windows go vet ./... was run.
  • A container start that outlives its 110 s wait against a live server (needs a server that stalls this long); unit-tested only. The cross-process duplicate it can still cause while pending (see Round 2) is not tested.
  • stagedFile opens the attachment at its first Read, which is after Multipart.Load; if it fails then, the whole log batch still fails (the batcher separates only Load errors).
  • go mod tidy -diff in pkg/ginkgo: it can't resolve without a goRP release that has Session. No dependency was added; rpagent no longer imports github.com/google/uuid, but the wrapper still does.

Open questions

  1. Merge order. Design: a reporting session for Go agents (ordering, Flush(ctx), breaker) #52 wants L6 merged together with its second consumer. But pkg/ginkgo can't build standalone, and its CI steps stay red, until a goRP release contains L6. Options:
    • (a) merge L6, release, then merge this PR with the require bumped;
    • (b) merge both, accepting red pkg/ginkgo CI steps until the release.
  2. Flush at the end of every spec instead of only Close in ReportAfterSuite (design §7.2 and its open question 6). It is required for parallel runs, but it puts a wait back into ReportAfterEach: one per spec, not one per request.
  3. Batching. The session defaults are 10 logs per request (before: 200 logs or 2 MB per spec), and the request is now waited for inside the hook. Should the agent pass WithLogBatching(MaxEntries: …)? A larger batch makes the unknown size of attachments matter.
  4. The "[attachment … could not be uploaded]" fallback log is gone: the failure is only a warning in the worker's output. Bringing it back would need a per-log error callback from the session.
  5. AbortItems as a public API (now in the L6 PR), versus an option on Abort or a typed error that tells the owner Abort stopped before the launch finish.

🤖 Generated with Claude Code

That-geeky-shree and others added 18 commits November 24, 2026 23:01
Address review feedback on #15:

- Stable testCaseId, codeRef and uniqueId so History and retries work
- Real timestamps for By() steps, logs and attachments
- Per-step status instead of the spec's final status
- Send GinkgoWriter and stdout output to ReportPortal
- Finish Describe/Context containers explicitly with the right status
- Report BeforeSuite/AfterSuite failures as their own items
- Env-var configuration, launch attributes, description and mode, and Ginkgo labels as item attributes
- Fix temp-file leaks and per-worker cleanup
- Suite discovery follows Ginkgo (any *_test.go calling RunSpecs, paths outside cwd), and a worker whose package was not registered logs an ERROR
- Never kill the test process from library code
- Skip only the agent's own rpagent package instead of any path containing the word
- Mark suites that received no specs as skipped, not failed
- Tests for container cache locking (including across processes) and hierarchy building
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The Ginkgo wrapper stops a launch it cannot finish in two steps, each
with its own share of the time: the open items, then the launch. With
Abort alone a suite finish that hangs or gets a 5xx used up the budget
or ended the abort, and the launch stayed In Progress. AbortItems is the
first step of Abort; the owner sends the launch finish itself.

Abort behaves as before.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The agent and the wrapper had their own reporting machinery: synchronous
requests with a retry loop (which replayed log batches, so a batch that
was stored but not answered was stored up to three times), a pending-log
batch per spec, a failure streak in the wrapper and a hand-written stop.
They now report through gorp.Session.

Workers attach to the wrapper's launch (AttachLaunch) and start specs,
By() steps and fixture items through the session; suites and containers
started elsewhere are handles (Launch.Item). The lock-file winner waits
for its container start (Item.Wait) before publishing the UUID. Every
ReportAfterEach ends with a bounded Flush, because in a parallel run only
process 1 gets to ReportAfterSuite, which closes the session.

The wrapper starts the launch and the suites with its own session, queues
the container and suite finishes and finishes the launch with
Launch.Finish. When the launch is not finished (deadline, signal, the
breaker after three transient failures in a row, a failed launch finish)
it stops it as before: suites with AbortItems in two thirds of
stopLaunchTimeout, then the launch in the last third.

Starts and finishes of workers are retried by the client (WithRetry,
3 attempts, 200 ms); logs are never sent twice. Names and uniqueIds are
shortened by the session; testCaseId uses gorp.BoundedID, which gives the
same result as the removed boundedID for ASCII IDs.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Brings the session review fixes (bounded log wait in Abort, Finish and
Abort serialized, ErrSessionClosed after Abort, trip accounting) and the
AbortItems of feat/session. pkg/gorp, README.md, AGENTS.md and SKILL.md
now equal feat/session: the conflicts in pkg/gorp/session.go,
session_test.go and AGENTS.md were resolved in favour of feat/session,
whose AbortItems replaces the one of 7377b08.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
After the merge of feat/session, Launch.Finish after (or during) an
abort sends nothing and returns ErrSessionClosed, not
ErrLaunchNotFinished. FinalizeLaunch took any error that did not match
ErrLaunchNotFinished for a finished launch and printed SUCCESS; it now
goes by the answer of Finish: no answer means this call did not finish
the launch, and the error matches ErrLaunchNotFinished (with
ErrSessionClosed after an abort), so the wrapper stops the launch.

The wrapper's abort already treats the AbortItems error as a warning and
always sends the STOPPED launch finish itself, with the client and its
own third of stopLaunchTimeout; its comment now says why (AbortItems
says nothing about the launch, may report logs not sent after its 2 s).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Brings the round-2 session fixes: Abort/AbortItems try every open item and give up after the breaker threshold of failures in a row, ctx bounds the waits between Finish and Abort, Flush fails when what it waited for was dropped, an unreadable attachment loses only its log, same-named attachments go in separate requests.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…y the retry budget

- A container start is waited for as long as one request with its
  retries takes (requestBudget: 3 attempts x the HTTP timeout + 2 pauses
  of at most 10 s, 110 s), not one HTTP timeout. When the wait still
  ends first, TestListener.StartShared keeps the item as pending under
  its cache key: this process reports under it (its session sends the
  children after it, the spec results bring it to the wrapper, which
  finishes it), and the next spec waits for it again instead of starting
  a second "Describe X" that nobody finished. The UUID is published to
  other workers only once the start was answered.
- flushReports is bounded by the same budget: the last Flush of a worker
  that is not the first gave up after one hung attempt, and the process
  exited with the retries unsent.
- NewReportingClient sets httpTimeout on the client; the client of
  WithApiKeyAuth always had gorp's 30 s, so the setting never applied.
- The wrapper's abort: AbortItems now tries every suite after a
  transient failure (gorp round-2 semantics); doc and a test.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.

3 participants