Skip to content

Commit 0ddec20

Browse files
authored
TestValidateLabels: run finalChecks from the cleanup (#12354)
Instead of doing the unnecessary atomic logic, we can just register a cleanup function: that runs after all subtests are finished. But the main reason why I'm changing this is because the test that should fail is the outer one, but instead with the atomic approach a random subtest fails every time, depending on their order of the execution. Signed-off-by: Oleg Zaytsev <mail@olegzaytsev.com>
1 parent cd2d157 commit 0ddec20

File tree

1 file changed

+2
-9
lines changed

1 file changed

+2
-9
lines changed

pkg/distributor/validate_test.go

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ import (
2727
"github.com/prometheus/common/model"
2828
"github.com/stretchr/testify/assert"
2929
"github.com/stretchr/testify/require"
30-
"go.uber.org/atomic"
3130
grpcstatus "google.golang.org/grpc/status"
3231
golangproto "google.golang.org/protobuf/proto"
3332

@@ -447,8 +446,8 @@ func TestValidateLabels(t *testing.T) {
447446
d.sampleValidationMetrics.deleteUserMetrics(utf8UserID)
448447
}
449448

450-
var inFlightSubsets atomic.Int64
451-
inFlightSubsets.Store(int64(len(testCases) * len(validationSchemes)))
449+
// Run final checks after all subtests are done.
450+
t.Cleanup(func() { finalChecks(t) })
452451

453452
for _, c := range testCases {
454453
t.Run(c.name, func(t *testing.T) {
@@ -457,12 +456,6 @@ func TestValidateLabels(t *testing.T) {
457456
t.Run(scheme.String(), func(t *testing.T) {
458457
t.Parallel()
459458

460-
defer func() {
461-
if inFlightSubsets.Add(-1) == 0 {
462-
finalChecks(t)
463-
}
464-
}()
465-
466459
var userID string
467460
switch scheme {
468461
case model.LegacyValidation:

0 commit comments

Comments
 (0)