How to use gracefulStop method of executor Package

Best K6 code snippet using executor.gracefulStop

executors_test.go

Source:executors_test.go Github

copy

Full Screen

...58 {`{"someKey": {"executor": "constant-vus", "vus": 10, "duration": "60s", "env": 123}}`, exp{parseError: true}},59 // Validation errors for constant-vus and the base config60 {61 `{"someKey": {"executor": "constant-vus", "vus": 10, "duration": "60s",62 "gracefulStop": "10s", "startTime": "70s", "env": {"test": "mest"}, "exec": "someFunc"}}`,63 exp{custom: func(t *testing.T, cm lib.ScenarioConfigs) {64 sched := NewConstantVUsConfig("someKey")65 sched.VUs = null.IntFrom(10)66 sched.Duration = types.NullDurationFrom(1 * time.Minute)67 sched.GracefulStop = types.NullDurationFrom(10 * time.Second)68 sched.StartTime = types.NullDurationFrom(70 * time.Second)69 sched.Exec = null.StringFrom("someFunc")70 sched.Env = map[string]string{"test": "mest"}71 require.Equal(t, cm, lib.ScenarioConfigs{"someKey": sched})72 require.Equal(t, sched.BaseConfig.Name, cm["someKey"].GetName())73 require.Equal(t, sched.BaseConfig.Type, cm["someKey"].GetType())74 require.Equal(t, sched.BaseConfig.GetGracefulStop(), cm["someKey"].GetGracefulStop())75 require.Equal(t,76 sched.BaseConfig.StartTime.Duration,77 types.Duration(cm["someKey"].GetStartTime()),78 )79 require.Equal(t, sched.BaseConfig.Env, cm["someKey"].GetEnv())80 assert.Empty(t, cm["someKey"].Validate())81 assert.Empty(t, cm.Validate())82 et, err := lib.NewExecutionTuple(nil, nil)83 require.NoError(t, err)84 assert.Equal(t, "10 looping VUs for 1m0s (exec: someFunc, startTime: 1m10s, gracefulStop: 10s)", cm["someKey"].GetDescription(et))85 schedReqs := cm["someKey"].GetExecutionRequirements(et)86 endOffset, isFinal := lib.GetEndOffset(schedReqs)87 assert.Equal(t, 70*time.Second, endOffset)88 assert.Equal(t, true, isFinal)89 assert.Equal(t, uint64(10), lib.GetMaxPlannedVUs(schedReqs))90 assert.Equal(t, uint64(10), lib.GetMaxPossibleVUs(schedReqs))91 totalReqs := cm.GetFullExecutionRequirements(et)92 endOffset, isFinal = lib.GetEndOffset(totalReqs)93 assert.Equal(t, 140*time.Second, endOffset)94 assert.Equal(t, true, isFinal)95 assert.Equal(t, uint64(10), lib.GetMaxPlannedVUs(schedReqs))96 assert.Equal(t, uint64(10), lib.GetMaxPossibleVUs(schedReqs))97 }},98 },99 {`{"aname": {"executor": "constant-vus", "duration": "60s"}}`, exp{}},100 {`{"": {"executor": "constant-vus", "vus": 10, "duration": "60s"}}`, exp{validationError: true}},101 {`{"aname": {"executor": "constant-vus"}}`, exp{validationError: true}},102 {`{"aname": {"executor": "constant-vus", "vus": 0.5}}`, exp{parseError: true}},103 {`{"aname": {"executor": "constant-vus", "vus": 10}}`, exp{validationError: true}},104 {`{"aname": {"executor": "constant-vus", "vus": 0, "duration": "60s"}}`, exp{validationError: true}},105 {`{"aname": {"executor": "constant-vus", "vus": -1, "duration": "60s"}}`, exp{validationError: true}},106 {`{"aname": {"executor": "constant-vus", "vus": 10, "duration": "0s"}}`, exp{validationError: true}},107 {`{"aname": {"executor": "constant-vus", "vus": 10, "duration": "10s", "startTime": "-10s"}}`, exp{validationError: true}},108 {`{"aname": {"executor": "constant-vus", "vus": 10, "duration": "10s", "exec": ""}}`, exp{validationError: true}},109 {`{"aname": {"executor": "constant-vus", "vus": 10, "duration": "10s", "gracefulStop": "-2s"}}`, exp{validationError: true}},110 // ramping-vus111 {112 `{"varloops": {"executor": "ramping-vus", "startVUs": 20, "gracefulStop": "15s", "gracefulRampDown": "10s",113 "startTime": "23s", "stages": [{"duration": "60s", "target": 30}, {"duration": "130s", "target": 10}]}}`,114 exp{custom: func(t *testing.T, cm lib.ScenarioConfigs) {115 sched := NewRampingVUsConfig("varloops")116 sched.GracefulStop = types.NullDurationFrom(15 * time.Second)117 sched.GracefulRampDown = types.NullDurationFrom(10 * time.Second)118 sched.StartVUs = null.IntFrom(20)119 sched.StartTime = types.NullDurationFrom(23 * time.Second)120 sched.Stages = []Stage{121 {Target: null.IntFrom(30), Duration: types.NullDurationFrom(60 * time.Second)},122 {Target: null.IntFrom(10), Duration: types.NullDurationFrom(130 * time.Second)},123 }124 require.Equal(t, cm, lib.ScenarioConfigs{"varloops": sched})125 assert.Empty(t, cm["varloops"].Validate())126 assert.Empty(t, cm.Validate())127 et, err := lib.NewExecutionTuple(nil, nil)128 require.NoError(t, err)129 assert.Equal(t, "Up to 30 looping VUs for 3m10s over 2 stages (gracefulRampDown: 10s, startTime: 23s, gracefulStop: 15s)", cm["varloops"].GetDescription(et))130 schedReqs := cm["varloops"].GetExecutionRequirements(et)131 endOffset, isFinal := lib.GetEndOffset(schedReqs)132 assert.Equal(t, 205*time.Second, endOffset)133 assert.Equal(t, true, isFinal)134 assert.Equal(t, uint64(30), lib.GetMaxPlannedVUs(schedReqs))135 assert.Equal(t, uint64(30), lib.GetMaxPossibleVUs(schedReqs))136 totalReqs := cm.GetFullExecutionRequirements(et)137 endOffset, isFinal = lib.GetEndOffset(totalReqs)138 assert.Equal(t, 228*time.Second, endOffset)139 assert.Equal(t, true, isFinal)140 assert.Equal(t, uint64(30), lib.GetMaxPlannedVUs(schedReqs))141 assert.Equal(t, uint64(30), lib.GetMaxPossibleVUs(schedReqs))142 }},143 },144 {145 `{"varloops": {"executor": "ramping-vus", "startVUs": 1, "gracefulStop": "0s", "gracefulRampDown": "10s",146 "stages": [{"duration": "10s", "target": 10}]}}`,147 exp{custom: func(t *testing.T, cm lib.ScenarioConfigs) {148 assert.Empty(t, cm["varloops"].Validate())149 assert.Empty(t, cm.Validate())150 et, err := lib.NewExecutionTuple(nil, nil)151 require.NoError(t, err)152 assert.Equal(t, "Up to 10 looping VUs for 10s over 1 stages (gracefulRampDown: 10s)", cm["varloops"].GetDescription(et))153 schedReqs := cm["varloops"].GetExecutionRequirements(et)154 assert.Equal(t, uint64(10), lib.GetMaxPlannedVUs(schedReqs))155 assert.Equal(t, uint64(10), lib.GetMaxPossibleVUs(schedReqs))156 }},157 },158 {159 `{"varloops": {"executor": "ramping-vus", "startVUs": 1, "gracefulStop": "0s", "gracefulRampDown": "0s",160 "stages": [{"duration": "10s", "target": 10}, {"duration": "0s", "target": 1}, {"duration": "10s", "target": 5}]}}`,161 exp{custom: func(t *testing.T, cm lib.ScenarioConfigs) {162 assert.Empty(t, cm["varloops"].Validate())163 assert.Empty(t, cm.Validate())164 et, err := lib.NewExecutionTuple(nil, nil)165 require.NoError(t, err)166 assert.Equal(t, "Up to 10 looping VUs for 20s over 3 stages (gracefulRampDown: 0s)", cm["varloops"].GetDescription(et))167 schedReqs := cm.GetFullExecutionRequirements(et)168 assert.Equal(t, uint64(10), lib.GetMaxPlannedVUs(schedReqs))169 assert.Equal(t, uint64(10), lib.GetMaxPossibleVUs(schedReqs))170 }},171 },172 {173 `{"varloops": {"executor": "ramping-vus", "startVUs": 1, "gracefulStop": "0s", "gracefulRampDown": "0s",174 "stages": [{"duration": "10s", "target": 10}, {"duration": "0s", "target": 11},{"duration": "0s", "target": 1}, {"duration": "10s", "target": 5}]}}`,175 exp{custom: func(t *testing.T, cm lib.ScenarioConfigs) {176 assert.Empty(t, cm["varloops"].Validate())177 assert.Empty(t, cm.Validate())178 et, err := lib.NewExecutionTuple(nil, nil)179 require.NoError(t, err)180 assert.Equal(t, "Up to 11 looping VUs for 20s over 4 stages (gracefulRampDown: 0s)", cm["varloops"].GetDescription(et))181 schedReqs := cm.GetFullExecutionRequirements(et)182 assert.Equal(t, uint64(11), lib.GetMaxPlannedVUs(schedReqs))183 assert.Equal(t, uint64(11), lib.GetMaxPossibleVUs(schedReqs))184 }},185 },186 {`{"varloops": {"executor": "ramping-vus", "startVUs": 0, "stages": [{"duration": "60s", "target": 0}]}}`, exp{validationError: true}},187 {`{"varloops": {"executor": "ramping-vus", "startVUs": -1, "stages": [{"duration": "60s", "target": 30}]}}`, exp{validationError: true}},188 {`{"varloops": {"executor": "ramping-vus", "startVUs": 2, "stages": [{"duration": "-60s", "target": 30}]}}`, exp{validationError: true}},189 {`{"varloops": {"executor": "ramping-vus", "startVUs": 2, "stages": [{"duration": "60s", "target": -30}]}}`, exp{validationError: true}},190 {`{"varloops": {"executor": "ramping-vus", "stages": [{"duration": "60s"}]}}`, exp{validationError: true}},191 {`{"varloops": {"executor": "ramping-vus", "stages": [{"target": 30}]}}`, exp{validationError: true}},192 {`{"varloops": {"executor": "ramping-vus", "stages": []}}`, exp{validationError: true}},193 {`{"varloops": {"executor": "ramping-vus"}}`, exp{validationError: true}},194 // shared-iterations195 {196 `{"ishared": {"executor": "shared-iterations", "iterations": 22, "vus": 12, "maxDuration": "100s"}}`,197 exp{custom: func(t *testing.T, cm lib.ScenarioConfigs) {198 sched := NewSharedIterationsConfig("ishared")199 sched.Iterations = null.IntFrom(22)200 sched.MaxDuration = types.NullDurationFrom(100 * time.Second)201 sched.VUs = null.IntFrom(12)202 assert.Empty(t, cm["ishared"].Validate())203 assert.Empty(t, cm.Validate())204 et, err := lib.NewExecutionTuple(nil, nil)205 require.NoError(t, err)206 assert.Equal(t, "22 iterations shared among 12 VUs (maxDuration: 1m40s, gracefulStop: 30s)", cm["ishared"].GetDescription(et))207 schedReqs := cm["ishared"].GetExecutionRequirements(et)208 endOffset, isFinal := lib.GetEndOffset(schedReqs)209 assert.Equal(t, 130*time.Second, endOffset)210 assert.Equal(t, true, isFinal)211 assert.Equal(t, uint64(12), lib.GetMaxPlannedVUs(schedReqs))212 assert.Equal(t, uint64(12), lib.GetMaxPossibleVUs(schedReqs))213 totalReqs := cm.GetFullExecutionRequirements(et)214 assert.Equal(t, schedReqs, totalReqs)215 et = mustNewExecutionTuple(newExecutionSegmentFromString("0:1/3"), newExecutionSegmentSequenceFromString("0,1/3,2/3,1"))216 assert.Equal(t, "8 iterations shared among 4 VUs (maxDuration: 1m40s, gracefulStop: 30s)", cm["ishared"].GetDescription(et))217 schedReqs = cm["ishared"].GetExecutionRequirements(et)218 endOffset, isFinal = lib.GetEndOffset(schedReqs)219 assert.Equal(t, 130*time.Second, endOffset)220 assert.Equal(t, true, isFinal)221 assert.Equal(t, uint64(4), lib.GetMaxPlannedVUs(schedReqs))222 assert.Equal(t, uint64(4), lib.GetMaxPossibleVUs(schedReqs))223 totalReqs = cm.GetFullExecutionRequirements(et)224 assert.Equal(t, schedReqs, totalReqs)225 et = mustNewExecutionTuple(newExecutionSegmentFromString("1/3:2/3"), newExecutionSegmentSequenceFromString("0,1/3,2/3,1"))226 assert.Equal(t, "7 iterations shared among 4 VUs (maxDuration: 1m40s, gracefulStop: 30s)", cm["ishared"].GetDescription(et))227 schedReqs = cm["ishared"].GetExecutionRequirements(et)228 endOffset, isFinal = lib.GetEndOffset(schedReqs)229 assert.Equal(t, 130*time.Second, endOffset)230 assert.Equal(t, true, isFinal)231 assert.Equal(t, uint64(4), lib.GetMaxPlannedVUs(schedReqs))232 assert.Equal(t, uint64(4), lib.GetMaxPossibleVUs(schedReqs))233 totalReqs = cm.GetFullExecutionRequirements(et)234 assert.Equal(t, schedReqs, totalReqs)235 et = mustNewExecutionTuple(newExecutionSegmentFromString("12/13:1"),236 newExecutionSegmentSequenceFromString("0,1/13,2/13,3/13,4/13,5/13,6/13,7/13,8/13,9/13,10/13,11/13,12/13,1"))237 assert.Equal(t, "0 iterations shared among 0 VUs (maxDuration: 1m40s, gracefulStop: 30s)", cm["ishared"].GetDescription(et))238 schedReqs = cm["ishared"].GetExecutionRequirements(et)239 endOffset, isFinal = lib.GetEndOffset(schedReqs)240 assert.Equal(t, time.Duration(0), endOffset)241 assert.Equal(t, true, isFinal)242 assert.Equal(t, uint64(0), lib.GetMaxPlannedVUs(schedReqs))243 assert.Equal(t, uint64(0), lib.GetMaxPossibleVUs(schedReqs))244 totalReqs = cm.GetFullExecutionRequirements(et)245 assert.Equal(t, schedReqs, totalReqs)246 }},247 },248 {`{"ishared": {"executor": "shared-iterations"}}`, exp{}}, // Has 1 VU & 1 iter default values249 {`{"ishared": {"executor": "shared-iterations", "iterations": 20}}`, exp{}},250 {`{"ishared": {"executor": "shared-iterations", "vus": 10}}`, exp{validationError: true}}, // error because VUs are more than iters251 {`{"ishared": {"executor": "shared-iterations", "iterations": 20, "vus": 10, "maxDuration": "30m"}}`, exp{}},252 {`{"ishared": {"executor": "shared-iterations", "iterations": 20, "vus": 10, "maxDuration": "-3m"}}`, exp{validationError: true}},253 {`{"ishared": {"executor": "shared-iterations", "iterations": 20, "vus": 10, "maxDuration": "0s"}}`, exp{validationError: true}},254 {`{"ishared": {"executor": "shared-iterations", "iterations": 20, "vus": -10}}`, exp{validationError: true}},255 {`{"ishared": {"executor": "shared-iterations", "iterations": -1, "vus": 1}}`, exp{validationError: true}},256 {`{"ishared": {"executor": "shared-iterations", "iterations": 20, "vus": 30}}`, exp{validationError: true}},257 // per-vu-iterations258 {259 `{"ipervu": {"executor": "per-vu-iterations", "iterations": 23, "vus": 13, "gracefulStop": 0}}`,260 exp{custom: func(t *testing.T, cm lib.ScenarioConfigs) {261 sched := NewPerVUIterationsConfig("ipervu")262 sched.Iterations = null.IntFrom(23)263 sched.GracefulStop = types.NullDurationFrom(0)264 sched.VUs = null.IntFrom(13)265 assert.Empty(t, cm["ipervu"].Validate())266 assert.Empty(t, cm.Validate())267 et, err := lib.NewExecutionTuple(nil, nil)268 require.NoError(t, err)269 assert.Equal(t, "23 iterations for each of 13 VUs (maxDuration: 10m0s)", cm["ipervu"].GetDescription(et))270 schedReqs := cm["ipervu"].GetExecutionRequirements(et)271 endOffset, isFinal := lib.GetEndOffset(schedReqs)272 assert.Equal(t, 600*time.Second, endOffset)273 assert.Equal(t, true, isFinal)274 assert.Equal(t, uint64(13), lib.GetMaxPlannedVUs(schedReqs))275 assert.Equal(t, uint64(13), lib.GetMaxPossibleVUs(schedReqs))276 totalReqs := cm.GetFullExecutionRequirements(et)277 assert.Equal(t, schedReqs, totalReqs)278 }},279 },280 {`{"ipervu": {"executor": "per-vu-iterations"}}`, exp{}}, // Has 1 VU & 1 iter default values281 {`{"ipervu": {"executor": "per-vu-iterations", "iterations": 20}}`, exp{}},282 {`{"ipervu": {"executor": "per-vu-iterations", "vus": 10}}`, exp{}},283 {`{"ipervu": {"executor": "per-vu-iterations", "iterations": 20, "vus": 10}}`, exp{}},284 {`{"ipervu": {"executor": "per-vu-iterations", "iterations": 20, "vus": 10, "maxDuration": "-3m"}}`, exp{validationError: true}},285 {`{"ipervu": {"executor": "per-vu-iterations", "iterations": 20, "vus": 10, "maxDuration": "0s"}}`, exp{validationError: true}},286 {`{"ipervu": {"executor": "per-vu-iterations", "iterations": 20, "vus": -10}}`, exp{validationError: true}},287 {`{"ipervu": {"executor": "per-vu-iterations", "iterations": -1, "vus": 1}}`, exp{validationError: true}},288 // constant-arrival-rate289 {290 `{"carrival": {"executor": "constant-arrival-rate", "rate": 30, "timeUnit": "1m", "duration": "10m", "preAllocatedVUs": 20, "maxVUs": 30}}`,291 exp{custom: func(t *testing.T, cm lib.ScenarioConfigs) {292 et, err := lib.NewExecutionTuple(nil, nil)293 require.NoError(t, err)294 sched := NewConstantArrivalRateConfig("carrival")295 sched.Rate = null.IntFrom(30)296 sched.Duration = types.NullDurationFrom(10 * time.Minute)297 sched.TimeUnit = types.NullDurationFrom(1 * time.Minute)298 sched.PreAllocatedVUs = null.IntFrom(20)299 sched.MaxVUs = null.IntFrom(30)300 assert.Empty(t, cm["carrival"].Validate())301 assert.Empty(t, cm.Validate())302 assert.Equal(t, "0.50 iterations/s for 10m0s (maxVUs: 20-30, gracefulStop: 30s)", cm["carrival"].GetDescription(et))303 schedReqs := cm["carrival"].GetExecutionRequirements(et)304 endOffset, isFinal := lib.GetEndOffset(schedReqs)305 assert.Equal(t, 630*time.Second, endOffset)306 assert.Equal(t, true, isFinal)307 assert.Equal(t, uint64(20), lib.GetMaxPlannedVUs(schedReqs))308 assert.Equal(t, uint64(30), lib.GetMaxPossibleVUs(schedReqs))309 totalReqs := cm.GetFullExecutionRequirements(et)310 assert.Equal(t, schedReqs, totalReqs)311 }},312 },313 {`{"carrival": {"executor": "constant-arrival-rate", "rate": 10, "duration": "10m", "preAllocatedVUs": 20, "maxVUs": 30}}`, exp{}},314 {`{"carrival": {"executor": "constant-arrival-rate", "rate": 10, "duration": "10m", "preAllocatedVUs": 20, "maxVUs": 30, "timeUnit": "-1s"}}`, exp{validationError: true}},315 {316 `{"carrival": {"executor": "constant-arrival-rate", "rate": 10, "duration": "10m", "preAllocatedVUs": 20}}`,317 exp{custom: func(t *testing.T, cm lib.ScenarioConfigs) {318 assert.Empty(t, cm["carrival"].Validate())319 require.EqualValues(t, 20, cm["carrival"].(*ConstantArrivalRateConfig).MaxVUs.Int64)320 }},321 },322 {`{"carrival": {"executor": "constant-arrival-rate", "rate": 10, "duration": "10m", "maxVUs": 30}}`, exp{validationError: true}},323 {`{"carrival": {"executor": "constant-arrival-rate", "rate": 10, "preAllocatedVUs": 20, "maxVUs": 30}}`, exp{validationError: true}},324 {`{"carrival": {"executor": "constant-arrival-rate", "duration": "10m", "preAllocatedVUs": 20, "maxVUs": 30}}`, exp{validationError: true}},325 {`{"carrival": {"executor": "constant-arrival-rate", "rate": 10, "duration": "0m", "preAllocatedVUs": 20, "maxVUs": 30}}`, exp{validationError: true}},326 {`{"carrival": {"executor": "constant-arrival-rate", "rate": 0, "duration": "10m", "preAllocatedVUs": 20, "maxVUs": 30}}`, exp{validationError: true}},327 {`{"carrival": {"executor": "constant-arrival-rate", "rate": 10, "duration": "10m", "preAllocatedVUs": 20, "maxVUs": 15}}`, exp{validationError: true}},328 {`{"carrival": {"executor": "constant-arrival-rate", "rate": 10, "duration": "0s", "preAllocatedVUs": 20, "maxVUs": 25}}`, exp{validationError: true}},329 {`{"carrival": {"executor": "constant-arrival-rate", "rate": 10, "duration": "10m", "preAllocatedVUs": -2, "maxVUs": 25}}`, exp{validationError: true}},330 // ramping-arrival-rate331 {332 `{"varrival": {"executor": "ramping-arrival-rate", "startRate": 10, "timeUnit": "30s", "preAllocatedVUs": 20,333 "maxVUs": 50, "stages": [{"duration": "3m", "target": 30}, {"duration": "5m", "target": 10}]}}`,334 exp{custom: func(t *testing.T, cm lib.ScenarioConfigs) {335 sched := NewRampingArrivalRateConfig("varrival")336 sched.StartRate = null.IntFrom(10)337 sched.Stages = []Stage{338 {Target: null.IntFrom(30), Duration: types.NullDurationFrom(180 * time.Second)},339 {Target: null.IntFrom(10), Duration: types.NullDurationFrom(300 * time.Second)},340 }341 sched.TimeUnit = types.NullDurationFrom(30 * time.Second)342 sched.PreAllocatedVUs = null.IntFrom(20)343 sched.MaxVUs = null.IntFrom(50)344 require.Equal(t, cm, lib.ScenarioConfigs{"varrival": sched})345 assert.Empty(t, cm["varrival"].Validate())346 assert.Empty(t, cm.Validate())347 et, err := lib.NewExecutionTuple(nil, nil)348 require.NoError(t, err)349 assert.Equal(t, "Up to 1.00 iterations/s for 8m0s over 2 stages (maxVUs: 20-50, gracefulStop: 30s)", cm["varrival"].GetDescription(et))350 schedReqs := cm["varrival"].GetExecutionRequirements(et)351 endOffset, isFinal := lib.GetEndOffset(schedReqs)352 assert.Equal(t, 510*time.Second, endOffset)353 assert.Equal(t, true, isFinal)354 assert.Equal(t, uint64(20), lib.GetMaxPlannedVUs(schedReqs))355 assert.Equal(t, uint64(50), lib.GetMaxPossibleVUs(schedReqs))356 totalReqs := cm.GetFullExecutionRequirements(et)357 assert.Equal(t, schedReqs, totalReqs)358 }},359 },360 {`{"varrival": {"executor": "ramping-arrival-rate", "preAllocatedVUs": 20, "maxVUs": 50, "stages": [{"duration": "5m", "target": 10}]}}`, exp{}},361 {`{"varrival": {"executor": "ramping-arrival-rate", "preAllocatedVUs": -20, "maxVUs": 50, "stages": [{"duration": "5m", "target": 10}]}}`, exp{validationError: true}},362 {`{"varrival": {"executor": "ramping-arrival-rate", "startRate": -1, "preAllocatedVUs": 20, "maxVUs": 50, "stages": [{"duration": "5m", "target": 10}]}}`, exp{validationError: true}},363 {...

