Skip to content

Commit feec19c

Browse files
rasifrclaude
authored andcommitted
tests: address review comments in recovery integration test
- Use UnixNano-suffixed cluster name to avoid file collisions in parallel runs - Re-enable n2's Spock subscription in t.Cleanup to prevent cross-test state leakage - Hard-fail on missing _spock_metadata_ instead of silently skipping Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent d9e77a3 commit feec19c

1 file changed

Lines changed: 12 additions & 8 deletions

File tree

tests/integration/recovery_single_node_test.go

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ import (
5757
// the failed origin node). The file is removed in t.Cleanup.
5858
func writeN2N3ClusterJSON(t *testing.T) string {
5959
t.Helper()
60-
clusterName := "test_cluster_n2_n3"
60+
clusterName := fmt.Sprintf("test_cluster_n2_n3_%d", time.Now().UnixNano())
6161
cfg := types.ClusterConfig{
6262
JSONVersion: "1.0",
6363
ClusterName: clusterName,
@@ -112,7 +112,7 @@ func writeN2N3ClusterJSON(t *testing.T) string {
112112
require.NoError(t, err)
113113
path := clusterName + ".json"
114114
require.NoError(t, os.WriteFile(path, data, 0644))
115-
t.Cleanup(func() { os.Remove(path) })
115+
t.Cleanup(func() { _ = os.Remove(path) })
116116
return clusterName
117117
}
118118

@@ -222,6 +222,10 @@ func TestCatastrophicSingleNodeFailure(t *testing.T) {
222222
fmt.Sprintf("SELECT spock.sub_disable('%s', true)", subName),
223223
)
224224
require.NoError(t, err, "disable n2 subscription to n1 (%s)", subName)
225+
t.Cleanup(func() {
226+
_, _ = pgCluster.Node2Pool.Exec(ctx,
227+
fmt.Sprintf("SELECT spock.sub_enable('%s')", subName))
228+
})
225229
log.Printf("Disabled n2 subscription %q to n1 – real lag begins", subName)
226230

227231
// -----------------------------------------------------------------------
@@ -382,12 +386,12 @@ func TestCatastrophicSingleNodeFailure(t *testing.T) {
382386

383387
// Verify _spock_metadata_ is populated in the diff rows.
384388
for _, row := range n3Rows {
385-
if metaRaw, ok := row.Get("_spock_metadata_"); ok {
386-
if meta, ok := metaRaw.(map[string]any); ok {
387-
require.Contains(t, meta, "node_origin", "_spock_metadata_ must include node_origin")
388-
require.Contains(t, meta, "commit_ts", "_spock_metadata_ must include commit_ts")
389-
}
390-
}
389+
metaRaw, ok := row.Get("_spock_metadata_")
390+
require.True(t, ok, "_spock_metadata_ must be present in every diff row")
391+
meta, ok := metaRaw.(map[string]any)
392+
require.True(t, ok, "_spock_metadata_ must be a map, got %T", metaRaw)
393+
require.Contains(t, meta, "node_origin", "_spock_metadata_ must include node_origin")
394+
require.Contains(t, meta, "commit_ts", "_spock_metadata_ must include commit_ts")
391395
}
392396
log.Printf("Phase 3 complete: diff found %d diffs on n3 vs n2 for origin n1", len(n3Rows))
393397

0 commit comments

Comments
 (0)