mirror of
https://github.com/mentos1386/zdravko.git
synced 2024-11-26 01:07:52 +00:00
fix(k6): config reading
This commit is contained in:
parent
4a36c60d9e
commit
33e8d2091d
4 changed files with 34 additions and 6 deletions
|
@ -22,7 +22,7 @@ func Healthcheck(ctx context.Context, param HealtcheckParam) (*HealthcheckResult
|
||||||
|
|
||||||
execution := k6.NewExecution(slog.Default(), param.Script)
|
execution := k6.NewExecution(slog.Default(), param.Script)
|
||||||
|
|
||||||
err := execution.Start(ctx)
|
err := execution.Run(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
|
@ -136,7 +136,7 @@ func (e *Execution) setupTracerProvider(ctx context.Context, test *loadedAndConf
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (e *Execution) Start(ctx context.Context) error {
|
func (e *Execution) Run(ctx context.Context) error {
|
||||||
var err error
|
var err error
|
||||||
var logger logrus.FieldLogger = logrus.StandardLogger()
|
var logger logrus.FieldLogger = logrus.StandardLogger()
|
||||||
|
|
||||||
|
|
|
@ -6,7 +6,7 @@ import (
|
||||||
"testing"
|
"testing"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestK6(t *testing.T) {
|
func TestK6Success(t *testing.T) {
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
logger := slog.Default()
|
logger := slog.Default()
|
||||||
|
|
||||||
|
@ -16,7 +16,7 @@ import { sleep } from 'k6';
|
||||||
|
|
||||||
export const options = {
|
export const options = {
|
||||||
vus: 10,
|
vus: 10,
|
||||||
duration: '30s',
|
duration: '5s',
|
||||||
};
|
};
|
||||||
|
|
||||||
export default function () {
|
export default function () {
|
||||||
|
@ -27,7 +27,35 @@ export default function () {
|
||||||
|
|
||||||
execution := NewExecution(logger, script)
|
execution := NewExecution(logger, script)
|
||||||
|
|
||||||
err := execution.Start(ctx)
|
err := execution.Run(ctx)
|
||||||
|
if err != nil {
|
||||||
|
t.Errorf("Error starting execution: %v", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestK6Fail(t *testing.T) {
|
||||||
|
ctx := context.Background()
|
||||||
|
logger := slog.Default()
|
||||||
|
|
||||||
|
script := `
|
||||||
|
import http from 'k6/http';
|
||||||
|
import { sleep } from 'k6';
|
||||||
|
|
||||||
|
export const options = {
|
||||||
|
thresholds: {
|
||||||
|
http_req_failed: ['rate<0.01'], // http errors should be less than 1%
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
export default function () {
|
||||||
|
http.get('https://fail.broken.example');
|
||||||
|
sleep(1);
|
||||||
|
}
|
||||||
|
`
|
||||||
|
|
||||||
|
execution := NewExecution(logger, script)
|
||||||
|
|
||||||
|
err := execution.Run(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("Error starting execution: %v", err)
|
t.Errorf("Error starting execution: %v", err)
|
||||||
}
|
}
|
||||||
|
|
|
@ -52,8 +52,8 @@ func (lt *loadedTest) consolidateDeriveAndValidateConfig() (*loadedAndConfigured
|
||||||
lt.logger.Debug("Consolidating config layers...")
|
lt.logger.Debug("Consolidating config layers...")
|
||||||
|
|
||||||
config := lib.Options{}
|
config := lib.Options{}
|
||||||
|
config = config.Apply(lt.initRunner.GetOptions())
|
||||||
|
|
||||||
config.Apply(lt.initRunner.GetOptions())
|
|
||||||
if config.SystemTags == nil {
|
if config.SystemTags == nil {
|
||||||
config.SystemTags = &metrics.DefaultSystemTagSet
|
config.SystemTags = &metrics.DefaultSystemTagSet
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue