Skip to content

test(valkey): fix build_replicaof_config spec assertions and verify_pod_role mocking#2616

Merged
weicao merged 1 commit into
feat/valkey-addonfrom
alice/valkey-start-spec-fix
Apr 29, 2026
Merged

test(valkey): fix build_replicaof_config spec assertions and verify_pod_role mocking#2616
weicao merged 1 commit into
feat/valkey-addonfrom
alice/valkey-start-spec-fix

Conversation

@weicao
Copy link
Copy Markdown
Contributor

@weicao weicao commented Apr 29, 2026

Summary

Fix the 3 build_replicaof_config test failures on the Valkey staging PR (#2592) which has been showing shellspec-test FAILURE for a while:

  • valkey_start_spec.sh:212writes no replicaof directive (this pod is primary)
  • valkey_start_spec.sh:240writes replicaof directive pointing to primary
  • valkey_start_spec.sh:272uses Sentinel-reported master as replicaof target

These are tests-only fixes; no product code changes.

Root causes

Two independent drifts between valkey-start.sh and the tests:

Drift A — info-log channel

build_replicaof_config logs decisions via echo ... >&2 (info-level on stderr), but the tests assert via The stdout should include. The tests were written against an earlier revision that emitted to stdout. The expected-text fragments are still correct — only the stream is wrong.

Fix: switch the 3 assertions from stdout to stderr.

Drift B — verify_pod_role wrapping timeout

Test 3 mocked valkey-cli to return Sentinel's response and relied on the same mock to satisfy verify_pod_role. The production code now wraps the role probe in:

role=$(timeout 3 ${cli_base} -h "${fqdn}" info replication 2>/dev/null | ...)

timeout shell-execs the binary path, bypassing test-scope shell functions, so the mock never serves the role probe. The script logs INFO: quorum elected ... but role='<unreachable>' — retrying in 5s. 12 times then falls through to pod scan / lexicographic bootstrap, which is why the test was looking for an obsolete "Sentinel reports current master" fragment that no longer exists in the success path.

Fix:

  • Mock verify_pod_role directly (the wrapping helper) — robust to the timeout shell-exec barrier
  • Dispatch the valkey-cli mock by argv: SENTINEL get-master-addr-by-name returns master FQDN + port, other paths no-op
  • Update the expected stderr fragment to "sentinel quorum + role verified" (what the script emits today on the success path)

Validation

  • shellspec --load-path shellspec addons/valkey/scripts-ut-spec/valkey_start_spec.sh13 examples, 0 failures
  • shellspec --load-path shellspec addons/valkey/scripts-ut-spec/ (full valkey suite) → 93 examples, 0 failures

CI on this PR (and the rebased PR #2592) should drop from 743 examples, 3 failures to 743 examples, 0 failures.

Why this is tests-only

addons/valkey/scripts/valkey-start.sh is unchanged. Only addons/valkey/scripts-ut-spec/valkey_start_spec.sh is touched, and only the 3 broken It blocks are touched. Other 10 examples in the file are untouched and still pass.

…od_role mocking

Three valkey_start_spec.sh tests for build_replicaof_config have been failing on
PR #2592 / #2615 since the script evolved its info-logging convention:

  1. line 212  this pod is the primary (lexicographic heuristic)
  2. line 240  this pod is a replica
  3. line 272  Sentinel reports the current master

Two underlying drifts:

(a) build_replicaof_config logs decisions to stderr (`echo ... >&2`), but the
    tests asserted on stdout. The tests were written against an earlier
    revision that used stdout. Switch the assertions to stderr — the existing
    expected-text fragments match what the script writes; only the stream is
    different.

(b) Test 3 mocked valkey-cli to return the sentinel response and relied on the
    same mock to satisfy verify_pod_role. The current production code wraps
    the role probe in `timeout 3 valkey-cli ... info replication`, and
    `timeout` shell-execs the binary path — it bypasses test-scope shell
    functions entirely, so the mock never serves the role probe. The fix
    mocks verify_pod_role directly (the wrapping helper) and dispatches the
    valkey-cli mock by argv (SENTINEL get-master-addr-by-name vs other).
    Also updates the expected stderr fragment from the obsolete "Sentinel
    reports current master" string to "sentinel quorum + role verified",
    which is what the script emits today on the success path.

No production code changes; tests-only fix.

Validation:
- `shellspec --load-path shellspec addons/valkey/scripts-ut-spec/valkey_start_spec.sh` — 13/0
- `shellspec --load-path shellspec addons/valkey/scripts-ut-spec/` (full valkey suite) — 93/0
@weicao weicao requested review from a team as code owners April 29, 2026 07:37
@codecov-commenter
Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 0% with 8 lines in your changes missing coverage. Please review.
⚠️ Please upload report for BASE (feat/valkey-addon@d5c730f). Learn more about missing BASE report.

Files with missing lines Patch % Lines
addons/valkey/scripts-ut-spec/valkey_start_spec.sh 0.00% 8 Missing ⚠️
Additional details and impacted files
@@                 Coverage Diff                 @@
##             feat/valkey-addon   #2616   +/-   ##
===================================================
  Coverage                     ?   0.00%           
===================================================
  Files                        ?      79           
  Lines                        ?   10623           
  Branches                     ?       0           
===================================================
  Hits                         ?       0           
  Misses                       ?   10623           
  Partials                     ?       0           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@weicao weicao merged commit 38634a5 into feat/valkey-addon Apr 29, 2026
7 checks passed
@weicao weicao deleted the alice/valkey-start-spec-fix branch April 29, 2026 08:16
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.

2 participants