Fix data race in CVE tests (#48070)

Fixes: https://github.com/fleetdm/fleet/actions/runs/28003942578.

New run: https://github.com/fleetdm/fleet/actions/runs/28026451929.

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

## Summary by CodeRabbit

* **Tests**
  * Improved test fixture logic for more reliable test execution.

**Note:** This release contains internal testing improvements with no
end-user-facing changes.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->
This commit is contained in:
Lucas Manuel Rodriguez
2026-06-24 09:49:50 -03:00
committed by GitHub
parent 05f0c5e628
commit 705f4db3a3
@@ -1,7 +1,7 @@
package mysql
import (
"encoding/binary"
"crypto/sha256"
"testing"
"github.com/fleetdm/fleet/v4/server/chart/api"
@@ -11,9 +11,6 @@ import (
"github.com/stretchr/testify/require"
)
// swCounter feeds unique software checksums (binary(16) UNIQUE NOT NULL).
var swCounter uint64
// seedSoftware inserts a `software` row and a linking `software_cve` row, so a
// CVE is attributed to software of the given name+source. Returns nothing — the
// resolver/collector queries match on name/source, not id.
@@ -21,9 +18,10 @@ func seedSoftware(t *testing.T, tdb *testutils.TestDB, name, source, cve string)
t.Helper()
ctx := t.Context()
swCounter++
checksum := make([]byte, 16)
binary.BigEndian.PutUint64(checksum[8:], swCounter)
// checksum is binary(16) UNIQUE NOT NULL; derive it from the row's own
// identifying inputs so each seeded row is unique.
sum := sha256.Sum256([]byte(name + "\x00" + source + "\x00" + cve))
checksum := sum[:16]
res, err := tdb.DB.ExecContext(ctx,
`INSERT INTO software (name, version, source, checksum) VALUES (?, '1.0', ?, ?)`,