Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove custom 'min' function (prior to Go v1.21) #3922

Merged
merged 2 commits into from
Aug 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 3 additions & 12 deletions cmd/tests/cmd_run_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"path/filepath"
"regexp"
"runtime"
"slices"
"strings"
"sync"
"sync/atomic"
Expand Down Expand Up @@ -1434,16 +1435,6 @@ func sum(vals []float64) (sum float64) {
return sum
}

func maxFloat64(vals []float64) float64 {
result := vals[0]
for _, val := range vals {
if result < val {
result = val
}
}
return result
}

func TestActiveVUsCount(t *testing.T) {
t.Parallel()

Expand Down Expand Up @@ -1499,8 +1490,8 @@ func TestActiveVUsCount(t *testing.T) {
jsonResults, err := fsext.ReadFile(ts.FS, "results.json")
require.NoError(t, err)
// t.Log(string(jsonResults))
assert.Equal(t, float64(10), maxFloat64(getSampleValues(t, jsonResults, "vus_max", nil)))
assert.Equal(t, float64(10), maxFloat64(getSampleValues(t, jsonResults, "vus", nil)))
assert.Equal(t, float64(10), slices.Max(getSampleValues(t, jsonResults, "vus_max", nil)))
assert.Equal(t, float64(10), slices.Max(getSampleValues(t, jsonResults, "vus", nil)))
assert.Equal(t, float64(0), sum(getSampleValues(t, jsonResults, "iterations", nil)))

logEntries := ts.LoggerHook.Drain()
Expand Down
4 changes: 2 additions & 2 deletions cmd/ui.go
Original file line number Diff line number Diff line change
Expand Up @@ -280,10 +280,10 @@ func showProgress(ctx context.Context, gs *state.GlobalState, pbs []*pb.Progress
var leftLen int64
for _, pb := range pbs {
l := pb.Left()
leftLen = lib.Max(int64(len(l)), leftLen)
leftLen = max(int64(len(l)), leftLen)
}
// Limit to maximum left text length
maxLeft := int(lib.Min(leftLen, maxLeftLength))
maxLeft := int(min(leftLen, maxLeftLength))

var progressBarsLastRenderLock sync.Mutex
var progressBarsLastRender []byte
Expand Down
4 changes: 1 addition & 3 deletions js/modules/k6/experimental/fs/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ import (
"io"
"path/filepath"
"sync/atomic"

"go.k6.io/k6/lib"
)

// file is an abstraction for interacting with files.
Expand Down Expand Up @@ -55,7 +53,7 @@ func (f *file) Read(into []byte) (n int, err error) {

// Calculate the effective new offset
targetOffset := currentOffset + int64(len(into))
newOffset := lib.Min(targetOffset, fileSize)
newOffset := min(targetOffset, fileSize)

// Read the data into the provided slice, and update
// the offset accordingly
Expand Down
19 changes: 0 additions & 19 deletions lib/util.go

This file was deleted.

52 changes: 0 additions & 52 deletions lib/util_test.go

This file was deleted.

10 changes: 1 addition & 9 deletions output/cloud/expv2/flush.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,16 +86,8 @@ func (f *metricsFlusher) flush() error {
}

func (f *metricsFlusher) flushBatches(batches []*pbcloud.MetricSet) error {
// TODO remove after go 1.21 becomes the minimum supported version - it has `min` in it
minInt := func(a, b int) int {
if a < b {
return a
}
return b
}

var (
workers = minInt(len(batches), f.batchPushConcurrency)
workers = min(len(batches), f.batchPushConcurrency)
errs = make(chan error, workers)
feed = make(chan *pbcloud.MetricSet)
finalErr error
Expand Down