Test that values are set in the HATracker after WatchPrefix has found it in the KVStore.
(t *testing.T)
| 285 | |
| 286 | // Test that values are set in the HATracker after WatchPrefix has found it in the KVStore. |
| 287 | func TestWatchPrefixAssignment(t *testing.T) { |
| 288 | t.Parallel() |
| 289 | replicaGroup := "c1" |
| 290 | replica := "r1" |
| 291 | |
| 292 | codec := GetReplicaDescCodec() |
| 293 | kvStore, closer := consul.NewInMemoryClient(codec, log.NewNopLogger(), nil) |
| 294 | t.Cleanup(func() { assert.NoError(t, closer.Close()) }) |
| 295 | |
| 296 | mock := kv.PrefixClient(kvStore, "prefix") |
| 297 | c, err := NewHATracker(HATrackerConfig{ |
| 298 | EnableHATracker: true, |
| 299 | KVStore: kv.Config{Mock: mock}, |
| 300 | UpdateTimeout: time.Millisecond, |
| 301 | UpdateTimeoutJitterMax: 0, |
| 302 | FailoverTimeout: time.Millisecond * 2, |
| 303 | }, trackerLimits{maxReplicaGroups: 100}, haTrackerStatusConfig, nil, "test-ha-tracker", log.NewNopLogger()) |
| 304 | require.NoError(t, err) |
| 305 | require.NoError(t, services.StartAndAwaitRunning(context.Background(), c)) |
| 306 | defer services.StopAndAwaitTerminated(context.Background(), c) //nolint:errcheck |
| 307 | |
| 308 | // Write the first time. |
| 309 | now := time.Now() |
| 310 | |
| 311 | err = c.CheckReplica(context.Background(), "user", replicaGroup, replica, now) |
| 312 | assert.NoError(t, err) |
| 313 | |
| 314 | // Check to see if the value in the trackers cache is correct. |
| 315 | checkReplicaTimestamp(t, time.Second, c, "user", replicaGroup, replica, now) |
| 316 | } |
| 317 | |
| 318 | func TestCheckReplicaOverwriteTimeout(t *testing.T) { |
| 319 | t.Parallel() |
nothing calls this directly
no test coverage detected