(t *testing.T)
| 1069 | } |
| 1070 | |
| 1071 | func TestLifecycler_StartingWithReadOnlyInstanceInRing(t *testing.T) { |
| 1072 | t.Parallel() |
| 1073 | |
| 1074 | ringStore, closer := consul.NewInMemoryClient(GetCodec(), log.NewNopLogger(), nil) |
| 1075 | t.Cleanup(func() { assert.NoError(t, closer.Close()) }) |
| 1076 | |
| 1077 | var ringConfig Config |
| 1078 | flagext.DefaultValues(&ringConfig) |
| 1079 | ringConfig.KVStore.Mock = ringStore |
| 1080 | |
| 1081 | ctx := context.Background() |
| 1082 | |
| 1083 | createLifecyclerFn := func(id string) *Lifecycler { |
| 1084 | // Add the first ingester to the ring |
| 1085 | lifecyclerConfig1 := testLifecyclerConfig(ringConfig, id) |
| 1086 | lifecyclerConfig1.HeartbeatPeriod = 100 * time.Millisecond |
| 1087 | lifecyclerConfig1.JoinAfter = 100 * time.Millisecond |
| 1088 | |
| 1089 | lifecycler, err := NewLifecycler(lifecyclerConfig1, &nopFlushTransferer{}, "ingester", ringKey, true, log.NewNopLogger(), nil) |
| 1090 | require.NoError(t, err) |
| 1091 | assert.Equal(t, 0, lifecycler.HealthyInstancesCount()) |
| 1092 | require.NoError(t, services.StartAndAwaitRunning(ctx, lifecycler)) |
| 1093 | t.Cleanup(func() { |
| 1094 | assert.NoError(t, services.StopAndAwaitTerminated(ctx, lifecycler)) |
| 1095 | }) |
| 1096 | return lifecycler |
| 1097 | } |
| 1098 | |
| 1099 | lifecycler1 := createLifecyclerFn("ing1") |
| 1100 | require.NoError(t, lifecycler1.ChangeReadOnlyState(ctx, true)) |
| 1101 | // Assert the ingester has changed to read only |
| 1102 | test.Poll(t, time.Second, true, func() interface{} { |
| 1103 | return lifecycler1.HealthyInstancesCount() == 1 && lifecycler1.ReadOnlyInstancesCount() == 1 |
| 1104 | }) |
| 1105 | |
| 1106 | // Assert the second ingester joins the ring and sees the first ingester as read only |
| 1107 | lifecycler2 := createLifecyclerFn("ing2") |
| 1108 | test.Poll(t, time.Second, true, func() interface{} { |
| 1109 | return lifecycler2.HealthyInstancesCount() == 2 && lifecycler2.ReadOnlyInstancesCount() == 1 |
| 1110 | }) |
| 1111 | } |
| 1112 | |
| 1113 | // Test Lifecycler when decreasing tokens and instance is already in the ring in leaving state. |
| 1114 | func TestLifecycler_DecreasingTokensLeavingInstanceInTheRing(t *testing.T) { |
nothing calls this directly
no test coverage detected