MCPcopy Create free account
hub / github.com/0xUnixIO/pulse / TestUsagePusher_AckTimeoutKeepsPending

Function TestUsagePusher_AckTimeoutKeepsPending

internal/nodeagent/usage_test.go:162–200  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

160}
161
162func TestUsagePusher_AckTimeoutKeepsPending(t *testing.T) {
163 t.Parallel()
164 api := &mockUsageAPI{}
165 sender := newMockSender()
166 p := NewUsagePusher(api, time.Hour)
167 p.SetAckTimeout(20 * time.Millisecond)
168 p.SetSender(sender)
169
170 ctx := context.Background()
171 p.tick(ctx) // prime
172 p.tick(ctx) // push seq=1
173
174 // 等 ack timeout 触发但 pending 应保留。
175 time.Sleep(80 * time.Millisecond)
176 if p.PendingCount() != 1 {
177 t.Fatalf("pending should still be 1 after ack timeout, got %d", p.PendingCount())
178 }
179
180 // 下一轮 tick 应同时重发 seq=1 和发新的 seq=2。
181 p.tick(ctx)
182 pushed := sender.pushedSeqs()
183 // 至少包含 seq=1 两次(首发 + 重发)和新 seq=2。
184 count1 := 0
185 hasNew := false
186 for _, s := range pushed {
187 if s == 1 {
188 count1++
189 }
190 if s == 2 {
191 hasNew = true
192 }
193 }
194 if count1 < 2 {
195 t.Fatalf("seq=1 should have been re-pushed, total occurrences=%d, all=%v", count1, pushed)
196 }
197 if !hasNew {
198 t.Fatalf("expected new seq=2 in pushes %v", pushed)
199 }
200}
201
202func TestUsagePusher_NoSenderSkips(t *testing.T) {
203 t.Parallel()

Callers

nothing calls this directly

Calls 7

SetAckTimeoutMethod · 0.95
SetSenderMethod · 0.95
tickMethod · 0.95
PendingCountMethod · 0.95
newMockSenderFunction · 0.85
NewUsagePusherFunction · 0.85
pushedSeqsMethod · 0.80

Tested by

no test coverage detected