MCPcopy
hub / github.com/lxc/incus / TestGetCandidateMembers

Function TestGetCandidateMembers

internal/server/db/node_test.go:308–329  ·  view source on GitHub ↗

If there are 2 online nodes, return the address of the one with the least number of instances.

(t *testing.T)

Source from the content-addressed store, hash-verified

306// If there are 2 online nodes, return the address of the one with the least
307// number of instances.
308func 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(`
317INSERT 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.

Callers

nothing calls this directly

Calls 7

NewTestClusterTxFunction · 0.92
CreateNodeMethod · 0.80
TxMethod · 0.80
GetNodesMethod · 0.80
GetCandidateMembersMethod · 0.80
ExecMethod · 0.65
LenMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…