Skip to content

Commit

Permalink
Execute gofmt -w -s . on the whole codebase to fix formatting issues
Browse files Browse the repository at this point in the history
  • Loading branch information
na-- committed Mar 31, 2023
1 parent 2824989 commit 507723e
Show file tree
Hide file tree
Showing 26 changed files with 161 additions and 127 deletions.
2 changes: 2 additions & 0 deletions js/common/bridge.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (

// if a fieldName is the key of this map exactly than the value for the given key should be used as
// the name of the field in js
//
//nolint:gochecknoglobals
var fieldNameExceptions = map[string]string{
"OCSP": "ocsp",
Expand Down Expand Up @@ -41,6 +42,7 @@ func FieldName(t reflect.Type, f reflect.StructField) string {

// if a methodName is the key of this map exactly than the value for the given key should be used as
// the name of the method in js
//
//nolint:gochecknoglobals
var methodNameExceptions = map[string]string{
"JSON": "json",
Expand Down
40 changes: 20 additions & 20 deletions js/eventloop/eventloop.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,28 +82,28 @@ func (e *EventLoop) wakeup() {
//
// A common pattern for async work is something like this:
//
// func doAsyncWork(vu modules.VU) *goja.Promise {
// enqueueCallback := vu.RegisterCallback()
// p, resolve, reject := vu.Runtime().NewPromise()
// func doAsyncWork(vu modules.VU) *goja.Promise {
// enqueueCallback := vu.RegisterCallback()
// p, resolve, reject := vu.Runtime().NewPromise()
//
// // Do the actual async work in a new independent goroutine, but make
// // sure that the Promise resolution is done on the main thread:
// go func() {
// // Also make sure to abort early if the context is cancelled, so
// // the VU is not stuck when the scenario ends or Ctrl+C is used:
// result, err := doTheActualAsyncWork(vu.Context())
// enqueueCallback(func() error {
// if err != nil {
// reject(err)
// } else {
// resolve(result)
// }
// return nil // do not abort the iteration
// })
// }()
// // Do the actual async work in a new independent goroutine, but make
// // sure that the Promise resolution is done on the main thread:
// go func() {
// // Also make sure to abort early if the context is cancelled, so
// // the VU is not stuck when the scenario ends or Ctrl+C is used:
// result, err := doTheActualAsyncWork(vu.Context())
// enqueueCallback(func() error {
// if err != nil {
// reject(err)
// } else {
// resolve(result)
// }
// return nil // do not abort the iteration
// })
// }()
//
// return p
// }
// return p
// }
//
// This ensures that the actual work happens asynchronously, while the Promise
// is immediately returned and the main thread resumes execution. It also
Expand Down
1 change: 1 addition & 0 deletions js/summary.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
)

// Copied from https://github.com/k6io/jslib.k6.io/tree/master/lib/k6-summary
//
//go:embed summary.js
var jslibSummaryCode string //nolint:gochecknoglobals

Expand Down
1 change: 0 additions & 1 deletion lib/compatibility_mode_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

43 changes: 24 additions & 19 deletions lib/execution_segment.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,13 @@ func stringToRat(s string) (*big.Rat, error) {
// quickly running an arbitrarily scaled-down version of a test.
//
// The parsing logic is that values with a colon, i.e. ':', are full segments:
// `1/2:3/4`, `0.5:0.75`, `50%:75%`, and even `2/4:75%` should be (1/2, 3/4]
//
// `1/2:3/4`, `0.5:0.75`, `50%:75%`, and even `2/4:75%` should be (1/2, 3/4]
//
// And values without a colon are the end of a first segment:
// `20%`, `0.2`, and `1/5` should be converted to (0, 1/5]
//
// `20%`, `0.2`, and `1/5` should be converted to (0, 1/5]
//
// empty values should probably be treated as "1", i.e. the whole execution
func NewExecutionSegmentFromString(toStr string) (result *ExecutionSegment, err error) {
from := zeroRat
Expand Down Expand Up @@ -210,8 +214,9 @@ func (es *ExecutionSegment) Equal(other *ExecutionSegment) bool {
// (0:1/2], then a.SubSegment(b) will return a new segment (1/2, 3/4].
//
// The basic formula for c = a.SubSegment(b) is:
// c.from = a.from + b.from * (a.to - a.from)
// c.to = c.from + (b.to - b.from) * (a.to - a.from)
//
// c.from = a.from + b.from * (a.to - a.from)
// c.to = c.from + (b.to - b.from) * (a.to - a.from)
func (es *ExecutionSegment) SubSegment(child *ExecutionSegment) *ExecutionSegment {
if child == nil {
return es // 100% sub-segment is the original segment
Expand Down Expand Up @@ -584,12 +589,12 @@ func (essw *ExecutionSegmentSequenceWrapper) ScaleInt64(segmentIndex int, value

// GetStripedOffsets returns the stripped offsets for the given segment
// the returned values are as follows in order:
// - start: the first value that is for the segment
// - offsets: a list of offsets from the previous value for the segment. This are only the offsets
// to from the start to the next start if we chunk the elements we are going to strip
// into lcd sized chunks
// - lcd: the LCD of the lengths of all segments in the sequence. This is also the number of
// elements after which the algorithm starts to loop and give the same values
// - start: the first value that is for the segment
// - offsets: a list of offsets from the previous value for the segment. This are only the offsets
// to from the start to the next start if we chunk the elements we are going to strip
// into lcd sized chunks
// - lcd: the LCD of the lengths of all segments in the sequence. This is also the number of
// elements after which the algorithm starts to loop and give the same values
func (essw *ExecutionSegmentSequenceWrapper) GetStripedOffsets(segmentIndex int) (int64, []int64, int64) {
offsets := essw.offsets[segmentIndex]
return offsets[0], offsets[1:], essw.lcd
Expand Down Expand Up @@ -670,22 +675,22 @@ func (essw *ExecutionSegmentSequenceWrapper) GetNewExecutionSegmentSequenceFromV
//
// The segmented iterators (i.e. SegmentedIndex values below) will be like this:
//
// Normal iterator: 0 1 2 3 4 5 6 7 8 9 10 11 ...
// Instance 1 (0:1/2) iterator: 0 2 4 6 8 10 ...
// Instance 2 (1/2:3/4) iterator: 1 5 9 ...
// Instance 2 (3/4:1) iterator: 3 7 11 ...
// Normal iterator: 0 1 2 3 4 5 6 7 8 9 10 11 ...
// Instance 1 (0:1/2) iterator: 0 2 4 6 8 10 ...
// Instance 2 (1/2:3/4) iterator: 1 5 9 ...
// Instance 2 (3/4:1) iterator: 3 7 11 ...
//
// See how every instance has its own uniqe non-overlapping iterator, but when
// we combine all of them, we cover every possible value in the original one.
//
// We also can use this property to scale integer numbers proportionally, as
// fairly as possible, between the instances, like this:
//
// Global int value to scale: 1 2 3 4 5 6 7 8 9 10 11 12 ...
// Calling ScaleInt64():
// - Instance 1 (0:1/2) value: 1 1 2 2 3 3 4 4 5 5 6 6 ...
// - Instance 2 (1/2:3/4) value: 0 1 1 1 1 2 2 2 2 3 3 3 ...
// - Instance 2 (3/4:1) value: 0 0 0 1 1 1 1 2 2 2 2 3 ...
// Global int value to scale: 1 2 3 4 5 6 7 8 9 10 11 12 ...
// Calling ScaleInt64():
// - Instance 1 (0:1/2) value: 1 1 2 2 3 3 4 4 5 5 6 6 ...
// - Instance 2 (1/2:3/4) value: 0 1 1 1 1 2 2 2 2 3 3 3 ...
// - Instance 2 (3/4:1) value: 0 0 0 1 1 1 1 2 2 2 2 3 ...
//
// Notice how the sum of the per-instance values is always equal to the global
// value - this is what ExecutionTuple.ScaleInt64() does. Also compare both
Expand Down
1 change: 0 additions & 1 deletion lib/execution_status_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions lib/executor/constant_arrival_rate.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@ func (car *ConstantArrivalRate) Init(ctx context.Context) error {
// time should iteration X begin) different, but keep everything else the same.
// This will allow us to implement https://github.com/k6io/k6/issues/1386
// and things like all of the TODOs below in one place only.
//
//nolint:funlen,cyclop
func (car ConstantArrivalRate) Run(parentCtx context.Context, out chan<- metrics.SampleContainer) (err error) {
gracefulStop := car.config.GetGracefulStop()
Expand Down
1 change: 1 addition & 0 deletions lib/executor/externally_controlled.go
Original file line number Diff line number Diff line change
Expand Up @@ -478,6 +478,7 @@ func (rs *externallyControlledRunState) handleConfigChange(oldCfg, newCfg Extern
// Run constantly loops through as many iterations as possible on a variable
// dynamically controlled number of VUs either for the specified duration, or
// until the test is manually stopped.
//
//nolint:funlen,gocognit
func (mex *ExternallyControlled) Run(parentCtx context.Context, out chan<- metrics.SampleContainer) (err error) {
mex.configLock.RLock()
Expand Down
22 changes: 11 additions & 11 deletions lib/executor/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,17 +127,17 @@ func getIterationRunner(
// only the regular duration.
//
// In either case, the usage of these contexts should be like this:
// - As long as the regDurationCtx isn't done, new iterations can be started.
// - After regDurationCtx is done, no new iterations should be started; every
// VU that finishes an iteration from now on can be returned to the buffer
// pool in the ExecutionState struct.
// - After maxDurationCtx is done, any VUs with iterations will be
// interrupted by the context's closing and will be returned to the buffer.
// - If you want to interrupt the execution of all VUs prematurely (e.g. there
// was an error or something like that), trigger maxDurationCancel().
// - If the whole test is aborted, the parent context will be cancelled, so
// that will also cancel these contexts, thus the "general abort" case is
// handled transparently.
// - As long as the regDurationCtx isn't done, new iterations can be started.
// - After regDurationCtx is done, no new iterations should be started; every
// VU that finishes an iteration from now on can be returned to the buffer
// pool in the ExecutionState struct.
// - After maxDurationCtx is done, any VUs with iterations will be
// interrupted by the context's closing and will be returned to the buffer.
// - If you want to interrupt the execution of all VUs prematurely (e.g. there
// was an error or something like that), trigger maxDurationCancel().
// - If the whole test is aborted, the parent context will be cancelled, so
// that will also cancel these contexts, thus the "general abort" case is
// handled transparently.
func getDurationContexts(parentCtx context.Context, regularDuration, gracefulStop time.Duration) (
startTime time.Time, maxDurationCtx, regDurationCtx context.Context, maxDurationCancel func(),
) {
Expand Down
1 change: 1 addition & 0 deletions lib/executor/per_vu_iterations.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ type PerVUIterations struct {
var _ lib.Executor = &PerVUIterations{}

// Run executes a specific number of iterations with each configured VU.
//
//nolint:funlen
func (pvi PerVUIterations) Run(parentCtx context.Context, out chan<- metrics.SampleContainer) (err error) {
numVUs := pvi.config.GetVUs(pvi.executionState.ExecutionTuple)
Expand Down
11 changes: 8 additions & 3 deletions lib/executor/ramping_arrival_rate.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,16 +183,20 @@ func (varr *RampingArrivalRate) Init(ctx context.Context) error {
// Lets look at a simple example - lets say we start with 2 events and the first stage is 5
// seconds to 2 events/s and then we have a second stage for 5 second that goes up to 3 events
// (using small numbers because ... well it is easier :D). This will look something like:
// ^
//
// ^
//
// 7|
// 6|
// 5|
// 4|
// 3| ,-+
// 2|----+-' |
// 1| | |
// +----+----+---------------------------------->
// 0s 5s 10s
//
// +----+----+---------------------------------->
// 0s 5s 10s
//
// TODO: bigger and more stages
//
// Now the question is when(where on the graph) does the first event happen? Well in this simple
Expand Down Expand Up @@ -298,6 +302,7 @@ func noNegativeSqrt(f float64) float64 {
// time should iteration X begin) different, but keep everyhing else the same.
// This will allow us to implement https://github.com/k6io/k6/issues/1386
// and things like all of the TODOs below in one place only.
//
//nolint:funlen,cyclop
func (varr RampingArrivalRate) Run(parentCtx context.Context, out chan<- metrics.SampleContainer) (err error) {
segment := varr.executionState.ExecutionTuple.Segment
Expand Down

0 comments on commit 507723e

Please sign in to comment.