Skip to content

Commit

Permalink
Merge pull request #22 from m-lab/sandbox-soltesz-ctxfix
Browse files Browse the repository at this point in the history
Add context to Open & Close methods
  • Loading branch information
stephen-soltesz authored Nov 25, 2019
2 parents d7b6430 + 598b745 commit d38b036
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
4 changes: 2 additions & 2 deletions tcpinfohandler/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ type handler struct {
}

// Open processes an Open message for a new flow, sending its UUID to the demuxer.
func (h *handler) Open(timestamp time.Time, uuid string, id *inetdiag.SockID) {
func (h *handler) Open(ctx context.Context, timestamp time.Time, uuid string, id *inetdiag.SockID) {
if id == nil {
metrics.BadEventsFromTCPInfo.WithLabelValues("nilid").Inc()
return
Expand All @@ -48,7 +48,7 @@ func (h *handler) Open(timestamp time.Time, uuid string, id *inetdiag.SockID) {
}

// Close does nothing. Timeouts are the authoritative closing mechanism.
func (h *handler) Close(timestamp time.Time, uuid string) {
func (h *handler) Close(ctx context.Context, timestamp time.Time, uuid string) {
}

// New makes a new eventsocket.Handler that informs the demuxer of new flow
Expand Down
8 changes: 4 additions & 4 deletions tcpinfohandler/handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ func TestHandlerOpen(t *testing.T) {
c := make(chan demuxer.UUIDEvent, 1)
h := New(ctx, c)

h.Open(time.Now(), "nildata", nil) // No crash == success
h.Open(time.Now(), "badips", &inetdiag.SockID{}) // No crash == success
h.Open(ctx, time.Now(), "nildata", nil) // No crash == success
h.Open(ctx, time.Now(), "badips", &inetdiag.SockID{}) // No crash == success

// Channel should be empty after the bad messages.
select {
Expand All @@ -40,7 +40,7 @@ func TestHandlerOpen(t *testing.T) {
DPort: dPort,
}

h.Open(timestamp, uuid, sockid)
h.Open(ctx, timestamp, uuid, sockid)
// Read the event from the channel
e := <-c
if e.Timestamp != timestamp {
Expand All @@ -51,5 +51,5 @@ func TestHandlerOpen(t *testing.T) {
}

// Make sure that Close won't crash. It should do nothing.
h.Close(timestamp, uuid) // no crash == success
h.Close(ctx, timestamp, uuid) // no crash == success
}

0 comments on commit d38b036

Please sign in to comment.