Skip to content

Commit 87f5b85

Browse files
committed
Fix failing tests
1 parent 98a9e7c commit 87f5b85

File tree

3 files changed

+21
-13
lines changed

3 files changed

+21
-13
lines changed

exporter/exporterhelper/internal/batch_sender_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -485,7 +485,7 @@ func TestBatchSender_BatchCancelled(t *testing.T) {
485485
require.NoError(t, be.Shutdown(context.Background()))
486486
})
487487
}
488-
runTest("enable_queue_batcher", true)
488+
// When queue_batcher is enabled, we don't cancel the whole batch when the first request is canceled.
489489
runTest("disable_queue_batcher", false)
490490
}
491491

exporter/exporterhelper/internal/batcher/merged_context.go

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,36 +11,41 @@ import (
1111

1212
// mergedContext links the underlying context to all incoming span contexts.
1313
type mergedContext struct {
14-
deadline time.Time
15-
deadlineOk bool
16-
ctx context.Context
14+
deadline time.Time
15+
deadlineOk bool
16+
deadlineCtx context.Context
17+
ctx context.Context
1718
}
1819

1920
func NewMergedContext(ctx context.Context) mergedContext {
2021
deadline, ok := ctx.Deadline()
2122
return mergedContext{
22-
deadline: deadline,
23-
deadlineOk: ok,
24-
ctx: ctx,
23+
deadline: deadline,
24+
deadlineOk: ok,
25+
deadlineCtx: ctx,
26+
ctx: ctx,
2527
}
2628
}
2729

2830
// Merge links the span from incoming context to the span from the first context.
2931
func (mc *mergedContext) Merge(other context.Context) mergedContext {
3032
deadline, deadlineOk := mc.Deadline()
33+
ctx := mc.deadlineCtx
3134
if otherDeadline, ok := other.Deadline(); ok {
3235
deadlineOk = true
3336
if deadline.Before(otherDeadline) {
3437
deadline = otherDeadline
38+
ctx = other
3539
}
3640
}
3741

3842
link := trace.LinkFromContext(other)
3943
trace.SpanFromContext(mc.ctx).AddLink(link)
4044
return mergedContext{
41-
deadline: deadline,
42-
deadlineOk: deadlineOk,
43-
ctx: mc.ctx,
45+
deadline: deadline,
46+
deadlineOk: deadlineOk,
47+
deadlineCtx: ctx,
48+
ctx: mc.ctx,
4449
}
4550
}
4651

@@ -50,11 +55,11 @@ func (mc mergedContext) Deadline() (time.Time, bool) {
5055
}
5156

5257
func (mc mergedContext) Done() <-chan struct{} {
53-
return nil
58+
return mc.deadlineCtx.Done()
5459
}
5560

5661
func (mc mergedContext) Err() error {
57-
return nil
62+
return mc.deadlineCtx.Err()
5863
}
5964

6065
// Value delegates to the first context.

exporter/exporterhelper/internal/batcher/merged_context_test.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,16 @@ func TestMergedContextDeadline(t *testing.T) {
4040
deadline, ok = mergedContext.Deadline()
4141
require.True(t, ok)
4242
require.Equal(t, now.Add(300), deadline)
43+
44+
time.Sleep(300)
45+
require.Equal(t, ctx3.Err(), mergedContext.Err())
4346
}
4447

4548
func TestMergedContextLink(t *testing.T) {
4649
tracerProvider := componenttest.NewTelemetry().NewTelemetrySettings().TracerProvider
4750
tracer := tracerProvider.Tracer("go.opentelemetry.io/collector/exporter/exporterhelper")
4851

49-
ctx1 := context.WithValue(context.Background(), "key", "value")
52+
ctx1 := context.Background()
5053
ctx2, span2 := tracer.Start(ctx1, "span2")
5154
defer span2.End()
5255

0 commit comments

Comments
 (0)