Skip to content

Commit 41586b4

Browse files
capabilities: fix executable timeout retention regression (#21702)
capabilities: fix executable request timeout retention tests
1 parent f8abcbb commit 41586b4

3 files changed

Lines changed: 17 additions & 9 deletions

File tree

core/capabilities/remote/executable/request/server_request_test.go

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -359,20 +359,18 @@ func Test_ServerRequest_Evictable(t *testing.T) {
359359

360360
t.Run("expired but below minimum retention", func(t *testing.T) {
361361
req := newRequest(20 * time.Millisecond)
362-
time.Sleep(60 * time.Millisecond)
362+
require.Eventually(t, func() bool { return req.Expired() }, time.Second, 10*time.Millisecond)
363363
assert.False(t, req.Evictable(200*time.Millisecond))
364364
})
365365

366366
t.Run("expired and retained past minimum retention", func(t *testing.T) {
367367
req := newRequest(20 * time.Millisecond)
368-
time.Sleep(60 * time.Millisecond)
369-
assert.True(t, req.Evictable(10*time.Millisecond))
368+
require.Eventually(t, func() bool { return req.Evictable(10 * time.Millisecond) }, time.Second, 10*time.Millisecond)
370369
})
371370

372371
t.Run("minimum retention elapsed but request timeout still active", func(t *testing.T) {
373372
req := newRequest(200 * time.Millisecond)
374-
time.Sleep(60 * time.Millisecond)
375-
assert.False(t, req.Evictable(10*time.Millisecond))
373+
require.Never(t, func() bool { return req.Evictable(10 * time.Millisecond) }, 100*time.Millisecond, 10*time.Millisecond)
376374
})
377375
}
378376

core/capabilities/remote/executable/server.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,13 +222,15 @@ func (r *server) expireRequests() {
222222
defer r.receiveLock.Unlock()
223223

224224
for requestID, executeReq := range r.requestIDToRequest {
225-
if executeReq.request.Evictable(commoncap.DefaultExecutableRequestTimeout) {
225+
if executeReq.request.Expired() {
226226
ctx, cancelFn := r.stopCh.NewCtx()
227227
err := executeReq.request.Cancel(ctx, types.Error_TIMEOUT, "request expired by executable server")
228228
cancelFn()
229229
if err != nil {
230230
r.lggr.Errorw("failed to cancel request", "request", executeReq, "err", err)
231231
}
232+
}
233+
if executeReq.request.Evictable(commoncap.DefaultExecutableRequestTimeout) {
232234
delete(r.requestIDToRequest, requestID)
233235
delete(r.messageIDToRequestIDsCount, executeReq.messageID)
234236
}

core/capabilities/remote/executable/server_test.go

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1060,17 +1060,17 @@ func Test_Server_DuplicateRequestRemainsDedupedPastRequestTimeout(t *testing.T)
10601060
}
10611061

10621062
server.Receive(ctx, msg)
1063-
require.Eventually(t, func() bool { return len(dispatcher.sent) == 1 }, time.Second, 10*time.Millisecond)
1063+
require.Eventually(t, func() bool { return dispatcher.Len() == 1 }, time.Second, 10*time.Millisecond)
10641064

10651065
time.Sleep(2 * cfg.RequestTimeout)
10661066
server.Receive(ctx, msg)
10671067

1068-
time.Sleep(100 * time.Millisecond)
1069-
require.Len(t, dispatcher.sent, 1)
1068+
require.Never(t, func() bool { return dispatcher.Len() > 1 }, 100*time.Millisecond, 10*time.Millisecond)
10701069
}
10711070

10721071
type noopDispatcher struct {
10731072
services.StateMachine
1073+
mu sync.Mutex
10741074
sent []*remotetypes.MessageBody
10751075
}
10761076

@@ -1095,6 +1095,14 @@ func (n *noopDispatcher) SetReceiverForMethod(string, uint32, string, remotetype
10951095
func (n *noopDispatcher) RemoveReceiverForMethod(string, uint32, string) {}
10961096

10971097
func (n *noopDispatcher) Send(peerID p2ptypes.PeerID, msgBody *remotetypes.MessageBody) error {
1098+
n.mu.Lock()
1099+
defer n.mu.Unlock()
10981100
n.sent = append(n.sent, msgBody)
10991101
return nil
11001102
}
1103+
1104+
func (n *noopDispatcher) Len() int {
1105+
n.mu.Lock()
1106+
defer n.mu.Unlock()
1107+
return len(n.sent)
1108+
}

0 commit comments

Comments
 (0)