Full Screen

Full Screen

base_config.go

Source:base_config.go Github

copy

Full Screen

...27 "go.k6.io/k6/lib/consts"28 "go.k6.io/k6/lib/types"29)30// DefaultGracefulStopValue is the graceful top value for all executors, unless31// it's manually changed by the gracefulStop in each one.32// TODO?: Discard? Or make this actually user-configurable somehow? hello #883...33var DefaultGracefulStopValue = 30 * time.Second //nolint:gochecknoglobals34var executorNameWhitelist = regexp.MustCompile(`^[0-9a-zA-Z_-]+$`) //nolint:gochecknoglobals35const executorNameErr = "the executor name should contain only numbers, latin letters, underscores, and dashes"36// BaseConfig contains the common config fields for all executors37type BaseConfig struct {38 Name string `json:"-"` // set via the JS object key39 Type string `json:"executor"`40 StartTime types.NullDuration `json:"startTime"`41 GracefulStop types.NullDuration `json:"gracefulStop"`42 Env map[string]string `json:"env"`43 Exec null.String `json:"exec"` // function name, externally validated44 Tags map[string]string `json:"tags"`45 // TODO: future extensions like distribution, others?46}47// NewBaseConfig returns a default base config with the default values48func NewBaseConfig(name, configType string) BaseConfig {49 return BaseConfig{50 Name: name,51 Type: configType,52 GracefulStop: types.NewNullDuration(DefaultGracefulStopValue, false),53 }54}55// Validate checks some basic things like present name, type, and a positive start time56func (bc BaseConfig) Validate() (errors []error) {57 // Some just-in-case checks, since those things are likely checked in other places or58 // even assigned by us:59 if bc.Name == "" {60 errors = append(errors, fmt.Errorf("executor name shouldn't be empty"))61 }62 if !executorNameWhitelist.MatchString(bc.Name) {63 errors = append(errors, fmt.Errorf(executorNameErr))64 }65 if bc.Exec.Valid && bc.Exec.String == "" {66 errors = append(errors, fmt.Errorf("exec value cannot be empty"))67 }68 if bc.Type == "" {69 errors = append(errors, fmt.Errorf("missing or empty type field"))70 }71 // The actually reasonable checks:72 if bc.StartTime.Duration < 0 {73 errors = append(errors, fmt.Errorf("the startTime can't be negative"))74 }75 if bc.GracefulStop.Duration < 0 {76 errors = append(errors, fmt.Errorf("the gracefulStop timeout can't be negative"))77 }78 return errors79}80// GetName returns the name of the executor.81func (bc BaseConfig) GetName() string {82 return bc.Name83}84// GetType returns the executor's type as a string ID.85func (bc BaseConfig) GetType() string {86 return bc.Type87}88// GetStartTime returns the starting time, relative to the beginning of the89// actual test, that this executor is supposed to execute.90func (bc BaseConfig) GetStartTime() time.Duration {91 return time.Duration(bc.StartTime.Duration)92}93// GetGracefulStop returns how long k6 is supposed to wait for any still94// running iterations to finish executing at the end of the normal executor95// duration, before it actually kills them.96//97// Of course, that doesn't count when the user manually interrupts the test,98// then iterations are immediately stopped.99func (bc BaseConfig) GetGracefulStop() time.Duration {100 return time.Duration(bc.GracefulStop.Duration)101}102// GetEnv returns any specific environment key=value pairs that103// are configured for the executor.104func (bc BaseConfig) GetEnv() map[string]string {105 return bc.Env106}107// GetExec returns the configured custom exec value, if any.108func (bc BaseConfig) GetExec() string {109 exec := bc.Exec.ValueOrZero()110 if exec == "" {111 exec = consts.DefaultFn112 }113 return exec114}115// GetTags returns any custom tags configured for the executor.116func (bc BaseConfig) GetTags() map[string]string {117 return bc.Tags118}119// IsDistributable returns true since by default all executors could be run in120// a distributed manner.121func (bc BaseConfig) IsDistributable() bool {122 return true123}124// getBaseInfo is a helper method for the "parent" String methods.125func (bc BaseConfig) getBaseInfo(facts ...string) string {126 if bc.Exec.Valid {127 facts = append(facts, fmt.Sprintf("exec: %s", bc.Exec.String))128 }129 if bc.StartTime.Duration > 0 {130 facts = append(facts, fmt.Sprintf("startTime: %s", bc.StartTime.Duration))131 }132 if bc.GracefulStop.Duration > 0 {133 facts = append(facts, fmt.Sprintf("gracefulStop: %s", bc.GracefulStop.Duration))134 }135 if len(facts) == 0 {136 return ""137 }138 return " (" + strings.Join(facts, ", ") + ")"139}...

