Skip to content

Commit d4ae169

Browse files
committed
[test]: core schemas cover nil context deadline
1 parent be2eb23 commit d4ae169

2 files changed

Lines changed: 8 additions & 0 deletions

File tree

core/schemas/context.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,9 @@ func (bc *BifrostContext) cancel(err error) {
204204
// For scoped contexts, delegates to the root context.
205205
// If both this context and the parent have deadlines, the earlier one is returned.
206206
func (bc *BifrostContext) Deadline() (time.Time, bool) {
207+
if bc == nil {
208+
return time.Time{}, false
209+
}
207210
if bc.valueDelegate != nil {
208211
return bc.valueDelegate.Deadline()
209212
}

core/schemas/context_test.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,11 @@ func TestNewBifrostContext_NilParent(t *testing.T) {
209209
}
210210

211211
func TestBifrostContext_DeadlineWithClearedParent(t *testing.T) {
212+
var nilCtx *BifrostContext
213+
if _, ok := nilCtx.Deadline(); ok {
214+
t.Fatal("nil BifrostContext should not report a deadline")
215+
}
216+
212217
deadline, ok := (&BifrostContext{}).Deadline()
213218
if ok {
214219
t.Errorf("Context with cleared parent should not have deadline, got %v", deadline)

0 commit comments

Comments
 (0)