(t *testing.T)
| 218 | } |
| 219 | |
| 220 | func TestPGCoordinatorSingle_AgentWithClient(t *testing.T) { |
| 221 | t.Parallel() |
| 222 | |
| 223 | store, ps := dbtestutil.NewDB(t) |
| 224 | ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitSuperLong) |
| 225 | defer cancel() |
| 226 | logger := testutil.Logger(t) |
| 227 | coordinator, err := tailnet.NewPGCoord(ctx, logger, ps, store) |
| 228 | require.NoError(t, err) |
| 229 | defer coordinator.Close() |
| 230 | |
| 231 | agent := agpltest.NewAgent(ctx, t, coordinator, "original") |
| 232 | defer agent.Close(ctx) |
| 233 | agent.UpdateDERP(10) |
| 234 | |
| 235 | client := agpltest.NewClient(ctx, t, coordinator, "client", agent.ID) |
| 236 | defer client.Close(ctx) |
| 237 | |
| 238 | client.AssertEventuallyHasDERP(agent.ID, 10) |
| 239 | client.UpdateDERP(11) |
| 240 | agent.AssertEventuallyHasDERP(client.ID, 11) |
| 241 | |
| 242 | // Ensure an update to the agent node reaches the connIO! |
| 243 | agent.UpdateDERP(12) |
| 244 | client.AssertEventuallyHasDERP(agent.ID, 12) |
| 245 | |
| 246 | // Close the agent channel so a new one can connect. |
| 247 | agent.Close(ctx) |
| 248 | |
| 249 | // Create a new agent connection. This is to simulate a reconnect! |
| 250 | agent = agpltest.NewPeer(ctx, t, coordinator, "reconnection", agpltest.WithID(agent.ID)) |
| 251 | // Ensure the coordinator sends its client node immediately! |
| 252 | agent.AssertEventuallyHasDERP(client.ID, 11) |
| 253 | |
| 254 | // Send a bunch of updates in rapid succession, and test that we eventually get the latest. We don't want the |
| 255 | // coordinator accidentally reordering things. |
| 256 | for d := int32(13); d < 36; d++ { |
| 257 | agent.UpdateDERP(d) |
| 258 | } |
| 259 | client.AssertEventuallyHasDERP(agent.ID, 35) |
| 260 | |
| 261 | agent.UngracefulDisconnect(ctx) |
| 262 | client.UngracefulDisconnect(ctx) |
| 263 | assertEventuallyLost(ctx, t, store, agent.ID) |
| 264 | assertEventuallyLost(ctx, t, store, client.ID) |
| 265 | } |
| 266 | |
| 267 | func TestPGCoordinatorSingle_MissedHeartbeats(t *testing.T) { |
| 268 | t.Parallel() |
nothing calls this directly
no test coverage detected