diff --git a/api/http/handler/endpoints/filter_test.go b/api/http/handler/endpoints/filter_test.go index 794bf413e..1e483bee8 100644 --- a/api/http/handler/endpoints/filter_test.go +++ b/api/http/handler/endpoints/filter_test.go @@ -189,9 +189,7 @@ func BenchmarkFilterEndpointsBySearchCriteria_PartialMatch(b *testing.B) { searchString := "edge-group" - b.ResetTimer() - - for range b.N { + for b.Loop() { e := filterEndpointsBySearchCriteria(endpoints, endpointGroups, edgeGroups, tagsMap, searchString) if len(e) != n { b.FailNow() @@ -237,13 +235,9 @@ func BenchmarkFilterEndpointsBySearchCriteria_FullMatch(b *testing.B) { searchString := "edge-group" - b.ResetTimer() - - for range b.N { + for b.Loop() { e := filterEndpointsBySearchCriteria(endpoints, endpointGroups, edgeGroups, tagsMap, searchString) - if len(e) != n { - b.FailNow() - } + require.Len(b, e, n) } } diff --git a/api/slicesx/filter_test.go b/api/slicesx/filter_test.go index 36f97fa10..febe4aa11 100644 --- a/api/slicesx/filter_test.go +++ b/api/slicesx/filter_test.go @@ -4,6 +4,8 @@ import ( "testing" "github.com/portainer/portainer/api/slicesx" + + "github.com/stretchr/testify/require" ) func Test_Filter(t *testing.T) { @@ -60,12 +62,9 @@ func Benchmark_Filter(b *testing.B) { source[i] = i } - b.ResetTimer() - for range b.N { + for b.Loop() { e := slicesx.Filter(source, func(x int) bool { return x%2 == 0 }) - if len(e) != n/2 { - b.FailNow() - } + require.Len(b, e, n/2) } } @@ -89,8 +88,6 @@ func Benchmark_FilterInPlace(b *testing.B) { b.ResetTimer() for i := range b.N { e := slicesx.FilterInPlace(copies[i], func(x int) bool { return x%2 == 0 }) - if len(e) != n/2 { - b.FailNow() - } + require.Len(b, e, n/2) } }