@@ -98,11 +98,11 @@ func TestPGCoordinatorSingle_AgentWithoutClients(t *testing.T) {
98
98
require .NoError (t , err )
99
99
defer coordinator .Close ()
100
100
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 )
104
104
require .Eventually (t , func () bool {
105
- agents , err := store .GetTailnetPeers (ctx , agent .ID )
105
+ agents , err := store .GetTailnetPeers (ctx , agent1 .ID )
106
106
if err != nil && ! xerrors .Is (err , sql .ErrNoRows ) {
107
107
t .Fatalf ("database error: %v" , err )
108
108
}
@@ -115,8 +115,8 @@ func TestPGCoordinatorSingle_AgentWithoutClients(t *testing.T) {
115
115
assert .EqualValues (t , 10 , node .PreferredDerp )
116
116
return true
117
117
}, 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 )
120
120
}
121
121
122
122
func TestPGCoordinatorSingle_AgentInvalidIP (t * testing.T ) {
@@ -132,18 +132,18 @@ func TestPGCoordinatorSingle_AgentInvalidIP(t *testing.T) {
132
132
require .NoError (t , err )
133
133
defer coordinator .Close ()
134
134
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 {
138
138
Addresses : []string {
139
139
agpl .TailscaleServicePrefix .RandomPrefix ().String (),
140
140
},
141
141
PreferredDerp : 10 ,
142
142
})
143
143
144
144
// 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 )
147
147
}
148
148
149
149
func TestPGCoordinatorSingle_AgentInvalidIPBits (t * testing.T ) {
@@ -159,18 +159,18 @@ func TestPGCoordinatorSingle_AgentInvalidIPBits(t *testing.T) {
159
159
require .NoError (t , err )
160
160
defer coordinator .Close ()
161
161
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 {
165
165
Addresses : []string {
166
- netip .PrefixFrom (agpl .TailscaleServicePrefix .AddrFromUUID (agent .ID ), 64 ).String (),
166
+ netip .PrefixFrom (agpl .TailscaleServicePrefix .AddrFromUUID (agent1 .ID ), 64 ).String (),
167
167
},
168
168
PreferredDerp : 10 ,
169
169
})
170
170
171
171
// 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 )
174
174
}
175
175
176
176
func TestPGCoordinatorSingle_AgentValidIP (t * testing.T ) {
@@ -186,16 +186,16 @@ func TestPGCoordinatorSingle_AgentValidIP(t *testing.T) {
186
186
require .NoError (t , err )
187
187
defer coordinator .Close ()
188
188
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 {
192
192
Addresses : []string {
193
- agpl .TailscaleServicePrefix .PrefixFromUUID (agent .ID ).String (),
193
+ agpl .TailscaleServicePrefix .PrefixFromUUID (agent1 .ID ).String (),
194
194
},
195
195
PreferredDerp : 10 ,
196
196
})
197
197
require .Eventually (t , func () bool {
198
- agents , err := store .GetTailnetPeers (ctx , agent .ID )
198
+ agents , err := store .GetTailnetPeers (ctx , agent1 .ID )
199
199
if err != nil && ! xerrors .Is (err , sql .ErrNoRows ) {
200
200
t .Fatalf ("database error: %v" , err )
201
201
}
@@ -208,8 +208,8 @@ func TestPGCoordinatorSingle_AgentValidIP(t *testing.T) {
208
208
assert .EqualValues (t , 10 , node .PreferredDerp )
209
209
return true
210
210
}, 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 )
213
213
}
214
214
215
215
func TestPGCoordinatorSingle_AgentWithClient (t * testing.T ) {
@@ -225,39 +225,39 @@ func TestPGCoordinatorSingle_AgentWithClient(t *testing.T) {
225
225
require .NoError (t , err )
226
226
defer coordinator .Close ()
227
227
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 )
231
231
232
- client := agpltest .NewClient (ctx , t , coordinator , "client" , agent .ID )
232
+ client := agpltest .NewClient (ctx , t , coordinator , "client" , agent1 .ID )
233
233
defer client .Close (ctx )
234
234
235
- client .AssertEventuallyHasDERP (agent .ID , 10 )
235
+ client .AssertEventuallyHasDERP (agent1 .ID , 10 )
236
236
client .UpdateDERP (11 )
237
- agent .AssertEventuallyHasDERP (client .ID , 11 )
237
+ agent1 .AssertEventuallyHasDERP (client .ID , 11 )
238
238
239
239
// 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 )
242
242
243
243
// Close the agent channel so a new one can connect.
244
- agent .Close (ctx )
244
+ agent1 .Close (ctx )
245
245
246
246
// 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 ))
248
248
// Ensure the coordinator sends its client node immediately!
249
- agent .AssertEventuallyHasDERP (client .ID , 11 )
249
+ agent1 .AssertEventuallyHasDERP (client .ID , 11 )
250
250
251
251
// Send a bunch of updates in rapid succession, and test that we eventually get the latest. We don't want the
252
252
// coordinator accidentally reordering things.
253
253
for d := int32 (13 ); d < 36 ; d ++ {
254
- agent .UpdateDERP (d )
254
+ agent1 .UpdateDERP (d )
255
255
}
256
- client .AssertEventuallyHasDERP (agent .ID , 35 )
256
+ client .AssertEventuallyHasDERP (agent1 .ID , 35 )
257
257
258
- agent .UngracefulDisconnect (ctx )
258
+ agent1 .UngracefulDisconnect (ctx )
259
259
client .UngracefulDisconnect (ctx )
260
- assertEventuallyLost (ctx , t , store , agent .ID )
260
+ assertEventuallyLost (ctx , t , store , agent1 .ID )
261
261
assertEventuallyLost (ctx , t , store , client .ID )
262
262
}
263
263
@@ -280,16 +280,16 @@ func TestPGCoordinatorSingle_MissedHeartbeats(t *testing.T) {
280
280
require .NoError (t , err )
281
281
defer coordinator .Close ()
282
282
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 )
286
286
287
- client := agpltest .NewClient (ctx , t , coordinator , "client" , agent .ID )
287
+ client := agpltest .NewClient (ctx , t , coordinator , "client" , agent1 .ID )
288
288
defer client .Close (ctx )
289
289
290
- client .AssertEventuallyHasDERP (agent .ID , 10 )
290
+ client .AssertEventuallyHasDERP (agent1 .ID , 10 )
291
291
client .UpdateDERP (11 )
292
- agent .AssertEventuallyHasDERP (client .ID , 11 )
292
+ agent1 .AssertEventuallyHasDERP (client .ID , 11 )
293
293
294
294
// simulate a second coordinator via DB calls only --- our goal is to test broken heart-beating, so we can't use a
295
295
// real coordinator
@@ -303,8 +303,8 @@ func TestPGCoordinatorSingle_MissedHeartbeats(t *testing.T) {
303
303
fCoord2 .heartbeat ()
304
304
afTrap .MustWait (ctx ).Release () // heartbeat timeout started
305
305
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 )
308
308
309
309
fCoord3 := & fakeCoordinator {
310
310
ctx : ctx ,
@@ -314,8 +314,8 @@ func TestPGCoordinatorSingle_MissedHeartbeats(t *testing.T) {
314
314
}
315
315
fCoord3 .heartbeat ()
316
316
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 )
319
319
320
320
// fCoord2 sends in a second heartbeat, one period later (on time)
321
321
mClock .Advance (tailnet .HeartbeatPeriod ).MustWait (ctx )
@@ -328,20 +328,20 @@ func TestPGCoordinatorSingle_MissedHeartbeats(t *testing.T) {
328
328
w := mClock .Advance (tailnet .HeartbeatPeriod )
329
329
rstTrap .MustWait (ctx ).Release ()
330
330
w .MustWait (ctx )
331
- client .AssertEventuallyHasDERP (agent .ID , 12 )
331
+ client .AssertEventuallyHasDERP (agent1 .ID , 12 )
332
332
333
333
// one more heartbeat period will result in fCoord2 being expired, which should cause us to
334
334
// revert to the original agent mapping
335
335
mClock .Advance (tailnet .HeartbeatPeriod ).MustWait (ctx )
336
336
// 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 )
338
338
339
339
// send fCoord3 heartbeat, which should trigger us to consider that mapping valid again.
340
340
fCoord3 .heartbeat ()
341
341
rstTrap .MustWait (ctx ).Release () // timeout gets reset
342
- client .AssertEventuallyHasDERP (agent .ID , 13 )
342
+ client .AssertEventuallyHasDERP (agent1 .ID , 13 )
343
343
344
- agent .UngracefulDisconnect (ctx )
344
+ agent1 .UngracefulDisconnect (ctx )
345
345
client .UngracefulDisconnect (ctx )
346
346
assertEventuallyLost (ctx , t , store , client .ID )
347
347
}
@@ -766,35 +766,35 @@ func TestPGCoordinator_NoDeleteOnClose(t *testing.T) {
766
766
require .NoError (t , err )
767
767
defer coordinator .Close ()
768
768
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 )
772
772
773
- client := agpltest .NewClient (ctx , t , coordinator , "client" , agent .ID )
773
+ client := agpltest .NewClient (ctx , t , coordinator , "client" , agent1 .ID )
774
774
defer client .Close (ctx )
775
775
776
776
// Simulate some traffic to generate
777
777
// a peer.
778
- client .AssertEventuallyHasDERP (agent .ID , 10 )
778
+ client .AssertEventuallyHasDERP (agent1 .ID , 10 )
779
779
client .UpdateDERP (11 )
780
780
781
- agent .AssertEventuallyHasDERP (client .ID , 11 )
781
+ agent1 .AssertEventuallyHasDERP (client .ID , 11 )
782
782
783
- anode := coordinator .Node (agent .ID )
783
+ anode := coordinator .Node (agent1 .ID )
784
784
require .NotNil (t , anode )
785
785
cnode := coordinator .Node (client .ID )
786
786
require .NotNil (t , cnode )
787
787
788
788
err = coordinator .Close ()
789
789
require .NoError (t , err )
790
- assertEventuallyLost (ctx , t , store , agent .ID )
790
+ assertEventuallyLost (ctx , t , store , agent1 .ID )
791
791
assertEventuallyLost (ctx , t , store , client .ID )
792
792
793
793
coordinator2 , err := tailnet .NewPGCoord (ctx , logger , ps , store )
794
794
require .NoError (t , err )
795
795
defer coordinator2 .Close ()
796
796
797
- anode = coordinator2 .Node (agent .ID )
797
+ anode = coordinator2 .Node (agent1 .ID )
798
798
require .NotNil (t , anode )
799
799
assert .Equal (t , 10 , anode .PreferredDERP )
800
800
@@ -1281,7 +1281,7 @@ func tcpEchoServer(t *testing.T) string {
1281
1281
tcpListener , err := net .Listen ("tcp" , "127.0.0.1:0" )
1282
1282
require .NoError (t , err )
1283
1283
t .Cleanup (func () {
1284
- tcpListener .Close ()
1284
+ _ = tcpListener .Close ()
1285
1285
listenerWg .Wait ()
1286
1286
})
1287
1287
listenerWg .Add (1 )
@@ -1304,14 +1304,15 @@ func tcpEchoServer(t *testing.T) string {
1304
1304
return tcpListener .Addr ().String ()
1305
1305
}
1306
1306
1307
+ // nolint:revive // t takes precedence.
1307
1308
func writeReadEcho (t * testing.T , ctx context.Context , conn net.Conn ) {
1308
1309
const msg = "hello, world"
1309
1310
1310
1311
deadline , ok := ctx .Deadline ()
1311
1312
if ok {
1312
- conn .SetWriteDeadline (deadline )
1313
+ _ = conn .SetWriteDeadline (deadline )
1313
1314
defer conn .SetWriteDeadline (time.Time {})
1314
- conn .SetReadDeadline (deadline )
1315
+ _ = conn .SetReadDeadline (deadline )
1315
1316
defer conn .SetReadDeadline (time.Time {})
1316
1317
}
1317
1318
0 commit comments