This test verifies that ring is getting updates, even after extending check in the loop method.
(t *testing.T)
| 3939 | |
| 3940 | // This test verifies that ring is getting updates, even after extending check in the loop method. |
| 3941 | func TestRingUpdates(t *testing.T) { |
| 3942 | const ( |
| 3943 | numInstances = 3 |
| 3944 | numZones = 3 |
| 3945 | ) |
| 3946 | |
| 3947 | tests := map[string]struct { |
| 3948 | excludedZones []string |
| 3949 | expectedInstances int |
| 3950 | expectedZones int |
| 3951 | expectedInstacesCountPerZone map[string]int |
| 3952 | }{ |
| 3953 | "without excluded zones": { |
| 3954 | expectedInstances: 3, |
| 3955 | expectedZones: 3, |
| 3956 | expectedInstacesCountPerZone: map[string]int{"zone-0": 1, "zone-1": 1, "zone-2": 1}, |
| 3957 | }, |
| 3958 | "with excluded zones": { |
| 3959 | excludedZones: []string{"zone-0"}, |
| 3960 | expectedInstances: 2, |
| 3961 | expectedZones: 2, |
| 3962 | expectedInstacesCountPerZone: map[string]int{"zone-0": 0 /* excluded! */, "zone-1": 1, "zone-2": 1}, |
| 3963 | }, |
| 3964 | } |
| 3965 | |
| 3966 | for testName, testData := range tests { |
| 3967 | testData := testData |
| 3968 | |
| 3969 | t.Run(testName, func(t *testing.T) { |
| 3970 | t.Parallel() |
| 3971 | |
| 3972 | inmem, closer := consul.NewInMemoryClient(GetCodec(), log.NewNopLogger(), nil) |
| 3973 | t.Cleanup(func() { assert.NoError(t, closer.Close()) }) |
| 3974 | |
| 3975 | cfg := Config{ |
| 3976 | KVStore: kv.Config{Mock: inmem}, |
| 3977 | HeartbeatTimeout: 1 * time.Minute, |
| 3978 | ReplicationFactor: 3, |
| 3979 | ExcludedZones: flagext.StringSliceCSV(testData.excludedZones), |
| 3980 | } |
| 3981 | |
| 3982 | ring, err := New(cfg, "test", "test", log.NewNopLogger(), nil) |
| 3983 | require.NoError(t, err) |
| 3984 | require.NoError(t, services.StartAndAwaitRunning(context.Background(), ring)) |
| 3985 | t.Cleanup(func() { |
| 3986 | _ = services.StopAndAwaitTerminated(context.Background(), ring) |
| 3987 | }) |
| 3988 | |
| 3989 | require.Equal(t, 0, ring.InstancesCount()) |
| 3990 | |
| 3991 | // Start 1 lifecycler for each instance we want to register in the ring. |
| 3992 | var lifecyclers []*Lifecycler |
| 3993 | for instanceID := 1; instanceID <= numInstances; instanceID++ { |
| 3994 | lifecyclers = append(lifecyclers, startLifecycler(t, cfg, 100*time.Millisecond, instanceID, numZones)) |
| 3995 | } |
| 3996 | |
| 3997 | // Ensure the ring client got updated. |
| 3998 | test.Poll(t, 1*time.Second, testData.expectedInstances, func() interface{} { |
nothing calls this directly
no test coverage detected