If there are 2 online nodes, return the address of the one with the least number of instances.
(t *testing.T)
| 306 | // If there are 2 online nodes, return the address of the one with the least |
| 307 | // number of instances. |
| 308 | func TestGetCandidateMembers(t *testing.T) { |
| 309 | tx, cleanup := db.NewTestClusterTx(t) |
| 310 | defer cleanup() |
| 311 | |
| 312 | _, err := tx.CreateNode("buzz", "1.2.3.4:666") |
| 313 | require.NoError(t, err) |
| 314 | |
| 315 | // Add an instance to the default node (ID 1) |
| 316 | _, err = tx.Tx().Exec(` |
| 317 | INSERT INTO instances (id, node_id, name, architecture, type, project_id, description) VALUES (1, 1, 'foo', 1, 1, 1, '') |
| 318 | `) |
| 319 | require.NoError(t, err) |
| 320 | |
| 321 | allMembers, err := tx.GetNodes(context.Background()) |
| 322 | require.NoError(t, err) |
| 323 | |
| 324 | members, err := tx.GetCandidateMembers(context.Background(), allMembers, nil, "", nil, time.Duration(db.DefaultOfflineThreshold)*time.Second) |
| 325 | require.NoError(t, err) |
| 326 | require.Len(t, members, 2) |
| 327 | |
| 328 | assert.Equal(t, "buzz", members[0].Name) |
| 329 | } |
| 330 | |
| 331 | // If there are nodes, and one of them is offline, return the name of the |
| 332 | // online node, even if the offline one has more instances. |
nothing calls this directly
no test coverage detected
searching dependent graphs…