(t *testing.T)
| 218 | } |
| 219 | |
| 220 | func TestCluster_AddRemovePeer(t *testing.T) { |
| 221 | cluster := NewTestCluster(3) |
| 222 | defer cluster.Close() |
| 223 | |
| 224 | ctx := context.Background() |
| 225 | require.Eventually(t, func() bool { |
| 226 | return cluster.IsReady(ctx) |
| 227 | }, 10*time.Second, 100*time.Millisecond) |
| 228 | |
| 229 | n1 := cluster.GetNode(0) |
| 230 | require.NoError(t, n1.Set(ctx, "foo", []byte("bar"))) |
| 231 | require.Eventually(t, func() bool { |
| 232 | got, _ := n1.Get(ctx, "foo") |
| 233 | return string(got) == "bar" |
| 234 | }, 1*time.Second, 100*time.Millisecond) |
| 235 | |
| 236 | t.Run("add a new peer node", func(t *testing.T) { |
| 237 | n4, err := cluster.createNode(n1.config.Peers) |
| 238 | require.NoError(t, err) |
| 239 | require.NotNil(t, n4) |
| 240 | |
| 241 | require.NoError(t, cluster.AddNode(ctx, n4.config.ID, n4.Addr())) |
| 242 | require.Eventually(t, func() bool { |
| 243 | return n4.IsReady(ctx) |
| 244 | }, 10*time.Second, 100*time.Millisecond) |
| 245 | |
| 246 | require.NoError(t, n4.Set(ctx, "foo", []byte("bar-1"))) |
| 247 | require.Eventually(t, func() bool { |
| 248 | got, _ := n1.Get(ctx, "foo") |
| 249 | return string(got) == "bar-1" |
| 250 | }, 1*time.Second, 100*time.Millisecond) |
| 251 | require.Len(t, n1.ListPeers(), 4) |
| 252 | }) |
| 253 | |
| 254 | t.Run("remove a peer node", func(t *testing.T) { |
| 255 | cluster.RemoveNode(ctx, 4) |
| 256 | require.Eventually(t, func() bool { |
| 257 | return len(n1.ListPeers()) == 3 |
| 258 | }, 10*time.Second, 100*time.Millisecond) |
| 259 | }) |
| 260 | } |
| 261 | |
| 262 | func TestTriggerSnapshot(t *testing.T) { |
| 263 | cluster := NewTestCluster(3) |
nothing calls this directly
no test coverage detected