If there are nodes, and one of them is offline, return the name of the online node, even if the offline one has more instances.
(t *testing.T)
| 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. |
| 333 | func TestGetCandidateMembers_OfflineNode(t *testing.T) { |
| 334 | tx, cleanup := db.NewTestClusterTx(t) |
| 335 | defer cleanup() |
| 336 | |
| 337 | id, err := tx.CreateNode("buzz", "1.2.3.4:666") |
| 338 | require.NoError(t, err) |
| 339 | |
| 340 | // Add an instance to the newly created node. |
| 341 | _, err = tx.Tx().Exec(` |
| 342 | INSERT INTO instances (id, node_id, name, architecture, type, project_id, description) VALUES (1, ?, 'foo', 1, 1, 1, '') |
| 343 | `, id) |
| 344 | require.NoError(t, err) |
| 345 | |
| 346 | // Mark the default node has offline. |
| 347 | err = tx.SetNodeHeartbeat("0.0.0.0", time.Now().Add(-time.Minute)) |
| 348 | require.NoError(t, err) |
| 349 | |
| 350 | allMembers, err := tx.GetNodes(context.Background()) |
| 351 | require.NoError(t, err) |
| 352 | |
| 353 | members, err := tx.GetCandidateMembers(context.Background(), allMembers, nil, "", nil, time.Duration(db.DefaultOfflineThreshold)*time.Second) |
| 354 | require.NoError(t, err) |
| 355 | require.Len(t, members, 1) |
| 356 | |
| 357 | assert.Equal(t, "buzz", members[0].Name) |
| 358 | } |
| 359 | |
| 360 | // If there are 2 online nodes, and an instance is pending on one of them, |
| 361 | // return the address of the other one number of instances. |
nothing calls this directly
no test coverage detected
searching dependent graphs…