Skip to content
Open
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
5 changes: 4 additions & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# v2.1.6
# v2.5.0
# Please don't remove the first line. It uses in CI to determine the golangci version
version: "2"
linters:
Expand Down Expand Up @@ -115,6 +115,9 @@ linters:
- linters:
- forbidigo
text: use of `os\.(SyscallError|Signal|Interrupt)` forbidden
- linters:
- revive
text: avoid meaningless package names
paths:
- third_party$
- builtin$
Expand Down
2 changes: 1 addition & 1 deletion cloudapi/logs.go
Original file line number Diff line number Diff line change
Expand Up @@ -244,5 +244,5 @@ func retry(s sleeper, attempts int, interval, maxDuration time.Duration, do func
return nil
}
}
return
return err
}
6 changes: 3 additions & 3 deletions cloudapi/logs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ func TestStreamLogsToLogger(t *testing.T) {
for _, e := range hook.Drain() {
lines = append(lines, e.Message)
}
return
return lines
}

generateLogline := func(key string, ts uint64, msg string) string {
Expand Down Expand Up @@ -276,7 +276,7 @@ func TestStreamLogsToLogger(t *testing.T) {
}

start = time.Unix(0, rawstart)
return
return start, err
}

var requestsCount uint64
Expand Down Expand Up @@ -355,7 +355,7 @@ func TestStreamLogsToLogger(t *testing.T) {
}

start = time.Unix(0, rawstart)
return
return start, err
}

var requestsCount uint64
Expand Down
6 changes: 3 additions & 3 deletions ext/ext.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,12 +136,12 @@ func extractModuleInfo(mod interface{}) (path, version string) {
case reflect.Func:
path = runtime.FuncForPC(reflect.ValueOf(mod).Pointer()).Name()
default:
return
return path, version
}

buildInfo, ok := debug.ReadBuildInfo()
if !ok {
return
return path, version
}

for _, dep := range buildInfo.Deps {
Expand All @@ -154,7 +154,7 @@ func extractModuleInfo(mod interface{}) (path, version string) {
}
}

return
return path, version
}

