TestExecState_CounterAggregation verifies that totals (Attempts / Retries / Hedges) are correctly derived as the sum of per-scope counters — so increments at the network OR upstream OR cache scope all contribute to the totals.
(t *testing.T)
| 69 | // counters — so increments at the network OR upstream OR cache scope |
| 70 | // all contribute to the totals. |
| 71 | func TestExecState_CounterAggregation(t *testing.T) { |
| 72 | t.Parallel() |
| 73 | |
| 74 | t.Run("totals sum across scopes", func(t *testing.T) { |
| 75 | t.Parallel() |
| 76 | req := common.NewNormalizedRequest([]byte(`{"jsonrpc":"2.0","method":"eth_blockNumber","id":1}`)) |
| 77 | st := req.ExecState() |
| 78 | require.NotNil(t, st) |
| 79 | |
| 80 | st.UpstreamAttempts.Store(3) |
| 81 | st.UpstreamRetries.Store(1) |
| 82 | st.UpstreamHedges.Store(1) |
| 83 | st.NetworkAttempts.Store(2) |
| 84 | st.NetworkRetries.Store(1) |
| 85 | st.NetworkHedges.Store(0) |
| 86 | st.CacheAttempts.Store(1) |
| 87 | st.CacheRetries.Store(0) |
| 88 | st.CacheHedges.Store(0) |
| 89 | |
| 90 | snap := st.Snapshot() |
| 91 | // Attempts = physical work only (Upstream + Cache). NetworkAttempts |
| 92 | // is a rotation count and is NOT summed in to avoid double-counting |
| 93 | // (each rotation triggers exactly one upstream invocation chain). |
| 94 | assert.Equal(t, 4, snap.Attempts, "Attempts = UpstreamAttempts (3) + CacheAttempts (1)") |
| 95 | // Retries / Hedges sum across scopes — each is a distinct event. |
| 96 | assert.Equal(t, 2, snap.Retries, "Retries = 1 (upstream) + 1 (network) + 0 (cache)") |
| 97 | assert.Equal(t, 1, snap.Hedges, "Hedges = 1 (upstream) + 0 (network) + 0 (cache)") |
| 98 | assert.Equal(t, 3, snap.UpstreamAttempts) |
| 99 | assert.Equal(t, 2, snap.NetworkAttempts) |
| 100 | assert.Equal(t, 1, snap.CacheAttempts) |
| 101 | }) |
| 102 | |
| 103 | t.Run("zero state snapshots to all-zeros", func(t *testing.T) { |
| 104 | t.Parallel() |
| 105 | req := common.NewNormalizedRequest([]byte(`{"jsonrpc":"2.0","method":"eth_blockNumber","id":1}`)) |
| 106 | st := req.ExecState() |
| 107 | snap := st.Snapshot() |
| 108 | assert.Equal(t, 0, snap.Attempts) |
| 109 | assert.Equal(t, 0, snap.Retries) |
| 110 | assert.Equal(t, 0, snap.Hedges) |
| 111 | }) |
| 112 | |
| 113 | t.Run("nil ExecState snapshots safely", func(t *testing.T) { |
| 114 | t.Parallel() |
| 115 | var st *common.ExecState |
| 116 | snap := st.Snapshot() |
| 117 | assert.Equal(t, 0, snap.Attempts) |
| 118 | assert.Equal(t, 0, snap.Retries) |
| 119 | assert.Equal(t, 0, snap.Hedges) |
| 120 | }) |
| 121 | |
| 122 | t.Run("MarkUpstreamAttemptWon marks the most-recent matching attempt", func(t *testing.T) { |
| 123 | t.Parallel() |
| 124 | req := common.NewNormalizedRequest([]byte(`{"jsonrpc":"2.0","method":"eth_blockNumber","id":1}`)) |
| 125 | st := req.ExecState() |
| 126 | require.NotNil(t, st) |
| 127 | |
| 128 | st.RecordUpstreamAttempt(common.UpstreamAttempt{UpstreamId: "rpc1", Outcome: common.UpstreamOutcomeTimeout}) |
nothing calls this directly
no test coverage detected