mirror of
https://github.com/sipeed/picoclaw.git
synced 2026-06-12 18:08:54 +00:00
fix(whatsapp_native,agent): address second round of review feedback
- WhatsApp Send(): detect unpaired state (Store.ID == nil) and return ErrTemporary instead of attempting to send while QR login is pending - handleReasoning: check the returned error type (DeadlineExceeded / Canceled) instead of ctx.Err() to decide log level, so pubCtx timeouts on a full bus are correctly classified as expected - Test: fill bus with a short-timeout loop instead of hardcoding the buffer size (64), making the test resilient to buffer size changes
This commit is contained in:
@@ -801,16 +801,20 @@ func TestHandleReasoning(t *testing.T) {
|
||||
t.Run("returns promptly when bus is full", func(t *testing.T) {
|
||||
al, msgBus := newLoop(t)
|
||||
|
||||
// Fill the outbound bus buffer (default size is 64) so that the
|
||||
// next PublishOutbound will block until the context deadline.
|
||||
for i := 0; i < 64; i++ {
|
||||
err := msgBus.PublishOutbound(context.Background(), bus.OutboundMessage{
|
||||
// Fill the outbound bus buffer until a publish would block.
|
||||
// Use a short timeout to detect when the buffer is full,
|
||||
// rather than hardcoding the buffer size.
|
||||
for i := 0; ; i++ {
|
||||
fillCtx, fillCancel := context.WithTimeout(context.Background(), 50*time.Millisecond)
|
||||
err := msgBus.PublishOutbound(fillCtx, bus.OutboundMessage{
|
||||
Channel: "filler",
|
||||
ChatID: "filler",
|
||||
Content: fmt.Sprintf("filler-%d", i),
|
||||
})
|
||||
fillCancel()
|
||||
if err != nil {
|
||||
t.Fatalf("failed to fill bus: %v", err)
|
||||
// Buffer is full (timed out trying to send).
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user