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

Once a scenario is run, it is run to the end ( runn loadt ). #1033

Merged
merged 2 commits into from
Sep 5, 2024
Merged
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: 1 addition & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,13 @@ test: cert
race:
go test ./... -race

test-loadt: cert
go test ./... -tags=loadt -count=1

test-integration: cert
chmod 600 testdata/sshd/id_rsa
go test ./... -tags=integration -count=1

test-all: cert
chmod 600 testdata/sshd/id_rsa
go test ./... -tags='integration loadt' -coverprofile=coverage.out -covermode=count
go test ./... -tags=integration -coverprofile=coverage.out -covermode=count

benchmark: cert
go test -bench . -benchmem -run Benchmark | octocov-go-test-bench --tee > custom_metrics_benchmark.json
Expand Down
1 change: 1 addition & 0 deletions loadt.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ func (r *loadtResult) Report(w io.Writer) error {
if err != nil {
return err
}

data := map[string]any{
"NumberOfRunbooks": r.runbookCount,
"WarmUpTime": r.warmUp.String(),
Expand Down
19 changes: 15 additions & 4 deletions loadt_test.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
//go:build loadt

package runn

import (
"context"
"testing"
"time"

"github.com/k1LoW/runn/testutil"
"github.com/ryo-yamaoka/otchkiss"
"github.com/ryo-yamaoka/otchkiss/setting"
)
Expand All @@ -17,16 +16,21 @@ func TestLoadt(t *testing.T) {
concarent int
}{
{"testdata/book/include_main.yml", 2},
{"testdata/book/http_sleep.yml", 2},
}
hs := testutil.HTTPServer(t)
t.Setenv("TEST_HTTP_ENDPOINT", hs.URL)
for _, tt := range tests {
t.Run(tt.in, func(t *testing.T) {
t.Parallel()
opts := []Option{}
opts := []Option{
Scopes(ScopeAllowRunExec),
}
o, err := Load(tt.in, opts...)
if err != nil {
t.Error(err)
}
s, err := setting.New(tt.concarent, 0, 5*time.Second, 5*time.Second)
s, err := setting.New(tt.concarent, 0, 100*time.Microsecond, 100*time.Millisecond)
if err != nil {
t.Error(err)
}
Expand All @@ -37,6 +41,13 @@ func TestLoadt(t *testing.T) {
if err := ot.Start(context.Background()); err != nil {
t.Error(err)
}

if ot.Result.Succeeded() == 0 {
t.Error("no succeeded")
}
if ot.Result.Failed() != 0 {
t.Error("some failed")
}
})
}
}
Expand Down
1 change: 1 addition & 0 deletions operator.go
Original file line number Diff line number Diff line change
Expand Up @@ -1545,6 +1545,7 @@ func (ops *operators) RequestOne(ctx context.Context) error {
if !ops.profile {
ops.sw.Disable()
}
ctx = context.WithoutCancel(ctx)
result, err := ops.runN(ctx)
if err != nil {
return err
Expand Down
8 changes: 4 additions & 4 deletions operator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -303,13 +303,13 @@ func TestLoad(t *testing.T) {
{"testdata/book/**/*", "nonexistent", "", "", 0},
{"testdata/book/**/*", "", "eb33c9aed04a7f1e03c1a1246b5d7bdaefd903d3", "", 1},
{"testdata/book/**/*", "", "eb33c9a", "", 1},
{"testdata/book/**/*", "", "", "http", 13},
{"testdata/book/**/*", "", "", "http", 14},
{"testdata/book/**/*", "", "", "openapi3", 9},
{"testdata/book/**/*", "", "", "http,openapi3", 13},
{"testdata/book/**/*", "", "", "http,openapi3", 14},
{"testdata/book/**/*", "", "", "http and openapi3", 9},
{"testdata/book/**/*", "", "", "http and nothing", 0},
{"testdata/book/**/*", "", "", "http or nothing", 13},
{"testdata/book/**/*", "", "", "http and not openapi3", 4},
{"testdata/book/**/*", "", "", "http or nothing", 14},
{"testdata/book/**/*", "", "", "http and not openapi3", 5},
{"testdata/book/needs_3.yml", "", "", "", 1}, // Runbooks that are only in the needs section are not counted at Load
}

Expand Down
15 changes: 15 additions & 0 deletions testdata/book/http_sleep.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
desc: Test using HTTP for loadt
labels:
- http
runners:
req:
endpoint: ${TEST_HTTP_ENDPOINT:-https:example.com}
steps:
-
desc: Sleep for 3 second
req:
/sleep/3:
get:
body: null
test:
current.res.status == 200
Loading