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

New executors #1007

Merged
merged 387 commits into from
Jul 6, 2020
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
Show all changes
387 commits
Select commit Hold shift + click to select a range
0b14828
Add enumer generation for ExecutionStatus
na-- Mar 22, 2020
298cf6b
Improve setup() and teardown() errors
na-- Mar 22, 2020
94c73a9
Make TestVariableLoopingVUsRun more deterministic
Mar 23, 2020
277e31b
Make TestVariableLoopingVUsRampDownNoWobble more deterministic
Mar 24, 2020
8841d3a
Simplify TestVariableLoopingVUsRampDownNoWobble
Mar 25, 2020
6507287
Merge pull request #1373 from loadimpact/fix/1357-flaky-tests
Mar 26, 2020
355ac25
Add test for ExecutionSegment.Scale consistency
Mar 26, 2020
0a2bc9c
Replace random ExecutionSegmentSequence generation, log random seed
Mar 26, 2020
d2af11c
Add responsive progress bars
Jan 17, 2020
b1dfe9c
Make UI mode configurable via CLI/env
Jan 23, 2020
242d955
Refactor terminal resize handling, simplify?
Mar 5, 2020
4ea5cd2
Fix scrollback when rendering progress bars with limited window width
Mar 5, 2020
ce07a70
Bring back PersistentText for avoiding stdout flicker
Mar 9, 2020
ff5eab2
Remove ui-mode option
Mar 27, 2020
17c9255
More compact updateTermWidth init
Mar 27, 2020
b14db8e
Merge pull request #1374 from loadimpact/test/1007-1296-segment-scale
Mar 30, 2020
1affab2
WIP Implement GetStripedOffsets
mstoykov Jan 30, 2020
cac2e09
two more test cases
mstoykov Jan 30, 2020
c7133d0
Use sort.SliceStable and copy ExecutionSegmentSequence
mstoykov Feb 3, 2020
cee0602
Add benchmarks
mstoykov Feb 3, 2020
ce94b52
Precalculate the numerator change
mstoykov Feb 3, 2020
b45e60b
Return correct offsets and return the LCD as well
mstoykov Feb 4, 2020
72c7023
Preemptivly break the loop if we know we have enough offsets
mstoykov Feb 4, 2020
6bdc4c9
Optimize the calculation of LCD as na-- proposed
mstoykov Feb 4, 2020
32fdd3d
Don't use rat.Cmp in order to save a lot memory and CPU
mstoykov Feb 4, 2020
91bb4ad
Sort by the numerator array
mstoykov Feb 4, 2020
037db77
Refactor the GetStrippedOffsets
mstoykov Feb 20, 2020
56248a7
Add ExecutionSegmentSequence cli flag
mstoykov Feb 17, 2020
08aacad
Use GetStrippedOffsets in constant-arrival-rate
mstoykov Feb 20, 2020
f219a1b
Considerable speedup of strippedOffsetFor by using less big.Rat
mstoykov Feb 21, 2020
cdf8ead
Rewrite lcd calculation to not use big.Rat as well
mstoykov Feb 21, 2020
005b855
Refactor and use the striping algorithm
mstoykov Mar 4, 2020
886859a
Use single select for rendering progress bars
Mar 30, 2020
363ed9c
Remove redundant logging in non-interactive mode
Mar 30, 2020
1d34063
Silence warning retrieving terminal size in non-interactive mode
Mar 30, 2020
dc46c03
Merge pull request #1332 from loadimpact/feat/1007-1279-responsive-pr…
Mar 30, 2020
73e6f5b
refactor some panics away
mstoykov Mar 31, 2020
67e3738
more errors
mstoykov Mar 31, 2020
8cd6f5f
Add test and benchmarks for the new ScaleInt64
mstoykov Mar 31, 2020
6a6cb41
Move precalculation ExecutionTuple in ConstantArrivalRate Init
mstoykov Mar 31, 2020
06a231e
Optimize case with only 1(full)segment
mstoykov Apr 1, 2020
c2f3163
Add/remove TODOs
mstoykov Apr 1, 2020
4af3174
typo fix
mstoykov Apr 1, 2020
6758233
Merge pull request #1323 from loadimpact/GetStripedOffsetsImplementation
mstoykov Apr 1, 2020
22e8ab0
fix golangci issues
mstoykov Apr 1, 2020
4f355f6
Refactor the Engine to process metrics independently from the test Run
na-- Apr 9, 2020
05f5408
Fix a racy test
na-- Apr 9, 2020
de645da
Fix more data races in tests
na-- Apr 9, 2020
f2ca5b0
Address code review comments
na-- Apr 14, 2020
85d8826
Add a test that ensures teardown() is ran even on aborted test runs
na-- Apr 14, 2020
3f95a23
Fix typos and wrong comments
na-- Apr 14, 2020
a8d1085
Fix VariableArrivalRate not working well (#1285)
mstoykov Apr 14, 2020
43f65ba
Merge pull request #1390 from loadimpact/engine-refactor
na-- Apr 14, 2020
1840d08
Fix typos
Mar 11, 2020
20b69f3
Refactor VU context handling, introduce VU activation
Mar 16, 2020
03ddf43
Refactor per-vu-iterations executor for new VU activation
Mar 16, 2020
5b48445
Refactor variable-looping-vus executor for new VU activation
Mar 16, 2020
c529e1e
Refactor shared-iterations executor for new VU activation
Mar 16, 2020
25c8ee9
Refactor constant-looping-vus executor for new VU activation
Mar 16, 2020
2a2b4b6
Refactor externally-controlled executor for new VU activation
Mar 16, 2020
721295a
Refactor constant-arrival-rate executor for new VU activation
Mar 16, 2020
f5968ae
Refactor variable-arrival-rate executor for new VU activation
Mar 17, 2020
6b88d93
Fix tests
Mar 17, 2020
b963308
Defer cancel all RunContexts in tests to release deactivation goroutines
Apr 7, 2020
2e1ef94
Use a separate ActiveVU struct
Mar 31, 2020
8fb23c3
Synchronize ActiveVU.RunOnce calls
Apr 1, 2020
5ab0d34
Fix active VU tracking in variable-looping-vus
Apr 3, 2020
e66f7e6
Handle VU ID counter in tests with ExecutionState
Apr 7, 2020
476ccca
Synchronize VU deactivation with executors
Apr 14, 2020
d6f5dd0
CI updates
na-- Apr 16, 2020
6ee9e3e
Fix a minor bug
na-- Apr 16, 2020
b3b2a6e
Unexport runMutex, move to ActiveVU
Apr 16, 2020
eb13303
Fix constant-arrival-rate executor hanging
na-- Apr 23, 2020
d24094c
Merge branch 'master' into feat/merge-master
Apr 24, 2020
d01e2c1
Change defer order in variable-arrival-rate executor
Apr 24, 2020
aac9d81
Bring back context cancelled TODO
Apr 24, 2020
a8ac0e5
Skip TestCDNJS
Apr 24, 2020
a52c502
Appease the godot linter
Apr 24, 2020
b0ed4a0
Merge pull request #1411 from loadimpact/feat/merge-master
Apr 24, 2020
5762401
Merge branch 'new-schedulers' into fix/1007-1283-context-cancelled
Apr 27, 2020
91bb3fb
Move runMutex to js.VU
Apr 27, 2020
82443a3
Fix lint CI step
Apr 27, 2020
05aad3a
Merge branch 'master' into feat/merge-master
Apr 27, 2020
27e4f0e
Silence nestif linter
Apr 27, 2020
248139b
Merge pull request #1416 from loadimpact/feat/merge-master
Apr 28, 2020
af18a3a
use ExecutionTuple
mstoykov Apr 10, 2020
4c59d5c
Add test with execution segmeng 0:1/3
mstoykov Apr 10, 2020
721a47e
Fix not adding steps with the same amount of VUs
mstoykov Apr 10, 2020
44512c7
Simplify and probably stabilize the calculation of the steps
mstoykov Apr 10, 2020
7402ee0
drop unneded variable
mstoykov Apr 10, 2020
e4607a1
Add one test with executionTuples for looping vus
mstoykov Apr 10, 2020
42f0475
delete preveScaledVUs and 'optimize' addStep ;)
mstoykov Apr 13, 2020
71c088f
add benchmark
mstoykov Apr 14, 2020
96e503f
Rewrite the varriable looping vus to fix a bug and speed it up
mstoykov Apr 14, 2020
89d5b73
Rename variable looping vus benchmark
mstoykov Apr 15, 2020
1bce1fe
Add a bunch of corner case tests for variable looping vus
mstoykov Apr 15, 2020
b75355c
Varriable->Variable
mstoykov Apr 15, 2020
8faff96
Fix going back if the offsets are different
mstoykov Apr 16, 2020
eea43fc
don't use switch use ifs
mstoykov Apr 16, 2020
35d4a5e
Refactor getRawExecutionSteps to be more logical
mstoykov Apr 23, 2020
d0a8ac5
Optimize getRawExecutionSteps by preallocating
mstoykov Apr 23, 2020
df30a71
fix TestVariableLoopingVUsRampDownNoWobble
mstoykov Apr 23, 2020
c60f01e
Don't stop VUs right away when stepping down but instead on the "next…
mstoykov Apr 24, 2020
70275a0
drop two ifs that are no longer needed
mstoykov Apr 24, 2020
964b477
rename local and global to scaled and unscaled
mstoykov Apr 24, 2020
37492ac
misc changes and comment fixes/additions
mstoykov Apr 24, 2020
c03b5e0
Steal some documentation and implementation ideas from the more reada…
mstoykov Apr 25, 2020
fb145c2
Add a randomized test for the variable-looping-vus requirements (#1413)
na-- Apr 27, 2020
6e86861
Fix wrongly preallocating the offsetsCache by 1 smaller
mstoykov Apr 25, 2020
edb8239
Merge pull request #1392 from loadimpact/varriableLoopingVUsStepping
mstoykov Apr 28, 2020
ad190b2
Fix TestSumRandomSegmentSequenceMatchesNoSegment
na-- Apr 28, 2020
5e7457b
Fix checking the wrong error when initing collectors
mstoykov Apr 28, 2020
79e1438
GetNewExecutionTupleBasedOnValue should return the same ExecutionTup……
mstoykov Apr 29, 2020
4892443
Properly synchronize VU deactivation and fix some tests (#1424)
na-- Apr 29, 2020
684520e
Merge branch 'new-schedulers' into fix/1007-1283-context-cancelled
Apr 29, 2020
d2a6f8a
Ignore funlen linter for SharedIterations.Run
Apr 29, 2020
62b519e
Fix TestVariableLoopingVUsRampDownNoWobble
Apr 29, 2020
f7cf5a6
Fix TestVURunInterrupt by creating the context just before it's used
mstoykov Apr 30, 2020
30bd863
Add VU deactivation synchronization to MiniRunner
Apr 30, 2020
a644c13
Use the striping algorithm for shared iterations
mstoykov Apr 28, 2020
7dcbfe1
Merge pull request #1368 from loadimpact/fix/1007-1283-context-cancelled
Apr 30, 2020
e693715
Add support for non-default function execution
Apr 17, 2020
4913ad0
Add support for executor-specific env vars
Apr 17, 2020
71a7180
Add support for executor-specific tags
Apr 21, 2020
702f80d
Ignore funlen linter for PerVUIterations.Run
Apr 30, 2020
f7bc0fa
Move script function names to lib/consts package
May 4, 2020
a185924
Validate executor config earlier
May 4, 2020
f7e0214
Use helper function for VUActivationParams, simplify by passing BaseC…
May 4, 2020
1eafd11
Refactor exec fallback
May 6, 2020
d90078d
Check exports with lambda instead of passing object
May 7, 2020
ae5ef34
Fix custom exec tags not leaking between executors
May 11, 2020
60c3c09
Revert moving executor init before VU init
May 11, 2020
25a26ab
Get new VUActivationParams instance per VU in some executors
May 11, 2020
80bff4d
Add custom executor tags to WebSocket metrics
May 11, 2020
06aa32d
Add custom executor tags to checks and group metrics
May 11, 2020
d25c71a
Remove superfluous use of fmt.Sprintf
May 11, 2020
8c5d8df
Define httpbin.local host in NoCrossover test
May 11, 2020
28032b6
Cleanup NoCrossover test a bit
May 11, 2020
ba076f6
Revert "Get new VUActivationParams instance per VU in some executors"
May 12, 2020
4cf716c
Merge RunTags into state.Tags and reuse that everywhere
May 12, 2020
438b422
Move newManualVUHandle function to EC RunState
May 12, 2020
56c0a89
Minor simplification of VU activation in vuHandle
May 12, 2020
60b2ffe
Change defer order in VLV Run
May 12, 2020
62b9c0b
Limit parallel VU initialization by GOMAXPROCS not CPU count
mstoykov May 13, 2020
0f665e1
Refactor ExecutionSegment sequences, wrappers and tuples
na-- May 12, 2020
e09562d
Resolve PR comments
na-- May 13, 2020
a44509d
Fix a bunch of minor issues and repetitions in #1428
na-- May 18, 2020
e1a5c0a
Fix __ENV polution
na-- May 18, 2020
b2b8648
Tweak NoCrossover test to better cover VU reuse scenarios
May 18, 2020
270fd91
Merge pull request #1428 from loadimpact/feat/1007-1300-env-tags-exec…
May 18, 2020
d1aeda5
Prevent panics from multiple calls to stop the engine
na-- May 20, 2020
2180b19
doc: add copyright
thinkerou May 19, 2020
6aadc03
dry getSimpleRunner the same way as getSimpleBundle
mstoykov Apr 30, 2020
252319a
optimize js package test by using compatibility mode base by default
mstoykov Apr 30, 2020
923f886
Introduce RunES6String and replace RunString to not support ES6
mstoykov Apr 30, 2020
6e4ea20
Fix a broken test
na-- May 21, 2020
473f934
Update the linter and fix linter issues
na-- May 21, 2020
e0ddf5d
Try to fix docker builds...
na-- May 21, 2020
cb8c731
Remove an unnecesary else statement (#1461)
thinkerou May 22, 2020
d3a1546
Fix metrics processing after test run (#1460)
na-- May 22, 2020
366a008
Bump version in preparation for the v0.27.0 release
na-- May 26, 2020
dd88859
Avoid overwriting options when grabbing exports from archive
May 26, 2020
91b8023
Format import statements (#1464)
thinkerou May 27, 2020
bf8a28c
Merge branch 'master' into feat/merge-master
May 28, 2020
83d0fcf
Merge pull request #1472 from loadimpact/feat/merge-master
May 28, 2020
c1687e0
Make certain that even sneakily open can't be used outside the init c…
mstoykov May 29, 2020
33d65e9
Dont reset startTime, as it can be racy and it wouldn't really matter
mstoykov Jun 1, 2020
0e5e354
Fix potential data races in Engine tests
na-- Jun 2, 2020
7e636c8
Fix another data race...
na-- Jun 2, 2020
5974049
refactor TestIntegrationConvertCmd to be more stable (#1484)
mstoykov Jun 4, 2020
bceeb6a
Prevent a cloud test from blocking and make it less likely it happens
mstoykov Jun 4, 2020
24b0671
Increase TestEmittedMetricsWhenScalingDown timeout a bit
mstoykov Jun 4, 2020
61cd643
increase timeout and better reporting for TestExecutionSchedulerRunCu…
mstoykov Jun 4, 2020
ac4ab4e
Increase setup/teardown timeouts in some failing tests
mstoykov Jun 3, 2020
830ebf6
Merge pull request #1486 from loadimpact/fixRacyTests
mstoykov Jun 4, 2020
96cd417
Make TestExecutionSchedulerRunCustomConfigNoCrossover more stable
mstoykov Jun 5, 2020
1f2528c
Make TestConstantLoopingVUsRun more stable
mstoykov Jun 5, 2020
e798653
Make TestConstantArrivalRateRunCorrectTiming faster and stabler
mstoykov Jun 8, 2020
6ee1625
Prevent lock in cloud tests
mstoykov Jun 8, 2020
ae18141
Merge pull request #1491 from loadimpact/fixRacyTests2
mstoykov Jun 9, 2020
d932446
Fix externally controlled executor not pausing (#1479)
mstoykov Jun 9, 2020
0839be8
make JSON output logging less noisy
michiboo May 28, 2020
08070ca
Rename the user-facing config options
na-- Jun 9, 2020
dcf2be3
Remove mentions of Load Impact Insights
na-- Jun 9, 2020
594b141
Remove CleanUpWrongMetadataJSON() now that we don't need it
na-- Jun 9, 2020
0bc0470
Rename Go names from Execution to Scenarios
na-- Jun 9, 2020
3fc886e
Rename more Go names from Execution to Scenarios
na-- Jun 9, 2020
5020f21
Rename ConstantLoopingVUs to ConstantVUs
na-- Jun 9, 2020
f95969a
Rename VariableArrivalRate to RampingArrivalRate
na-- Jun 9, 2020
05524b6
Rename VariableLoopingVUs to RampingVUs
na-- Jun 9, 2020
54a1a45
Rename executor files to reflect their new names
na-- Jun 9, 2020
0486c11
merge steps in VLV executors for more stability (#1496)
mstoykov Jun 10, 2020
c8bfbcb
fix js package http benchmark and add one with base compatibility-mode
mstoykov Jun 12, 2020
1841d35
Skip bridge benchmarks atleast one of which is broken since 4cfbe1612…
mstoykov Jun 12, 2020
4e4d5d8
Skip BenchmarkResponseJson which was apperantly broken when spliting …
mstoykov Jun 12, 2020
40d5c1a
Make the version a constant
na-- Jun 11, 2020
1ff05a4
Update the used Go version in appveyor
na-- Jun 11, 2020
06c82e2
Fix config validation messages after the renames
na-- Jun 11, 2020
987c903
Make errors starting the API server fatal, if adddress was explicitly…
na-- Jun 16, 2020
56a6285
Rename configType to executorType
na-- Jun 17, 2020
e0eab8f
rewrite vuHandle as a state machine and fix some more races (#1506)
mstoykov Jun 17, 2020
2f150f2
Merge pull request #1503 from loadimpact/fixBenchmarks
mstoykov Jun 17, 2020
56a03ae
remove space from logrus Field
mstoykov Jun 23, 2020
986f67d
Don't leak goroutines everywhere in the ws code
mstoykov Jun 24, 2020
a6bd751
update github.com/gorilla/websocket to 1.4.2
mstoykov Jun 24, 2020
fc34f91
Fix ws_ping not being formatted as time
mstoykov Jun 24, 2020
a9903e0
Merge pull request #1515 from loadimpact/updateWSLib
mstoykov Jun 25, 2020
33ca3af
Fix externally-controlled maxVUs scaling
Jun 24, 2020
1dc8222
Fix double increment of initializedVUs in executor tests
Jun 25, 2020
06f66c5
Update TestExternallyControlledRun to check for maxVUs and scaling down
Jun 25, 2020
fc48c46
Rewrite TestExternallyControlledRun to hopefully fix flakiness
Jun 25, 2020
b9939c7
Remove old ExecutionSchedulerSetVUs test, integrate in TestExternally…
Jun 29, 2020
d3894cb
Update goja
mstoykov Jun 29, 2020
bea60a4
Update outdated comment
Jun 29, 2020
0411270
Add "scenario" as default system tag
Jun 29, 2020
27a699e
Merge pull request #1520 from loadimpact/updateGoja
mstoykov Jun 30, 2020
64f30fc
Decrement initialized VUs only when not returning VUs to the global pool
Jun 30, 2020
d84fe0e
Minor type cleanup in TestExternallyControlledRun
Jun 30, 2020
61158c8
Reuse the context and state in js.VU as much as possible (#1478)
mstoykov Jun 30, 2020
890270d
Merge pull request #1517 from loadimpact/fix/1511-external-scale
Jun 30, 2020
e2dd282
Fix startTime>0 messing up the externally-controlled executor
na-- Jun 30, 2020
15c1000
chore: drop workaround for pre go1.13 fixes #1165
mstoykov Jun 30, 2020
ecf5e1a
Make MaxVUs equal to preallocatedVUs when missing for arrival rate ex…
mstoykov Jun 30, 2020
447f892
Tag the scenario logs properly
na-- Jul 1, 2020
94b88a0
VariableArrivalRate: don't block on unplannedVU init if possible
mstoykov May 5, 2020
6a23e86
Make certain no unitilized VU will be left unreturned
mstoykov May 7, 2020
502a550
Fix ramping VU initialization
na-- Jun 29, 2020
223ed80
Fix tests and constant-arrival-rate VU init
na-- Jul 2, 2020
9780e43
Fix a typo and a test
na-- Jul 2, 2020
07dea12
Handle unplanned VU init errors better
na-- Jul 3, 2020
89361f6
Merge pull request #1500 from loadimpact/fixRampingArrivalRateUnplann…
mstoykov Jul 3, 2020
e0c93e8
Add a new dropped_iterations metric
na-- Jul 2, 2020
29168ee
Fix a context bug and add tests
na-- Jul 3, 2020
9d6cffb
Fix a flaky test
na-- Jul 3, 2020
6b308c5
Fix a typo by simplifying the code
na-- Jul 3, 2020
41a4f73
Consistently use parentCtx in the executors' Run() methods
na-- Jul 3, 2020
ba12f04
Fix cloud test progress status in CLI
Jul 6, 2020
089e416
Move cloud status output to right side of progressbar, show time duri…
Jul 6, 2020
74cf031
Fix: show stages and new executor duration during cloud test run
Jun 9, 2020
f69cdeb
Ensure every progress bar change is printed, better align run and clo…
Jun 16, 2020
20b988a
Revert progressbar status prefix whitespace in local execution
Jul 6, 2020
41f89e7
Add missing printBar call in cloud execution
Jul 6, 2020
028c46e
Add helper function to modify and print the progressbar
Jul 6, 2020
1c7f2ce
Unify execution description for cloud/local execution
Jul 6, 2020
cc01c16
Revert executor.Stage / lib.Stage merge
Jul 6, 2020
83ae172
Reorder some var declarations for better legibility
Jul 6, 2020
f57e189
Remove duplicate execution plan calculations
Jul 6, 2020
c5e62ff
Merge pull request #1490 from loadimpact/fix/1488-cli-cloud-status
Jul 6, 2020
182297b
Display user-friendly times and correct VU numbers
na-- Jul 6, 2020
488a1fb
Fix a variable name typo
na-- Jul 6, 2020
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
17 changes: 10 additions & 7 deletions api/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,15 @@ import (
"net/http/httptest"
"testing"

"github.com/sirupsen/logrus"

"github.com/loadimpact/k6/api/common"
"github.com/loadimpact/k6/core"
"github.com/loadimpact/k6/core/local"
"github.com/loadimpact/k6/lib"
log "github.com/sirupsen/logrus"
logtest "github.com/sirupsen/logrus/hooks/test"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/urfave/negroni"
)

Expand All @@ -51,7 +54,7 @@ func TestLogger(t *testing.T) {
r := httptest.NewRequest(method, "http://example.com"+path, nil)

l, hook := logtest.NewNullLogger()
l.Level = log.DebugLevel
l.Level = logrus.DebugLevel
NewLogger(l)(negroni.NewResponseWriter(rw), r, testHTTPHandler)

res := rw.Result()
Expand All @@ -63,7 +66,7 @@ func TestLogger(t *testing.T) {
}

e := hook.LastEntry()
assert.Equal(t, log.DebugLevel, e.Level)
assert.Equal(t, logrus.DebugLevel, e.Level)
assert.Equal(t, fmt.Sprintf("%s %s", method, path), e.Message)
assert.Equal(t, http.StatusOK, e.Data["status"])
})
Expand All @@ -73,10 +76,10 @@ func TestLogger(t *testing.T) {
}

func TestWithEngine(t *testing.T) {
engine, err := core.NewEngine(nil, lib.Options{})
if !assert.NoError(t, err) {
return
}
executor, err := local.New(&lib.MiniRunner{}, logrus.StandardLogger())
require.NoError(t, err)
engine, err := core.NewEngine(executor, lib.Options{}, logrus.StandardLogger())
require.NoError(t, err)
na-- marked this conversation as resolved.
Show resolved Hide resolved

rw := httptest.NewRecorder()
r := httptest.NewRequest("GET", "http://example.com/", nil)
Expand Down
8 changes: 6 additions & 2 deletions api/v1/group_routes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ import (
"github.com/loadimpact/k6/core/local"
"github.com/loadimpact/k6/lib"
"github.com/manyminds/api2go/jsonapi"
"github.com/sirupsen/logrus"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

func TestGetGroups(t *testing.T) {
Expand All @@ -41,8 +43,10 @@ func TestGetGroups(t *testing.T) {
g2, err := g1.Group("group 2")
assert.NoError(t, err)

engine, err := core.NewEngine(local.New(&lib.MiniRunner{Group: g0}), lib.Options{})
assert.NoError(t, err)
executor, err := local.New(&lib.MiniRunner{Group: g0}, logrus.StandardLogger())
require.NoError(t, err)
engine, err := core.NewEngine(executor, lib.Options{}, logrus.StandardLogger())
require.NoError(t, err)

t.Run("list", func(t *testing.T) {
rw := httptest.NewRecorder()
Expand Down
4 changes: 2 additions & 2 deletions api/v1/metric_routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func HandleGetMetrics(rw http.ResponseWriter, r *http.Request, p httprouter.Para

var t time.Duration
if engine.Executor != nil {
t = engine.Executor.GetTime()
t = engine.Executor.GetState().GetCurrentTestRunDuration()
}

metrics := make([]Metric, 0)
Expand All @@ -56,7 +56,7 @@ func HandleGetMetric(rw http.ResponseWriter, r *http.Request, p httprouter.Param

var t time.Duration
if engine.Executor != nil {
t = engine.Executor.GetTime()
t = engine.Executor.GetState().GetCurrentTestRunDuration()
}

var metric Metric
Expand Down
17 changes: 13 additions & 4 deletions api/v1/metric_routes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,12 @@ import (
"net/http/httptest"
"testing"

"github.com/stretchr/testify/require"

"github.com/sirupsen/logrus"
na-- marked this conversation as resolved.
Show resolved Hide resolved

"github.com/loadimpact/k6/core"
"github.com/loadimpact/k6/core/local"
"github.com/loadimpact/k6/lib"
"github.com/loadimpact/k6/stats"
"github.com/manyminds/api2go/jsonapi"
Expand All @@ -35,8 +40,10 @@ import (
)

func TestGetMetrics(t *testing.T) {
engine, err := core.NewEngine(nil, lib.Options{})
assert.NoError(t, err)
executor, err := local.New(&lib.MiniRunner{}, logrus.StandardLogger())
require.NoError(t, err)
engine, err := core.NewEngine(executor, lib.Options{}, logrus.StandardLogger())
require.NoError(t, err)

engine.Metrics = map[string]*stats.Metric{
"my_metric": stats.New("my_metric", stats.Trend, stats.Time),
Expand Down Expand Up @@ -74,8 +81,10 @@ func TestGetMetrics(t *testing.T) {
}

func TestGetMetric(t *testing.T) {
engine, err := core.NewEngine(nil, lib.Options{})
assert.NoError(t, err)
executor, err := local.New(&lib.MiniRunner{}, logrus.StandardLogger())
require.NoError(t, err)
engine, err := core.NewEngine(executor, lib.Options{}, logrus.StandardLogger())
require.NoError(t, err)

engine.Metrics = map[string]*stats.Metric{
"my_metric": stats.New("my_metric", stats.Trend, stats.Time),
Expand Down
10 changes: 6 additions & 4 deletions api/v1/setup_teardown_routes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ import (
"testing"
"time"

"github.com/sirupsen/logrus"

"github.com/loadimpact/k6/core"
"github.com/loadimpact/k6/core/local"
"github.com/loadimpact/k6/js"
Expand Down Expand Up @@ -140,14 +142,14 @@ func TestSetupData(t *testing.T) {
runner.SetOptions(lib.Options{
Paused: null.BoolFrom(true),
VUs: null.IntFrom(2),
VUsMax: null.IntFrom(2),
Iterations: null.IntFrom(3),
NoSetup: null.BoolFrom(true),
SetupTimeout: types.NullDurationFrom(1 * time.Second),
TeardownTimeout: types.NullDurationFrom(1 * time.Second),
})
executor := local.New(runner)
executor.SetRunSetup(false)
engine, err := core.NewEngine(executor, runner.GetOptions())
executor, err := local.New(runner, logrus.StandardLogger())
require.NoError(t, err)
engine, err := core.NewEngine(executor, runner.GetOptions(), logrus.StandardLogger())
require.NoError(t, err)

ctx, cancel := context.WithCancel(context.Background())
Expand Down
9 changes: 5 additions & 4 deletions api/v1/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,12 @@ type Status struct {
}

func NewStatus(engine *core.Engine) Status {
executorState := engine.Executor.GetState()
return Status{
Paused: null.BoolFrom(engine.Executor.IsPaused()),
VUs: null.IntFrom(engine.Executor.GetVUs()),
VUsMax: null.IntFrom(engine.Executor.GetVUsMax()),
Running: engine.Executor.IsRunning(),
Running: executorState.HasStarted(),
Paused: null.BoolFrom(executorState.IsPaused()),
VUs: null.IntFrom(int64(executorState.GetCurrentlyActiveVUsCount())),
VUsMax: null.IntFrom(int64(executorState.GetInitializedVUsCount())),
Tainted: engine.IsTainted(),
}
}
Expand Down
30 changes: 18 additions & 12 deletions api/v1/status_routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,22 +56,28 @@ func HandlePatchStatus(rw http.ResponseWriter, r *http.Request, p httprouter.Par
return
}

if status.VUsMax.Valid {
if err := engine.Executor.SetVUsMax(status.VUsMax.Int64); err != nil {
apiError(rw, "Couldn't change cap", err.Error(), http.StatusBadRequest)
return
}
}
if status.VUs.Valid {
if err := engine.Executor.SetVUs(status.VUs.Int64); err != nil {
apiError(rw, "Couldn't scale", err.Error(), http.StatusBadRequest)
if status.Paused.Valid {
if err = engine.Executor.SetPaused(status.Paused.Bool); err != nil {
apiError(rw, "Pause error", err.Error(), http.StatusInternalServerError)
return
}
}
if status.Paused.Valid {
engine.Executor.SetPaused(status.Paused.Bool)
}

/*
//TODO: handle manual executor update
if status.VUsMax.Valid {
if err := engine.Executor.SetVUsMax(status.VUsMax.Int64); err != nil {
apiError(rw, "Couldn't change cap", err.Error(), http.StatusBadRequest)
return
}
}
if status.VUs.Valid {
if err := engine.Executor.SetVUs(status.VUs.Int64); err != nil {
apiError(rw, "Couldn't scale", err.Error(), http.StatusBadRequest)
return
}
}
*/
data, err := jsonapi.Marshal(NewStatus(engine))
if err != nil {
apiError(rw, "Encoding error", err.Error(), http.StatusInternalServerError)
Expand Down
14 changes: 10 additions & 4 deletions api/v1/status_routes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,22 +21,25 @@
package v1

import (
"bytes"
"encoding/json"
"net/http"
"net/http/httptest"
"testing"

"github.com/loadimpact/k6/core"
"github.com/loadimpact/k6/core/local"
"github.com/loadimpact/k6/lib"
"github.com/manyminds/api2go/jsonapi"
"github.com/sirupsen/logrus"
"github.com/stretchr/testify/assert"
"gopkg.in/guregu/null.v3"
"github.com/stretchr/testify/require"
)

func TestGetStatus(t *testing.T) {
engine, err := core.NewEngine(nil, lib.Options{})
assert.NoError(t, err)
executor, err := local.New(&lib.MiniRunner{}, logrus.StandardLogger())
require.NoError(t, err)
engine, err := core.NewEngine(executor, lib.Options{}, logrus.StandardLogger())
require.NoError(t, err)

rw := httptest.NewRecorder()
NewHandler().ServeHTTP(rw, newRequestWithEngine(engine, "GET", "/v1/status", nil))
Expand All @@ -62,6 +65,8 @@ func TestGetStatus(t *testing.T) {
})
}

//TODO: fix after the manual executor
/*
func TestPatchStatus(t *testing.T) {
testdata := map[string]struct {
StatusCode int
Expand Down Expand Up @@ -108,3 +113,4 @@ func TestPatchStatus(t *testing.T) {
})
}
}
*/
44 changes: 30 additions & 14 deletions cmd/cloud.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ package cmd
import (
"bytes"
"encoding/json"
"fmt"
"os"
"os/signal"
"path/filepath"
Expand All @@ -33,6 +34,7 @@ import (
"github.com/loadimpact/k6/lib"
"github.com/loadimpact/k6/stats/cloud"
"github.com/loadimpact/k6/ui"
"github.com/loadimpact/k6/ui/pb"
"github.com/pkg/errors"
"github.com/spf13/afero"
"github.com/spf13/cobra"
Expand All @@ -57,11 +59,9 @@ This will execute the test on the Load Impact cloud service. Use "k6 login cloud
RunE: func(cmd *cobra.Command, args []string) error {
//TODO: disable in quiet mode?
_, _ = BannerColor.Fprintf(stdout, "\n%s\n\n", Banner)
initBar := ui.ProgressBar{
Width: 60,
Left: func() string { return " uploading script" },
}
fprintf(stdout, "%s \r", initBar.String())

progressBar := pb.New(pb.WithConstLeft(" Init"))
printBar(progressBar, "Parsing script")

// Runner
pwd, err := os.Getwd()
Expand All @@ -81,11 +81,13 @@ This will execute the test on the Load Impact cloud service. Use "k6 login cloud
return err
}

printBar(progressBar, "Getting script options")
r, err := newRunner(src, runType, fs, runtimeOptions)
if err != nil {
return err
}

printBar(progressBar, "Consolidating options")
cliOpts, err := getOptions(cmd.Flags())
if err != nil {
return err
Expand All @@ -99,6 +101,11 @@ This will execute the test on the Load Impact cloud service. Use "k6 login cloud
return ExitCode{cerr, invalidConfigErrorCode}
}

//TODO: warn about lack of support for --no-setup and --no-teardown in the cloud?
//TODO: validate for usage of execution segment
//TODO: validate for manual exacution (i.e. schedulers that aren't distributable)
//TODO: move those validations to a separate function and reuse validateConfig()?

err = r.SetOptions(conf.Options)
if err != nil {
return err
Expand All @@ -113,6 +120,7 @@ This will execute the test on the Load Impact cloud service. Use "k6 login cloud
return errors.New("Not logged in, please use `k6 login cloud`.")
}

printBar(progressBar, "Building the archive")
arc := r.MakeArchive()
// TODO: Fix this
// We reuse cloud.Config for parsing options.ext.loadimpact, but this probably shouldn't be
Expand Down Expand Up @@ -161,22 +169,28 @@ This will execute the test on the Load Impact cloud service. Use "k6 login cloud
}

// Start cloud test run
printBar(progressBar, "Validating script options")
client := cloud.NewClient(cloudConfig.Token.String, cloudConfig.Host.String, Version)
if err := client.ValidateOptions(arc.Options); err != nil {
return err
}

printBar(progressBar, "Uploading archive")
refID, err := client.StartCloudTestRun(name, cloudConfig.ProjectID.Int64, arc)
if err != nil {
return err
}
progressBar.Modify(pb.WithConstLeft(" Run"))
printBar(progressBar, "Initializing the cloud test")

testURL := cloud.URLForResults(refID, cloudConfig)
fprintf(stdout, "\n\n")
fprintf(stdout, " execution: %s\n", ui.ValueColor.Sprint("cloud"))
fprintf(stdout, " executor: %s\n", ui.ValueColor.Sprint("cloud"))
fprintf(stdout, " script: %s\n", ui.ValueColor.Sprint(filename))
fprintf(stdout, " output: %s\n", ui.ValueColor.Sprint(testURL))
//TODO: print schedulers information
fprintf(stdout, "\n")
printBar(progressBar, "Initializing the cloud test")

// The quiet option hides the progress bar and disallow aborting the test
if quiet {
Expand All @@ -190,12 +204,15 @@ This will execute the test on the Load Impact cloud service. Use "k6 login cloud

var progressErr error
testProgress := &cloud.TestProgressResponse{}
progress := ui.ProgressBar{
Width: 60,
Left: func() string {
return " " + testProgress.RunStatusText
},
}
percentageFmt := "[" + pb.GetFixedLengthFloatFormat(100, 2) + "%%] %s"
progressBar.Modify(
pb.WithProgress(func() (float64, string) {
if testProgress.RunStatus < lib.RunStatusRunning {
return 0, testProgress.RunStatusText
}
return testProgress.Progress, fmt.Sprintf(percentageFmt, testProgress.Progress*100, testProgress.RunStatusText)
}),
)

ticker := time.NewTicker(time.Millisecond * 2000)
shouldExitLoop := false
Expand All @@ -209,8 +226,7 @@ This will execute the test on the Load Impact cloud service. Use "k6 login cloud
if (testProgress.RunStatus > lib.RunStatusRunning) || (exitOnRunning && testProgress.RunStatus == lib.RunStatusRunning) {
shouldExitLoop = true
}
progress.Progress = testProgress.Progress
fprintf(stdout, "%s\x1b[0K\r", progress.String())
printBar(progressBar, "")
} else {
log.WithError(progressErr).Error("Test progress error")
}
Expand Down
Loading