(t *testing.T)
| 316 | } |
| 317 | |
| 318 | func TestCheckReplicaOverwriteTimeout(t *testing.T) { |
| 319 | t.Parallel() |
| 320 | replica1 := "replica1" |
| 321 | replica2 := "replica2" |
| 322 | |
| 323 | c, err := NewHATracker(HATrackerConfig{ |
| 324 | EnableHATracker: true, |
| 325 | KVStore: kv.Config{Store: "inmemory"}, |
| 326 | UpdateTimeout: 100 * time.Millisecond, |
| 327 | UpdateTimeoutJitterMax: 0, |
| 328 | FailoverTimeout: time.Second, |
| 329 | }, trackerLimits{maxReplicaGroups: 100}, haTrackerStatusConfig, nil, "test-ha-tracker", log.NewNopLogger()) |
| 330 | require.NoError(t, err) |
| 331 | require.NoError(t, services.StartAndAwaitRunning(context.Background(), c)) |
| 332 | defer services.StopAndAwaitTerminated(context.Background(), c) //nolint:errcheck |
| 333 | |
| 334 | now := time.Now() |
| 335 | |
| 336 | // Write the first time. |
| 337 | err = c.CheckReplica(context.Background(), "user", "test", replica1, now) |
| 338 | assert.NoError(t, err) |
| 339 | |
| 340 | // Throw away a sample from replica2. |
| 341 | err = c.CheckReplica(context.Background(), "user", "test", replica2, now) |
| 342 | assert.Error(t, err) |
| 343 | |
| 344 | // Wait more than the overwrite timeout. |
| 345 | now = now.Add(1100 * time.Millisecond) |
| 346 | |
| 347 | // Accept from replica 2, this should overwrite the saved replica of replica 1. |
| 348 | err = c.CheckReplica(context.Background(), "user", "test", replica2, now) |
| 349 | assert.NoError(t, err) |
| 350 | |
| 351 | // We timed out accepting samples from replica 1 and should now reject them. |
| 352 | err = c.CheckReplica(context.Background(), "user", "test", replica1, now) |
| 353 | assert.Error(t, err) |
| 354 | } |
| 355 | |
| 356 | func TestCheckReplicaMultiCluster(t *testing.T) { |
| 357 | t.Parallel() |
nothing calls this directly
no test coverage detected