func init() {
Expand Down
2 changes: 1 addition & 1 deletion internal/cmd/tests/grpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func NewGRPC(t testing.TB) *GRPC {

addr := getFreeBindAddr(t)

lis, err := net.Listen("tcp", addr)
lis, err := (&net.ListenConfig{}).Listen(t.Context(), "tcp", addr)
if err != nil {
t.Fatalf("failed to listen: %v", err)
}
Expand Down
3 changes: 2 additions & 1 deletion internal/cmd/tests/test_state.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
"github.com/sirupsen/logrus"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

"go.k6.io/k6/cmd/state"
"go.k6.io/k6/internal/event"
"go.k6.io/k6/internal/lib/testutils"
Expand Down Expand Up @@ -128,7 +129,7 @@ func getFreeBindAddr(tb testing.TB) string {
port := atomic.AddUint64(&portRangeStart, 1)
addr := net.JoinHostPort("localhost", strconv.FormatUint(port, 10))

listener, err := net.Listen("tcp", addr)
listener, err := (&net.ListenConfig{}).Listen(tb.Context(), "tcp", addr)
if err != nil {
continue // port was busy for some reason
}
Expand Down
2 changes: 1 addition & 1 deletion internal/js/eventloop/eventloop.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ func (e *EventLoop) popAll() (queue []func() error, awaiting bool) {
e.queue = make([]func() error, 0, len(queue))
awaiting = e.registeredCallbacks != 0
e.lock.Unlock()
return
return queue, awaiting
}

func (e *EventLoop) putInfront(queue []func() error) {
Expand Down
2 changes: 1 addition & 1 deletion internal/js/modules/k6/browser/browser/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (

func panicIfFatalError(ctx context.Context, err error) {
if errors.Is(err, k6error.ErrFatal) {
k6ext.Abort(ctx, err.Error())
k6ext.Abortf(ctx, err.Error())
}
}

Expand Down
6 changes: 3 additions & 3 deletions internal/js/modules/k6/browser/browser/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,15 +113,15 @@ func (m *RootModule) initialize(vu k6modules.VU) {
)
m.remoteRegistry, err = newRemoteRegistry(initEnv.LookupEnv)
if err != nil {
k6ext.Abort(vu.Context(), "failed to create remote registry: %v", err)
k6ext.Abortf(vu.Context(), "failed to create remote registry: %v", err)
}
m.tracesMetadata, err = parseTracesMetadata(initEnv.LookupEnv)
if err != nil {
k6ext.Abort(vu.Context(), "parsing browser traces metadata: %v", err)
k6ext.Abortf(vu.Context(), "parsing browser traces metadata: %v", err)
}
m.filePersister, err = newScreenshotPersister(initEnv.LookupEnv)
if err != nil {
k6ext.Abort(vu.Context(), "failed to create file persister: %v", err)
k6ext.Abortf(vu.Context(), "failed to create file persister: %v", err)
}
if e, ok := initEnv.LookupEnv(env.K6TestRunID); ok && e != "" {
m.testRunID = e
Expand Down
4 changes: 2 additions & 2 deletions internal/js/modules/k6/browser/browser/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ func (r *browserRegistry) handleIterEvents(

if data, ok = e.Data.(k6event.IterData); !ok {
e.Done()
k6ext.Abort(vuCtx, "unexpected iteration event data format: %v", e.Data)
k6ext.Abortf(vuCtx, "unexpected iteration event data format: %v", e.Data)
// Continue so we don't block the k6 event system producer.
// Test will be aborted by k6, which will previously send the
// 'Exit' event so browser resources cleanup can be guaranteed.
Expand All @@ -306,7 +306,7 @@ func (r *browserRegistry) handleIterEvents(
b, err := r.buildFn(ctx, tracedCtx)
if err != nil {
e.Done()
k6ext.Abort(vuCtx, "error building browser on IterStart: %v", err)
k6ext.Abortf(vuCtx, "error building browser on IterStart: %v", err)
// Continue so we don't block the k6 event system producer.
// Test will be aborted by k6, which will previously send the
// 'Exit' event so browser resources cleanup can be guaranteed.
Expand Down
2 changes: 1 addition & 1 deletion internal/js/modules/k6/browser/common/browser.go
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ func (b *Browser) initEvents() error {
if ev, ok := event.data.(*target.EventAttachedToTarget); ok {
b.logger.Debugf("Browser:initEvents:onAttachedToTarget", "sid:%v tid:%v", ev.SessionID, ev.TargetInfo.TargetID)
if err := b.onAttachedToTarget(ev); err != nil {
k6ext.Panic(b.vuCtx, "browser is attaching to target: %w", err)
k6ext.Panicf(b.vuCtx, "browser is attaching to target: %w", err)
}
} else if ev, ok := event.data.(*target.EventDetachedFromTarget); ok {
b.logger.Debugf("Browser:initEvents:onDetachedFromTarget", "sid:%v", ev.SessionID)
Expand Down
2 changes: 1 addition & 1 deletion internal/js/modules/k6/browser/common/connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -658,5 +658,5 @@ func (c *Connection) isClosing() (s bool) {
default:
}

return
return s
}
12 changes: 6 additions & 6 deletions internal/js/modules/k6/browser/common/frame_session.go
Original file line number Diff line number Diff line change
Expand Up @@ -682,7 +682,7 @@ func (fs *FrameSession) onExecutionContextCreated(event *cdpruntime.EventExecuti
Type string `json:"type"`
}
if err := json.Unmarshal(auxData, &i); err != nil {
k6ext.Panic(fs.ctx, "unmarshaling executionContextCreated event JSON: %w", err)
k6ext.Panicf(fs.ctx, "unmarshaling executionContextCreated event JSON: %w", err)
}

frame, ok := fs.manager.getFrameByID(i.FrameID)
Expand Down Expand Up @@ -767,7 +767,7 @@ func (fs *FrameSession) onFrameDetached(frameID cdp.FrameID, reason cdppage.Fram
fs.session.ID(), fs.targetID, frameID, reason)

if err := fs.manager.frameDetached(frameID, reason); err != nil {
k6ext.Panic(fs.ctx, "handling frameDetached event: %w", err)
k6ext.Panicf(fs.ctx, "handling frameDetached event: %w", err)
}
}

Expand All @@ -780,7 +780,7 @@ func (fs *FrameSession) onFrameNavigated(frame *cdp.Frame, initial bool) {
frame.ID, frame.ParentID, frame.LoaderID.String(),
frame.Name, frame.URL+frame.URLFragment, initial)
if err != nil {
k6ext.Panic(fs.ctx, "handling frameNavigated event to %q: %w",
k6ext.Panicf(fs.ctx, "handling frameNavigated event to %q: %w",
frame.URL+frame.URLFragment, err)
}

Expand Down Expand Up @@ -855,7 +855,7 @@ func (fs *FrameSession) onFrameRequestedNavigation(event *cdppage.EventFrameRequ
if event.Disposition == "currentTab" {
err := fs.manager.frameRequestedNavigation(event.FrameID, event.URL, "")
if err != nil {
k6ext.Panic(fs.ctx, "handling frameRequestedNavigation event to %q: %w", event.URL, err)
k6ext.Panicf(fs.ctx, "handling frameRequestedNavigation event to %q: %w", event.URL, err)
}
}
}
Expand Down Expand Up @@ -995,7 +995,7 @@ func (fs *FrameSession) onAttachedToTarget(event *target.EventAttachedToTarget)
return // ignore
}
reason = "fatal"
k6ext.Panic(fs.ctx, "attaching %v: %w", ti.Type, err)
k6ext.Panicf(fs.ctx, "attaching %v: %w", ti.Type, err)
}
}

Expand Down Expand Up @@ -1064,7 +1064,7 @@ func (fs *FrameSession) onTargetCrashed() {
// TODO:?
s, ok := fs.session.(*Session)
if !ok {
k6ext.Panic(fs.ctx, "unexpected type %T", fs.session)
k6ext.Panicf(fs.ctx, "unexpected type %T", fs.session)
}
s.markAsCrashed()
}
Expand Down
2 changes: 1 addition & 1 deletion internal/js/modules/k6/browser/common/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ func createWaitForEventPredicateHandler(
//nolint:unused
func panicOrSlowMo(ctx context.Context, err error) {
if err != nil {
k6ext.Panic(ctx, "%w", err)
k6ext.Panicf(ctx, "%w", err)
}
applySlowMo(ctx)
}
Expand Down
4 changes: 2 additions & 2 deletions internal/js/modules/k6/browser/common/network_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -1041,14 +1041,14 @@ func (m *NetworkManager) ThrottleNetwork(networkProfile NetworkProfile) error {
func (m *NetworkManager) SetUserAgent(userAgent string) {
action := emulation.SetUserAgentOverride(userAgent)
if err := action.Do(cdp.WithExecutor(m.ctx, m.session)); err != nil {
k6ext.Panic(m.ctx, "setting user agent: %w", err)
k6ext.Panicf(m.ctx, "setting user agent: %w", err)
}
}

// SetCacheEnabled toggles cache on/off.
func (m *NetworkManager) SetCacheEnabled(enabled bool) {
m.userCacheDisabled = !enabled
if err := m.updateProtocolCacheDisabled(); err != nil {
k6ext.Panic(m.ctx, "%v", err)
k6ext.Panicf(m.ctx, "%v", err)
}
}
8 changes: 4 additions & 4 deletions internal/js/modules/k6/browser/k6ext/panic.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,23 +14,23 @@ import (
k6common "go.k6.io/k6/js/common"
)

// Abort will shutdown the whole test run. This should
// Abortf will shutdown the whole test run. This should
// only be used from the sobek mapping layer. It is only
// to be used when an error will occur in all iterations,
// so it's permanent.
func Abort(ctx context.Context, format string, a ...any) {
func Abortf(ctx context.Context, format string, a ...any) {
failFunc := func(rt *sobek.Runtime, a ...any) {
reason := fmt.Errorf(format, a...).Error()
rt.Interrupt(&errext.InterruptError{Reason: reason})
}
sharedPanic(ctx, failFunc, a...)
}

// Panic will cause a panic with the given error which will stop
// Panicf will cause a panic with the given error which will stop
// the current iteration. Before panicking, it will find the
// browser process from the context and kill it if it still exists.
// TODO: test.
func Panic(ctx context.Context, format string, a ...any) {
func Panicf(ctx context.Context, format string, a ...any) {
failFunc := func(rt *sobek.Runtime, a ...any) {
k6common.Throw(rt, fmt.Errorf(format, a...))
}
Expand Down
2 changes: 1 addition & 1 deletion internal/js/modules/k6/browser/tests/browser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ func TestMultiBrowserPanic(t *testing.T) {

func() {
defer func() { _ = recover() }()
k6ext.Panic(b1.ctx, "forcing a panic")
k6ext.Panicf(b1.ctx, "forcing a panic")
}()
})

Expand Down
2 changes: 1 addition & 1 deletion internal/js/runner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -865,7 +865,7 @@ func getTestServerWithCertificate(t *testing.T, certPem, key []byte) *httptest.S
},
ForceAttemptHTTP2: s.EnableHTTP2,
}
s.Listener, err = net.Listen("tcp", "")
s.Listener, err = (&net.ListenConfig{}).Listen(context.Background(), "tcp", "")
require.NoError(t, err)
s.Listener = tls.NewListener(s.Listener, s.TLS)
s.URL = "https://" + s.Listener.Addr().String()
Expand Down
2 changes: 1 addition & 1 deletion internal/lib/summary/summary.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ func ValidateMode(val string) (m Mode, err error) {
if err = m.UnmarshalText([]byte(val)); err != nil {
return 0, err
}
return
return m, err
}

// Summary is the data structure that holds all the summary data (thresholds, metrics, checks, etc)
Expand Down
2 changes: 1 addition & 1 deletion internal/lib/testutils/minirunner/minirunner.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ func (r *MiniRunner) Setup(ctx context.Context, out chan<- metrics.SampleContain
if fn := r.SetupFn; fn != nil {
r.SetupData, err = fn(ctx, out)
}
return
return err
}

// GetSetupData returns json representation of the setup data if setup() is
Expand Down
2 changes: 1 addition & 1 deletion internal/output/influxdb/output_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ func testOutputCycle(t testing.TB, handler http.HandlerFunc, body func(testing.T
MaxHeaderBytes: 1 << 20,
ReadHeaderTimeout: time.Second,
}
l, err := net.Listen("tcp", "127.0.0.1:0")
l, err := (&net.ListenConfig{}).Listen(context.Background(), "tcp", "127.0.0.1:0")
require.NoError(t, err)
defer func() {
_ = l.Close()
Expand Down
9 changes: 5 additions & 4 deletions internal/output/opentelemetry/output_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,15 @@ import (

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"go.k6.io/k6/internal/lib/testutils"
"go.k6.io/k6/metrics"
"go.k6.io/k6/output"
collectormetrics "go.opentelemetry.io/proto/otlp/collector/metrics/v1"
commonpb "go.opentelemetry.io/proto/otlp/common/v1"
metricpb "go.opentelemetry.io/proto/otlp/metrics/v1"
"google.golang.org/grpc"
"google.golang.org/protobuf/proto"

"go.k6.io/k6/internal/lib/testutils"
"go.k6.io/k6/metrics"
"go.k6.io/k6/output"
)

type MetricsServer interface {
Expand Down Expand Up @@ -82,7 +83,7 @@ type grpcMetricsServer struct {
}

func newGRPCServer() (*grpcMetricsServer, error) {
listener, err := net.Listen("tcp", "localhost:0")
listener, err := (&net.ListenConfig{}).Listen(context.Background(), "tcp", "localhost:0")
if err != nil {
return nil, fmt.Errorf("failed to create listener: %w", err)
}
Expand Down
2 changes: 1 addition & 1 deletion internal/output/summary/data.go
Original file line number Diff line number Diff line change
Expand Up @@ -441,7 +441,7 @@ func extractPercentileThresholdSource(source string) (agg string, percentile flo

agg = "p(" + matches[1] + ")"
isPercentile = true
return
return agg, percentile, isPercentile
}

return "", 0, false
Expand Down
2 changes: 1 addition & 1 deletion js/modules/k6/http/request_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2373,7 +2373,7 @@ func GetTestServerWithCertificate(t *testing.T, certPem, key []byte, suitesIDs .
ResponseHeaderTimeout: time.Second,
IdleConnTimeout: time.Second,
}
s.Listener, err = net.Listen("tcp", "")
s.Listener, err = (&net.ListenConfig{}).Listen(context.Background(), "tcp", "")
require.NoError(t, err)
s.Listener = tls.NewListener(s.Listener, s.TLS)
return s, client
Expand Down
2 changes: 1 addition & 1 deletion lib/executor/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func sumStagesDuration(stages []Stage) (result time.Duration) {
for _, s := range stages {
result += s.Duration.TimeDuration()
}
return
return result
}

func getStagesUnscaledMaxTarget(unscaledStartValue int64, stages []Stage) int64 {
Expand Down
4 changes: 2 additions & 2 deletions lib/netext/httpext/error_codes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ func testMapOfErrorCodes(t *testing.T, testTable map[errCode]error) {
func TestConnReset(t *testing.T) {
t.Parallel()
// based on https://gist.github.com/jpittis/4357d817dc425ae99fbf719828ab1800
ln, err := net.Listen("tcp", "localhost:0")
ln, err := (&net.ListenConfig{}).Listen(context.Background(), "tcp", "localhost:0")
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -261,7 +261,7 @@ func TestX509UnknownAuthorityError(t *testing.T) {
func TestDefaultTLSError(t *testing.T) {
t.Parallel()

l, err := net.Listen("tcp", "127.0.0.1:0")
l, err := (&net.ListenConfig{}).Listen(context.Background(), "tcp", "127.0.0.1:0")
require.NoError(t, err)
go func() {
conn, err := l.Accept()
Expand Down
Loading
Loading