test: ensure cpuset cgroup is setup before fingerprinting (#17428)

This PR fixes a racey test where we need to ensure the cpuset cgroup
is setup before trying to fingerprint it.
This commit is contained in:
Seth Hoenig 2023-06-05 14:15:00 -05:00 committed by GitHub
parent 700168e136
commit d1d4d22f8e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 10 additions and 1 deletions

View File

@ -11,6 +11,7 @@ import (
"github.com/hashicorp/nomad/ci"
"github.com/hashicorp/nomad/client/config"
"github.com/hashicorp/nomad/client/lib/cgutil"
"github.com/hashicorp/nomad/helper/testlog"
"github.com/hashicorp/nomad/nomad/structs"
"github.com/shoenig/test/must"
@ -19,12 +20,20 @@ import (
func TestCPUFingerprint_Classic(t *testing.T) {
ci.Parallel(t)
f := NewCPUFingerprint(testlog.HCLogger(t))
logger := testlog.HCLogger(t)
// create cpuset manager so we can ensure cgroup tree is correct
mgr := cgutil.CreateCPUSetManager("", nil, logger)
mgr.Init()
// create the fingerprinter
f := NewCPUFingerprint(logger)
node := &structs.Node{Attributes: make(map[string]string)}
request := &FingerprintRequest{Config: &config.Config{}, Node: node}
var response FingerprintResponse
// run the fingerprinter
err := f.Fingerprint(request, &response)
must.NoError(t, err)