Skip to content

Commit eba9261

Browse files
committed
lint
1 parent 75849b8 commit eba9261

File tree

1 file changed

+66
-65
lines changed

1 file changed

+66
-65
lines changed

enterprise/tailnet/pgcoord_test.go

Lines changed: 66 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -98,11 +98,11 @@ func TestPGCoordinatorSingle_AgentWithoutClients(t *testing.T) {
9898
require.NoError(t, err)
9999
defer coordinator.Close()
100100

101-
agent := agpltest.NewAgent(ctx, t, coordinator, "agent")
102-
defer agent.Close(ctx)
103-
agent.UpdateDERP(10)
101+
agent1 := agpltest.NewAgent(ctx, t, coordinator, "agent")
102+
defer agent1.Close(ctx)
103+
agent1.UpdateDERP(10)
104104
require.Eventually(t, func() bool {
105-
agents, err := store.GetTailnetPeers(ctx, agent.ID)
105+
agents, err := store.GetTailnetPeers(ctx, agent1.ID)
106106
if err != nil && !xerrors.Is(err, sql.ErrNoRows) {
107107
t.Fatalf("database error: %v", err)
108108
}
@@ -115,8 +115,8 @@ func TestPGCoordinatorSingle_AgentWithoutClients(t *testing.T) {
115115
assert.EqualValues(t, 10, node.PreferredDerp)
116116
return true
117117
}, testutil.WaitShort, testutil.IntervalFast)
118-
agent.UngracefulDisconnect(ctx)
119-
assertEventuallyLost(ctx, t, store, agent.ID)
118+
agent1.UngracefulDisconnect(ctx)
119+
assertEventuallyLost(ctx, t, store, agent1.ID)
120120
}
121121

122122
func TestPGCoordinatorSingle_AgentInvalidIP(t *testing.T) {
@@ -132,18 +132,18 @@ func TestPGCoordinatorSingle_AgentInvalidIP(t *testing.T) {
132132
require.NoError(t, err)
133133
defer coordinator.Close()
134134

135-
agent := agpltest.NewAgent(ctx, t, coordinator, "agent")
136-
defer agent.Close(ctx)
137-
agent.UpdateNode(&proto.Node{
135+
agent1 := agpltest.NewAgent(ctx, t, coordinator, "agent")
136+
defer agent1.Close(ctx)
137+
agent1.UpdateNode(&proto.Node{
138138
Addresses: []string{
139139
agpl.TailscaleServicePrefix.RandomPrefix().String(),
140140
},
141141
PreferredDerp: 10,
142142
})
143143

144144
// The agent connection should be closed immediately after sending an invalid addr
145-
agent.AssertEventuallyResponsesClosed()
146-
assertEventuallyLost(ctx, t, store, agent.ID)
145+
agent1.AssertEventuallyResponsesClosed()
146+
assertEventuallyLost(ctx, t, store, agent1.ID)
147147
}
148148

149149
func TestPGCoordinatorSingle_AgentInvalidIPBits(t *testing.T) {
@@ -159,18 +159,18 @@ func TestPGCoordinatorSingle_AgentInvalidIPBits(t *testing.T) {
159159
require.NoError(t, err)
160160
defer coordinator.Close()
161161

162-
agent := agpltest.NewAgent(ctx, t, coordinator, "agent")
163-
defer agent.Close(ctx)
164-
agent.UpdateNode(&proto.Node{
162+
agent1 := agpltest.NewAgent(ctx, t, coordinator, "agent")
163+
defer agent1.Close(ctx)
164+
agent1.UpdateNode(&proto.Node{
165165
Addresses: []string{
166-
netip.PrefixFrom(agpl.TailscaleServicePrefix.AddrFromUUID(agent.ID), 64).String(),
166+
netip.PrefixFrom(agpl.TailscaleServicePrefix.AddrFromUUID(agent1.ID), 64).String(),
167167
},
168168
PreferredDerp: 10,
169169
})
170170

171171
// The agent connection should be closed immediately after sending an invalid addr
172-
agent.AssertEventuallyResponsesClosed()
173-
assertEventuallyLost(ctx, t, store, agent.ID)
172+
agent1.AssertEventuallyResponsesClosed()
173+
assertEventuallyLost(ctx, t, store, agent1.ID)
174174
}
175175

176176
func TestPGCoordinatorSingle_AgentValidIP(t *testing.T) {
@@ -186,16 +186,16 @@ func TestPGCoordinatorSingle_AgentValidIP(t *testing.T) {
186186
require.NoError(t, err)
187187
defer coordinator.Close()
188188

189-
agent := agpltest.NewAgent(ctx, t, coordinator, "agent")
190-
defer agent.Close(ctx)
191-
agent.UpdateNode(&proto.Node{
189+
agent1 := agpltest.NewAgent(ctx, t, coordinator, "agent")
190+
defer agent1.Close(ctx)
191+
agent1.UpdateNode(&proto.Node{
192192
Addresses: []string{
193-
agpl.TailscaleServicePrefix.PrefixFromUUID(agent.ID).String(),
193+
agpl.TailscaleServicePrefix.PrefixFromUUID(agent1.ID).String(),
194194
},
195195
PreferredDerp: 10,
196196
})
197197
require.Eventually(t, func() bool {
198-
agents, err := store.GetTailnetPeers(ctx, agent.ID)
198+
agents, err := store.GetTailnetPeers(ctx, agent1.ID)
199199
if err != nil && !xerrors.Is(err, sql.ErrNoRows) {
200200
t.Fatalf("database error: %v", err)
201201
}
@@ -208,8 +208,8 @@ func TestPGCoordinatorSingle_AgentValidIP(t *testing.T) {
208208
assert.EqualValues(t, 10, node.PreferredDerp)
209209
return true
210210
}, testutil.WaitShort, testutil.IntervalFast)
211-
agent.UngracefulDisconnect(ctx)
212-
assertEventuallyLost(ctx, t, store, agent.ID)
211+
agent1.UngracefulDisconnect(ctx)
212+
assertEventuallyLost(ctx, t, store, agent1.ID)
213213
}
214214

215215
func TestPGCoordinatorSingle_AgentWithClient(t *testing.T) {
@@ -225,39 +225,39 @@ func TestPGCoordinatorSingle_AgentWithClient(t *testing.T) {
225225
require.NoError(t, err)
226226
defer coordinator.Close()
227227

228-
agent := agpltest.NewAgent(ctx, t, coordinator, "original")
229-
defer agent.Close(ctx)
230-
agent.UpdateDERP(10)
228+
agent1 := agpltest.NewAgent(ctx, t, coordinator, "original")
229+
defer agent1.Close(ctx)
230+
agent1.UpdateDERP(10)
231231

232-
client := agpltest.NewClient(ctx, t, coordinator, "client", agent.ID)
232+
client := agpltest.NewClient(ctx, t, coordinator, "client", agent1.ID)
233233
defer client.Close(ctx)
234234

235-
client.AssertEventuallyHasDERP(agent.ID, 10)
235+
client.AssertEventuallyHasDERP(agent1.ID, 10)
236236
client.UpdateDERP(11)
237-
agent.AssertEventuallyHasDERP(client.ID, 11)
237+
agent1.AssertEventuallyHasDERP(client.ID, 11)
238238

239239
// Ensure an update to the agent node reaches the connIO!
240-
agent.UpdateDERP(12)
241-
client.AssertEventuallyHasDERP(agent.ID, 12)
240+
agent1.UpdateDERP(12)
241+
client.AssertEventuallyHasDERP(agent1.ID, 12)
242242

243243
// Close the agent channel so a new one can connect.
244-
agent.Close(ctx)
244+
agent1.Close(ctx)
245245

246246
// Create a new agent connection. This is to simulate a reconnect!
247-
agent = agpltest.NewPeer(ctx, t, coordinator, "reconnection", agpltest.WithID(agent.ID))
247+
agent1 = agpltest.NewPeer(ctx, t, coordinator, "reconnection", agpltest.WithID(agent1.ID))
248248
// Ensure the coordinator sends its client node immediately!
249-
agent.AssertEventuallyHasDERP(client.ID, 11)
249+
agent1.AssertEventuallyHasDERP(client.ID, 11)
250250

251251
// Send a bunch of updates in rapid succession, and test that we eventually get the latest. We don't want the
252252
// coordinator accidentally reordering things.
253253
for d := int32(13); d < 36; d++ {
254-
agent.UpdateDERP(d)
254+
agent1.UpdateDERP(d)
255255
}
256-
client.AssertEventuallyHasDERP(agent.ID, 35)
256+
client.AssertEventuallyHasDERP(agent1.ID, 35)
257257

258-
agent.UngracefulDisconnect(ctx)
258+
agent1.UngracefulDisconnect(ctx)
259259
client.UngracefulDisconnect(ctx)
260-
assertEventuallyLost(ctx, t, store, agent.ID)
260+
assertEventuallyLost(ctx, t, store, agent1.ID)
261261
assertEventuallyLost(ctx, t, store, client.ID)
262262
}
263263

@@ -280,16 +280,16 @@ func TestPGCoordinatorSingle_MissedHeartbeats(t *testing.T) {
280280
require.NoError(t, err)
281281
defer coordinator.Close()
282282

283-
agent := agpltest.NewAgent(ctx, t, coordinator, "agent")
284-
defer agent.Close(ctx)
285-
agent.UpdateDERP(10)
283+
agent1 := agpltest.NewAgent(ctx, t, coordinator, "agent")
284+
defer agent1.Close(ctx)
285+
agent1.UpdateDERP(10)
286286

287-
client := agpltest.NewClient(ctx, t, coordinator, "client", agent.ID)
287+
client := agpltest.NewClient(ctx, t, coordinator, "client", agent1.ID)
288288
defer client.Close(ctx)
289289

290-
client.AssertEventuallyHasDERP(agent.ID, 10)
290+
client.AssertEventuallyHasDERP(agent1.ID, 10)
291291
client.UpdateDERP(11)
292-
agent.AssertEventuallyHasDERP(client.ID, 11)
292+
agent1.AssertEventuallyHasDERP(client.ID, 11)
293293

294294
// simulate a second coordinator via DB calls only --- our goal is to test broken heart-beating, so we can't use a
295295
// real coordinator
@@ -303,8 +303,8 @@ func TestPGCoordinatorSingle_MissedHeartbeats(t *testing.T) {
303303
fCoord2.heartbeat()
304304
afTrap.MustWait(ctx).Release() // heartbeat timeout started
305305

306-
fCoord2.agentNode(agent.ID, &agpl.Node{PreferredDERP: 12})
307-
client.AssertEventuallyHasDERP(agent.ID, 12)
306+
fCoord2.agentNode(agent1.ID, &agpl.Node{PreferredDERP: 12})
307+
client.AssertEventuallyHasDERP(agent1.ID, 12)
308308

309309
fCoord3 := &fakeCoordinator{
310310
ctx: ctx,
@@ -314,8 +314,8 @@ func TestPGCoordinatorSingle_MissedHeartbeats(t *testing.T) {
314314
}
315315
fCoord3.heartbeat()
316316
rstTrap.MustWait(ctx).Release() // timeout gets reset
317-
fCoord3.agentNode(agent.ID, &agpl.Node{PreferredDERP: 13})
318-
client.AssertEventuallyHasDERP(agent.ID, 13)
317+
fCoord3.agentNode(agent1.ID, &agpl.Node{PreferredDERP: 13})
318+
client.AssertEventuallyHasDERP(agent1.ID, 13)
319319

320320
// fCoord2 sends in a second heartbeat, one period later (on time)
321321
mClock.Advance(tailnet.HeartbeatPeriod).MustWait(ctx)
@@ -328,20 +328,20 @@ func TestPGCoordinatorSingle_MissedHeartbeats(t *testing.T) {
328328
w := mClock.Advance(tailnet.HeartbeatPeriod)
329329
rstTrap.MustWait(ctx).Release()
330330
w.MustWait(ctx)
331-
client.AssertEventuallyHasDERP(agent.ID, 12)
331+
client.AssertEventuallyHasDERP(agent1.ID, 12)
332332

333333
// one more heartbeat period will result in fCoord2 being expired, which should cause us to
334334
// revert to the original agent mapping
335335
mClock.Advance(tailnet.HeartbeatPeriod).MustWait(ctx)
336336
// note that the timeout doesn't get reset because both fCoord2 and fCoord3 are expired
337-
client.AssertEventuallyHasDERP(agent.ID, 10)
337+
client.AssertEventuallyHasDERP(agent1.ID, 10)
338338

339339
// send fCoord3 heartbeat, which should trigger us to consider that mapping valid again.
340340
fCoord3.heartbeat()
341341
rstTrap.MustWait(ctx).Release() // timeout gets reset
342-
client.AssertEventuallyHasDERP(agent.ID, 13)
342+
client.AssertEventuallyHasDERP(agent1.ID, 13)
343343

344-
agent.UngracefulDisconnect(ctx)
344+
agent1.UngracefulDisconnect(ctx)
345345
client.UngracefulDisconnect(ctx)
346346
assertEventuallyLost(ctx, t, store, client.ID)
347347
}
@@ -766,35 +766,35 @@ func TestPGCoordinator_NoDeleteOnClose(t *testing.T) {
766766
require.NoError(t, err)
767767
defer coordinator.Close()
768768

769-
agent := agpltest.NewAgent(ctx, t, coordinator, "original")
770-
defer agent.Close(ctx)
771-
agent.UpdateDERP(10)
769+
agent1 := agpltest.NewAgent(ctx, t, coordinator, "original")
770+
defer agent1.Close(ctx)
771+
agent1.UpdateDERP(10)
772772

773-
client := agpltest.NewClient(ctx, t, coordinator, "client", agent.ID)
773+
client := agpltest.NewClient(ctx, t, coordinator, "client", agent1.ID)
774774
defer client.Close(ctx)
775775

776776
// Simulate some traffic to generate
777777
// a peer.
778-
client.AssertEventuallyHasDERP(agent.ID, 10)
778+
client.AssertEventuallyHasDERP(agent1.ID, 10)
779779
client.UpdateDERP(11)
780780

781-
agent.AssertEventuallyHasDERP(client.ID, 11)
781+
agent1.AssertEventuallyHasDERP(client.ID, 11)
782782

783-
anode := coordinator.Node(agent.ID)
783+
anode := coordinator.Node(agent1.ID)
784784
require.NotNil(t, anode)
785785
cnode := coordinator.Node(client.ID)
786786
require.NotNil(t, cnode)
787787

788788
err = coordinator.Close()
789789
require.NoError(t, err)
790-
assertEventuallyLost(ctx, t, store, agent.ID)
790+
assertEventuallyLost(ctx, t, store, agent1.ID)
791791
assertEventuallyLost(ctx, t, store, client.ID)
792792

793793
coordinator2, err := tailnet.NewPGCoord(ctx, logger, ps, store)
794794
require.NoError(t, err)
795795
defer coordinator2.Close()
796796

797-
anode = coordinator2.Node(agent.ID)
797+
anode = coordinator2.Node(agent1.ID)
798798
require.NotNil(t, anode)
799799
assert.Equal(t, 10, anode.PreferredDERP)
800800

@@ -1281,7 +1281,7 @@ func tcpEchoServer(t *testing.T) string {
12811281
tcpListener, err := net.Listen("tcp", "127.0.0.1:0")
12821282
require.NoError(t, err)
12831283
t.Cleanup(func() {
1284-
tcpListener.Close()
1284+
_ = tcpListener.Close()
12851285
listenerWg.Wait()
12861286
})
12871287
listenerWg.Add(1)
@@ -1304,14 +1304,15 @@ func tcpEchoServer(t *testing.T) string {
13041304
return tcpListener.Addr().String()
13051305
}
13061306

1307+
// nolint:revive // t takes precedence.
13071308
func writeReadEcho(t *testing.T, ctx context.Context, conn net.Conn) {
13081309
const msg = "hello, world"
13091310

13101311
deadline, ok := ctx.Deadline()
13111312
if ok {
1312-
conn.SetWriteDeadline(deadline)
1313+
_ = conn.SetWriteDeadline(deadline)
13131314
defer conn.SetWriteDeadline(time.Time{})
1314-
conn.SetReadDeadline(deadline)
1315+
_ = conn.SetReadDeadline(deadline)
13151316
defer conn.SetReadDeadline(time.Time{})
13161317
}
13171318

0 commit comments

Comments
 (0)