diff --git a/internal/utils/timeout.go b/internal/utils/timeout.go index 423bc41..e15036c 100644 --- a/internal/utils/timeout.go +++ b/internal/utils/timeout.go @@ -45,7 +45,7 @@ func WithInactivityTimeout(parent context.Context, d time.Duration) (context.Con timer.Reset(d) case <-timer.C: - cancel(fmt.Errorf("no activity for %v", d)) + cancel(fmt.Errorf("no activity for %v: %w", d, context.DeadlineExceeded)) return } } diff --git a/internal/utils/timeout_test.go b/internal/utils/timeout_test.go new file mode 100644 index 0000000..e49d80a --- /dev/null +++ b/internal/utils/timeout_test.go @@ -0,0 +1,33 @@ +// Copyright 2026 The A2A Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package utils + +import ( + "context" + "errors" + "testing" + "time" +) + +func TestWithInactivityTimeoutCauseIsDeadlineExceeded(t *testing.T) { + t.Parallel() + + ctx, _ := WithInactivityTimeout(t.Context(), 10*time.Millisecond) + <-ctx.Done() + + if err := UnpackCause(ctx, ctx.Err()); !errors.Is(err, context.DeadlineExceeded) { + t.Errorf("UnpackCause() = %v, want an error wrapping context.DeadlineExceeded", err) + } +}