Skip to content

Commit 2b8c3f8

Browse files
committed
Use context.TODO in more places
1 parent a626fe3 commit 2b8c3f8

File tree

5 files changed

+18
-18
lines changed

5 files changed

+18
-18
lines changed

cmd/contact-auditor/main.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,9 +99,9 @@ func (c contactAuditor) writeResults(result string) {
9999
// run retrieves a cursor from `beginAuditQuery` and then audits the
100100
// `contact` column of all returned rows for abnormalities or policy
101101
// violations.
102-
func (c contactAuditor) run(resChan chan *result) error {
102+
func (c contactAuditor) run(ctx context.Context, resChan chan *result) error {
103103
c.logger.Infof("Beginning database query")
104-
rows, err := c.beginAuditQuery(context.Background())
104+
rows, err := c.beginAuditQuery(ctx)
105105
if err != nil {
106106
return err
107107
}
@@ -194,7 +194,7 @@ func main() {
194194

195195
logger.Info("Running contact-auditor")
196196

197-
err = auditor.run(nil)
197+
err = auditor.run(context.TODO(), nil)
198198
cmd.FailOnError(err, "Audit was interrupted, results may be incomplete")
199199

200200
logger.Info("Audit finished successfully")

cmd/contact-auditor/main_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ func TestContactAuditor(t *testing.T) {
4141
testCtx.addRegistrations(t)
4242

4343
resChan := make(chan *result, 10)
44-
err := testCtx.c.run(resChan)
44+
err := testCtx.c.run(context.Background(), resChan)
4545
test.AssertNotError(t, err, "received error")
4646

4747
// We should get back A, B, C, and D

cmd/id-exporter/main.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -283,15 +283,15 @@ func main() {
283283
hostnames, err := unmarshalHostnames(*hostnamesFile)
284284
cmd.FailOnError(err, "Problem unmarshalling hostnames")
285285

286-
results, err = exporter.findIDsForHostnames(context.Background(), hostnames)
286+
results, err = exporter.findIDsForHostnames(context.TODO(), hostnames)
287287
cmd.FailOnError(err, "Could not find IDs for hostnames")
288288

289289
} else if *withExampleHostnames {
290-
results, err = exporter.findIDsWithExampleHostnames(context.Background())
290+
results, err = exporter.findIDsWithExampleHostnames(context.TODO())
291291
cmd.FailOnError(err, "Could not find IDs with hostnames")
292292

293293
} else {
294-
results, err = exporter.findIDs(context.Background())
294+
results, err = exporter.findIDs(context.TODO())
295295
cmd.FailOnError(err, "Could not find IDs")
296296
}
297297

cmd/notify-mailer/main.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ func (m *mailer) makeMessageBody(recipients []recipient) (string, error) {
120120
return messageBody.String(), nil
121121
}
122122

123-
func (m *mailer) run() error {
123+
func (m *mailer) run(ctx context.Context) error {
124124
err := m.ok()
125125
if err != nil {
126126
return err
@@ -129,7 +129,7 @@ func (m *mailer) run() error {
129129
totalRecipients := len(m.recipients)
130130
m.log.Infof("Resolving addresses for (%d) recipients", totalRecipients)
131131

132-
addressToRecipient, err := m.resolveAddresses(context.Background())
132+
addressToRecipient, err := m.resolveAddresses(ctx)
133133
if err != nil {
134134
return err
135135
}
@@ -607,7 +607,7 @@ func main() {
607607
parallelSends: *parallelSends,
608608
}
609609

610-
err = m.run()
610+
err = m.run(context.TODO())
611611
cmd.FailOnError(err, "Couldn't complete")
612612

613613
log.Info("Completed successfully")

cmd/notify-mailer/main_test.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,7 @@ func TestSleepInterval(t *testing.T) {
295295
// Call run() - this should sleep `sleepLen` per destination address
296296
// After it returns, we expect (sleepLen * number of destinations) seconds has
297297
// elapsed
298-
err := m.run()
298+
err := m.run(context.Background())
299299
test.AssertNotError(t, err, "error calling mailer run()")
300300
expectedEnd := clock.NewFake()
301301
expectedEnd.Add(time.Second * time.Duration(sleepLen*len(recipients)))
@@ -315,7 +315,7 @@ func TestSleepInterval(t *testing.T) {
315315

316316
// Call run() - this should blast through all destinations without sleep
317317
// After it returns, we expect no clock time to have elapsed on the fake clock
318-
err = m.run()
318+
err = m.run(context.Background())
319319
test.AssertNotError(t, err, "error calling mailer run()")
320320
expectedEnd = clock.NewFake()
321321
test.AssertEquals(t, m.clk.Now(), expectedEnd.Now())
@@ -346,7 +346,7 @@ func TestMailIntervals(t *testing.T) {
346346

347347
// Run the mailer. It should produce an error about the interval start
348348
mc.Clear()
349-
err := m.run()
349+
err := m.run(context.Background())
350350
test.AssertError(t, err, "expected error")
351351
test.AssertEquals(t, len(mc.Messages), 0)
352352

@@ -365,7 +365,7 @@ func TestMailIntervals(t *testing.T) {
365365

366366
// Run the mailer. It should produce an error about the sleep interval
367367
mc.Clear()
368-
err = m.run()
368+
err = m.run(context.Background())
369369
test.AssertEquals(t, len(mc.Messages), 0)
370370
test.AssertEquals(t, err.Error(), "sleep interval (-10) is < 0")
371371

@@ -387,7 +387,7 @@ func TestMailIntervals(t *testing.T) {
387387
// [email protected] (beginning of the range),
388388
// and one to [email protected].
389389
mc.Clear()
390-
err = m.run()
390+
err = m.run(context.Background())
391391
test.AssertNotError(t, err, "run() produced an error")
392392
test.AssertEquals(t, len(mc.Messages), 2)
393393
test.AssertEquals(t, mocks.MailerMessage{
@@ -418,7 +418,7 @@ func TestMailIntervals(t *testing.T) {
418418
// Run the mailer. Two messages should have been produced, one to
419419
// [email protected] (ID 1), one to [email protected] (ID 2)
420420
mc.Clear()
421-
err = m.run()
421+
err = m.run(context.Background())
422422
test.AssertNotError(t, err, "run() produced an error")
423423
test.AssertEquals(t, len(mc.Messages), 2)
424424
test.AssertEquals(t, mocks.MailerMessage{
@@ -457,7 +457,7 @@ func TestParallelism(t *testing.T) {
457457
}
458458

459459
mc.Clear()
460-
err := m.run()
460+
err := m.run(context.Background())
461461
test.AssertNotError(t, err, "run() produced an error")
462462

463463
// The fake clock should have advanced 9 seconds, one for each parallel
@@ -500,7 +500,7 @@ func TestMessageContentStatic(t *testing.T) {
500500

501501
// Run the mailer, one message should have been created with the content
502502
// expected
503-
err := m.run()
503+
err := m.run(context.Background())
504504
test.AssertNotError(t, err, "error calling mailer run()")
505505
test.AssertEquals(t, len(mc.Messages), 1)
506506
test.AssertEquals(t, mocks.MailerMessage{

0 commit comments

Comments
 (0)