Full Screen

Full Screen

gracefulStop

Using AI Code Generation

copy

Full Screen

1import java.util.concurrent.*;2public class Main {3 public static void main(String[] args) {4 ExecutorService executor = Executors.newSingleThreadExecutor();5 executor.execute(new Runnable() {6 public void run() {7 try {8 Thread.sleep(100);9 } catch (InterruptedException e) {10 System.out.println("Interrupted");11 }12 }13 });14 executor.shutdown();15 try {16 if (!executor.awaitTermination(80, TimeUnit.MILLISECONDS)) {17 executor.shutdownNow();18 }19 } catch (InterruptedException e) {20 executor.shutdownNow();21 }22 }23}24import java.util.concurrent.*;25public class Main {26 public static void main(String[] args) {27 ExecutorService executor = Executors.newSingleThreadExecutor();28 executor.execute(new Runnable() {29 public void run() {30 try {31 Thread.sleep(100);32 } catch (InterruptedException e) {33 System.out.println("Interrupted");34 }35 }36 });37 executor.shutdownNow();38 try {39 if (!executor.awaitTermination(80, TimeUnit.MILLISECONDS)) {40 executor.shutdownNow();41 }42 } catch (InterruptedException e) {43 executor.shutdownNow();44 }45 }46}47import java.util.concurrent.*;48public class Main {49 public static void main(String[] args) {50 ExecutorService executor = Executors.newSingleThreadExecutor();51 executor.execute(new Runnable() {52 public void run() {53 try {54 Thread.sleep(100);55 } catch (InterruptedException e) {56 System.out.println("Interrupted");57 }58 }59 });60 executor.shutdown();61 try {62 if (!executor.awaitTermination(80, TimeUnit.MILLISECONDS)) {63 executor.shutdownNow();64 }65 } catch (InterruptedException e) {66 executor.shutdownNow();67 }68 }69}70import java.util.concurrent.*;71public class Main {72 public static void main(String[] args) {73 ExecutorService executor = Executors.newSingleThreadExecutor();74 executor.execute(new Runnable() {75 public void run() {76 try {77 Thread.sleep(100);78 } catch (InterruptedException e) {79 System.out.println("Interrupted

Full Screen

Full Screen

gracefulStop

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 fmt.Println("Starting the application...")4 go longRunningTask()5 time.Sleep(2 * time.Second)6 fmt.Println("Stopping the application...")7}8func longRunningTask() {9 fmt.Println("Starting a task...")10 time.Sleep(5 * time.Second)11 fmt.Println("Task is completed...")12}13import (14func main() {15 fmt.Println("Starting the application...")16 go longRunningTask()17 time.Sleep(2 * time.Second)18 fmt.Println("Stopping the application...")19}20func longRunningTask() {21 fmt.Println("Starting a task...")22 time.Sleep(5 * time.Second)23 fmt.Println("Task is completed...")24}25import (26func main() {27 fmt.Println("Starting the application...")28 go longRunningTask()29 time.Sleep(2 * time.Second)30 fmt.Println("Stopping the application...")31}32func longRunningTask() {33 fmt.Println("Starting a task...")34 time.Sleep(5 * time.Second)35 fmt.Println("Task is completed...")36}37import (38func main() {39 fmt.Println("Starting the application...")40 go longRunningTask()41 time.Sleep(2 * time.Second)42 fmt.Println("Stopping the application...")43}44func longRunningTask() {45 fmt.Println("Starting a task...")46 time.Sleep(5 * time.Second)47 fmt.Println("Task is completed...")48}49import (

Full Screen

Full Screen

gracefulStop

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 fmt.Println("Starting the application...")4 go longRunningTask()5 time.Sleep(2 * time.Second)6 fmt.Println("Stopping the application...")7}8func longRunningTask() {9 fmt.Println("Starting a task...")10 time.Sleep(5 * time.Second)11 fmt.Println("Task is done.")12}13import (14func main() {15 fmt.Println("Starting the application...")16 go longRunningTask()17 time.Sleep(2 * time.Second)18 fmt.Println("Stopping the application...")19}20func longRunningTask() {21 fmt.Println("Starting a task...")22 time.Sleep(5 * time.Second)23 fmt.Println("Task is done.")24}25import (26func main() {27 fmt.Println("Starting the application...")28 go longRunningTask()29 time.Sleep(2 * time.Second)30 fmt.Println("Stopping the application...")31}32func longRunningTask() {33 fmt.Println("Starting a task...")34 time.Sleep(5 * time.Second)35 fmt.Println("Task is done.")36}37import (38func main() {39 fmt.Println("Starting the application...")40 go longRunningTask()41 time.Sleep(2 * time.Second)42 fmt.Println("Stopping the application...")43}44func longRunningTask() {45 fmt.Println("Starting a task...")46 time.Sleep(5 * time.Second)47 fmt.Println("Task is done.")48}49import (50func main() {51 fmt.Println("Starting the application...")52 go longRunningTask()53 time.Sleep(2 * time.Second)54 fmt.Println("Stopping the application...")55}56func longRunningTask() {57 fmt.Println("Starting a task...")

Full Screen

Full Screen

gracefulStop

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 e := executor.NewExecutor()4 e.Start()5 time.Sleep(5 * time.Second)6 e.GracefulStop()7 fmt.Println("Done")8}9import (10func main() {11 e := executor.NewExecutor()12 e.Start()13 time.Sleep(5 * time.Second)14 e.ShutdownNow()15 fmt.Println("Done")16}17import (18func main() {19 e := executor.NewExecutor()20 e.Start()21 time.Sleep(5 * time.Second)22 e.Shutdown()23 fmt.Println("Done")24}

Full Screen

Full Screen

gracefulStop

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 fmt.Println("Starting the application...")4 executor := NewExecutor()5 executor.Start()6 time.Sleep(5 * time.Second)7 executor.GracefulStop()8 fmt.Println("Stopping the application...")9}10import (11func main() {12 fmt.Println("Starting the application...")13 executor := NewExecutor()14 executor.Start()15 time.Sleep(5 * time.Second)16 executor.ShutdownNow()17 fmt.Println("Stopping the application...")18}19import (20func main() {21 fmt.Println("Starting the application...")22 executor := NewExecutor()23 executor.Start()24 time.Sleep(5 * time.Second)25 executor.Shutdown()26 fmt.Println("Stopping the application...")27}28import (29func main() {30 fmt.Println("Starting the application...")31 executor := NewExecutor()32 executor.Start()33 time.Sleep(5 * time.Second)34 executor.Shutdown()35 fmt.Println("Waiting for executor to terminate...")36 executor.WaitTermination()37 fmt.Println("Stopping the application...")38}39import (40func main() {41 fmt.Println("Starting the application...")42 executor := NewExecutor()43 executor.Start()44 time.Sleep(5 * time.Second)45 executor.ShutdownNow()46 fmt.Println("Waiting for executor to terminate...")47 executor.WaitTermination()48 fmt.Println("Stopping the application...")49}50import (51func main() {52 fmt.Println("Starting the application...")53 executor := NewExecutor()54 executor.Start()55 time.Sleep(5 * time.Second)56 executor.ShutdownNow()57 fmt.Println("Waiting for executor to terminate...")58 executor.WaitTermination()59 fmt.Println("Is executor shutdown: ", executor.IsShutdown())60 fmt.Println("Stopping the application...")61}

Full Screen

Full Screen

gracefulStop

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 executor := NewExecutor(10)4 for i := 0; i < 10; i++ {5 executor.Submit(func() {6 time.Sleep(5 * time.Second)7 fmt.Println("Task Done")8 })9 }

Full Screen

Full Screen

gracefulStop

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 e = NewExecutor()4 e.Execute()5 time.Sleep(3 * time.Second)6 e.GracefulStop()7}8import (9func main() {10 e = NewExecutor()11 e.Execute()12 time.Sleep(3 * time.Second)13 e.Stop()14}15import (16func main() {17 e = NewExecutor()18 e.Execute()19 time.Sleep(3 * time.Second)20 e.Stop()21}22import (23func main() {24 e = NewExecutor()25 e.Execute()26 time.Sleep(3 * time.Second)27 e.Stop()28}29import (30func main() {31 e = NewExecutor()32 e.Execute()33 time.Sleep(3 * time.Second)34 e.Stop()35}36import (37func main() {38 e = NewExecutor()39 e.Execute()40 time.Sleep(3 * time.Second)41 e.Stop()42}43import (44func main() {45 e = NewExecutor()46 e.Execute()47 time.Sleep(3 * time.Second)48 e.Stop()49}50import (51func main() {52 e = NewExecutor()53 e.Execute()54 time.Sleep(3 * time.Second)55 e.Stop()56}57import (58func main() {59 e = NewExecutor()60 e.Execute()61 time.Sleep(3 * time.Second)62 e.Stop()63}64import (

Full Screen

Full Screen

gracefulStop

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 fmt.Println("Hello, playground")4 executor := NewExecutor()5 executor.Start()6 executor.Run()7 executor.GracefulStop()8}9import (10type Executor struct {11}12func NewExecutor() *Executor {13 condMutex := &sync.Mutex{}14 return &Executor{15 cond: sync.NewCond(condMutex),16 }17}18func (e *Executor) Start() {19}20func (e *Executor) Run() {21 go func() {22 for e.running {23 e.cond.L.Lock()24 e.cond.Wait()25 e.cond.L.Unlock()26 time.Sleep(1 * time.Second)27 fmt.Println("hello")28 }29 }()30}31func (e *Executor) GracefulStop() {32 e.cond.Signal()33}34import (35type Executor struct {36}37func NewExecutor() *Executor {38 condMutex := &sync.Mutex{}39 return &Executor{40 cond: sync.NewCond(condMutex),41 }42}43func (e *Executor) Start() {44}45func (e *Executor) Run() {46 go func() {47 for e.running {48 e.cond.L.Lock()49 e.cond.Wait()50 e.cond.L.Unlock()51 time.Sleep(1 * time.Second)52 fmt.Println("hello")53 }54 }()55}56func (e *Executor) GracefulStop() {57 e.cond.Signal()58}59import (60type Executor struct {61}62func NewExecutor() *Executor {

Full Screen

Full Screen

gracefulStop

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 c := cron.New()4 c.AddFunc("* * * * *", func() {5 fmt.Println("Every minute on the minute")6 })7 c.Start()8 ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)9 defer cancel()10 <-ctx.Done()11 c.Stop()12}13import (14func main() {15 c := cron.New()16 c.AddFunc("* * * * *", func() {17 fmt.Println("Every minute on the minute")18 })19 c.Start()20 ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)21 defer cancel()22 <-ctx.Done()23 c.Stop()24}25import (26func main() {27 c := cron.New()28 c.AddFunc("* * * * *", func() {29 fmt.Println("Every minute on the minute")30 })31 c.Start()

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run K6 automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Most used method in

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful