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

Function TestGetCandidateMembers_OfflineNode

internal/server/db/node_test.go:333–358  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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.
333func 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(`
342INSERT 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.

Callers

nothing calls this directly

Calls 9

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

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…