Skip to content

Commit a621684

Browse files
committed
move context to function callbacks
1 parent da24738 commit a621684

File tree

5 files changed

+16
-20
lines changed

5 files changed

+16
-20
lines changed

core/connection/connection.go

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -364,7 +364,6 @@ func (c *connection) commandStartedEvent(ctx context.Context, wm wiremessage.Wir
364364
}
365365

366366
startedEvent := &event.CommandStartedEvent{
367-
Context: ctx,
368367
ConnectionID: c.id,
369368
}
370369

@@ -418,7 +417,7 @@ func (c *connection) commandStartedEvent(ctx context.Context, wm wiremessage.Wir
418417
startedEvent.Command = emptyDoc
419418
}
420419

421-
c.cmdMonitor.Started(startedEvent)
420+
c.cmdMonitor.Started(ctx, startedEvent)
422421

423422
if !acknowledged {
424423
if c.cmdMonitor.Succeeded == nil {
@@ -427,14 +426,13 @@ func (c *connection) commandStartedEvent(ctx context.Context, wm wiremessage.Wir
427426

428427
// unack writes must provide a CommandSucceededEvent with an { ok: 1 } reply
429428
finishedEvent := event.CommandFinishedEvent{
430-
Context: ctx,
431429
DurationNanos: 0,
432430
CommandName: startedEvent.CommandName,
433431
RequestID: startedEvent.RequestID,
434432
ConnectionID: c.id,
435433
}
436434

437-
c.cmdMonitor.Succeeded(&event.CommandSucceededEvent{
435+
c.cmdMonitor.Succeeded(ctx, &event.CommandSucceededEvent{
438436
CommandFinishedEvent: finishedEvent,
439437
Reply: bson.NewDocument(
440438
bson.EC.Int32("ok", 1),
@@ -522,7 +520,6 @@ func (c *connection) commandFinishedEvent(ctx context.Context, wm wiremessage.Wi
522520
}
523521

524522
finishedEvent := event.CommandFinishedEvent{
525-
Context: ctx,
526523
DurationNanos: cmdMetadata.TimeDifference(),
527524
CommandName: cmdMetadata.Name,
528525
RequestID: requestID,
@@ -535,7 +532,7 @@ func (c *connection) commandFinishedEvent(ctx context.Context, wm wiremessage.Wi
535532
Reply: emptyDoc,
536533
CommandFinishedEvent: finishedEvent,
537534
}
538-
c.cmdMonitor.Succeeded(successEvent)
535+
c.cmdMonitor.Succeeded(ctx, successEvent)
539536
return nil
540537
}
541538

@@ -556,7 +553,7 @@ func (c *connection) commandFinishedEvent(ctx context.Context, wm wiremessage.Wi
556553
CommandFinishedEvent: finishedEvent,
557554
}
558555

559-
c.cmdMonitor.Succeeded(successEvent)
556+
c.cmdMonitor.Succeeded(ctx, successEvent)
560557
return nil
561558
}
562559

@@ -565,7 +562,7 @@ func (c *connection) commandFinishedEvent(ctx context.Context, wm wiremessage.Wi
565562
CommandFinishedEvent: finishedEvent,
566563
}
567564

568-
c.cmdMonitor.Failed(failureEvent)
565+
c.cmdMonitor.Failed(ctx, failureEvent)
569566
return nil
570567
}
571568

core/event/monitoring.go

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ func (cm *CommandMetadata) TimeDifference() int64 {
3030

3131
// CommandStartedEvent represents an event generated when a command is sent to a server.
3232
type CommandStartedEvent struct {
33-
Context context.Context
3433
Command *bson.Document
3534
DatabaseName string
3635
CommandName string
@@ -40,7 +39,6 @@ type CommandStartedEvent struct {
4039

4140
// CommandFinishedEvent represents a generic command finishing.
4241
type CommandFinishedEvent struct {
43-
Context context.Context
4442
DurationNanos int64
4543
CommandName string
4644
RequestID int64
@@ -61,7 +59,7 @@ type CommandFailedEvent struct {
6159

6260
// CommandMonitor represents a monitor that is triggered for different events.
6361
type CommandMonitor struct {
64-
Started func(*CommandStartedEvent)
65-
Succeeded func(*CommandSucceededEvent)
66-
Failed func(*CommandFailedEvent)
62+
Started func(context.Context, *CommandStartedEvent)
63+
Succeeded func(context.Context, *CommandSucceededEvent)
64+
Failed func(context.Context, *CommandFailedEvent)
6765
}

mongo/causal_consistency_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package mongo
22

33
import (
4+
"context"
45
"os"
56
"reflect"
67
"testing"
@@ -17,10 +18,10 @@ var ccStarted *event.CommandStartedEvent
1718
var ccSucceeded *event.CommandSucceededEvent
1819

1920
var ccMonitor = &event.CommandMonitor{
20-
Started: func(cse *event.CommandStartedEvent) {
21+
Started: func(ctx context.Context, cse *event.CommandStartedEvent) {
2122
ccStarted = cse
2223
},
23-
Succeeded: func(cse *event.CommandSucceededEvent) {
24+
Succeeded: func(ctx context.Context, cse *event.CommandSucceededEvent) {
2425
ccSucceeded = cse
2526
},
2627
}

mongo/command_monitoring_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,13 @@ var failedChan = make(chan *event.CommandFailedEvent, 100)
3232
var cursorID int64
3333

3434
var monitor = &event.CommandMonitor{
35-
Started: func(cse *event.CommandStartedEvent) {
35+
Started: func(ctx context.Context, cse *event.CommandStartedEvent) {
3636
startedChan <- cse
3737
},
38-
Succeeded: func(cse *event.CommandSucceededEvent) {
38+
Succeeded: func(ctx context.Context, cse *event.CommandSucceededEvent) {
3939
succeededChan <- cse
4040
},
41-
Failed: func(cfe *event.CommandFailedEvent) {
41+
Failed: func(ctx context.Context, cfe *event.CommandFailedEvent) {
4242
failedChan <- cfe
4343
},
4444
}

mongo/sessions_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,10 @@ var sessionSucceeded *event.CommandSucceededEvent
4747
var sessionsMonitoredTop *topology.Topology
4848

4949
var sessionsMonitor = &event.CommandMonitor{
50-
Started: func(cse *event.CommandStartedEvent) {
50+
Started: func(ctx context.Context, cse *event.CommandStartedEvent) {
5151
sessionStarted = cse
5252
},
53-
Succeeded: func(cse *event.CommandSucceededEvent) {
53+
Succeeded: func(ctx context.Context, cse *event.CommandSucceededEvent) {
5454
sessionSucceeded = cse
5555
},
5656
}

0 commit comments

Comments
 (0)