Skip to content

Commit

Permalink
Merge pull request #172 from yandex/dev
Browse files Browse the repository at this point in the history
v0.5.14
  • Loading branch information
oke11o authored Oct 26, 2023
2 parents a9118d4 + a9d7003 commit fcd376e
Show file tree
Hide file tree
Showing 12 changed files with 98 additions and 53 deletions.
2 changes: 1 addition & 1 deletion cli/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import (
"go.uber.org/zap/zapcore"
)

const Version = "0.5.13"
const Version = "0.5.14"
const defaultConfigFile = "load"
const stdinConfigSelector = "-"

Expand Down
28 changes: 25 additions & 3 deletions components/providers/http/decoders/jsonline_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (

const jsonlineDecoderInput = `{"host": "ya.net", "method": "GET", "uri": "/?sleep=100", "tag": "sleep1", "headers": {"User-agent": "Tank", "Connection": "close"}}
{"host": "ya.net", "method": "POST", "uri": "/?sleep=200", "tag": "sleep2", "headers": {"User-agent": "Tank", "Connection": "close"}, "body": "body_data"}
{"host": "ya.net", "method": "PUT", "uri": "/", "tag": "sleep3", "headers": {"User-agent": "Tank", "Connection": "close"}, "body": "body_data"}
`
Expand All @@ -41,12 +42,19 @@ func getJsonlineAmmoWants(t *testing.T) []DecodedAmmo {
http.Header{"Connection": []string{"close"}, "Content-Type": []string{"application/json"}, "User-Agent": []string{"Tank"}},
"sleep2",
),
mustNewAmmo(t,
"PUT",
"http://ya.net/",
[]byte("body_data"),
http.Header{"Connection": []string{"close"}, "Content-Type": []string{"application/json"}, "User-Agent": []string{"Tank"}},
"sleep3",
),
}
}

func Test_jsonlineDecoder_Scan(t *testing.T) {
decoder := newJsonlineDecoder(strings.NewReader(jsonlineDecoderInput), config.Config{
Limit: 4,
Limit: 6,
}, http.Header{"Content-Type": []string{"application/json"}})

ctx, cancel := context.WithTimeout(context.Background(), time.Second)
Expand All @@ -69,7 +77,7 @@ func Test_jsonlineDecoder_Scan(t *testing.T) {

func Test_jsonlineDecoder_LoadAmmo(t *testing.T) {
decoder := newJsonlineDecoder(strings.NewReader(jsonlineDecoderInput), config.Config{
Limit: 4,
Limit: 7,
}, http.Header{"Content-Type": []string{"application/json"}})

ctx, cancel := context.WithTimeout(context.Background(), time.Second)
Expand All @@ -80,6 +88,20 @@ func Test_jsonlineDecoder_LoadAmmo(t *testing.T) {
ammos, err := decoder.LoadAmmo(ctx)
assert.NoError(t, err)
assert.Equal(t, wants, ammos)
assert.Equal(t, decoder.config.Limit, uint(4))
assert.Equal(t, decoder.config.Limit, uint(7))
assert.Equal(t, decoder.config.Passes, uint(0))
}

func Benchmark_jsonlineDecoder_Scan_line(b *testing.B) {
decoder := newJsonlineDecoder(
strings.NewReader(jsonlineDecoderInput), config.Config{},
http.Header{"Content-Type": []string{"application/json"}},
)
ctx := context.Background()

b.ResetTimer()
for i := 0; i < b.N; i++ {
_, err := decoder.Scan(ctx)
require.NoError(b, err)
}
}
2 changes: 1 addition & 1 deletion components/providers/http/decoders/raw.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ func (d *rawDecoder) Scan(ctx context.Context) (DecodedAmmo, error) {
d.ammoNum++
reqSize, tag, err := raw.DecodeHeader(data)
if err != nil {
return nil, xerrors.Errorf("header decoding error: %w", err)
return nil, xerrors.Errorf("header decoding error for ammoNum %d: %w", d.ammoNum, err)
}

a := d.pool.Get().(*ammo.RawAmmo)
Expand Down
4 changes: 4 additions & 0 deletions components/providers/http/decoders/raw/decoder.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package raw
import (
"bufio"
"bytes"
"fmt"
"net/http"
"strconv"
"strings"
Expand All @@ -12,6 +13,9 @@ func DecodeHeader(headerString string) (reqSize int, tag string, err error) {
var sizeStr string
sizeStr, tag, _ = strings.Cut(headerString, " ")
reqSize, err = strconv.Atoi(sizeStr)
if err != nil {
return 0, "", fmt.Errorf("invalid payload size line `%s`. expect `%%d %%s`", headerString)
}
return reqSize, tag, err
}

Expand Down
15 changes: 15 additions & 0 deletions components/providers/http/decoders/raw_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"time"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/yandex/pandora/components/providers/http/config"
)

Expand Down Expand Up @@ -120,3 +121,17 @@ func Test_rawDecoder_LoadAmmo(t *testing.T) {
assert.Equal(t, decoder.config.Passes, uint(0))

}

func Benchmark_rawDecoder_Scan(b *testing.B) {
decoder := newRawDecoder(
strings.NewReader(rawDecoderInput), config.Config{},
http.Header{"Content-Type": []string{"application/json"}},
)
ctx := context.Background()

b.ResetTimer()
for i := 0; i < b.N; i++ {
_, err := decoder.Scan(ctx)
require.NoError(b, err)
}
}
20 changes: 17 additions & 3 deletions components/providers/http/decoders/uri_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ func Test_uriDecoder_readLine(t *testing.T) {
}
}

const uriInput = ` /0
const uriDecoderInput = ` /0
[A:b]
/1
[Host : example.com]
Expand Down Expand Up @@ -120,7 +120,7 @@ func getURIAmmoWants(t *testing.T) []DecodedAmmo {
}

func Test_uriDecoder_Scan(t *testing.T) {
decoder := newURIDecoder(strings.NewReader(uriInput), config.Config{
decoder := newURIDecoder(strings.NewReader(uriDecoderInput), config.Config{
Limit: 10,
}, http.Header{"Content-Type": []string{"application/json"}})

Expand All @@ -143,7 +143,7 @@ func Test_uriDecoder_Scan(t *testing.T) {
}

func Test_uriDecoder_LoadAmmo(t *testing.T) {
decoder := newURIDecoder(strings.NewReader(uriInput), config.Config{
decoder := newURIDecoder(strings.NewReader(uriDecoderInput), config.Config{
Limit: 10,
}, http.Header{"Content-Type": []string{"application/json"}})

Expand All @@ -158,3 +158,17 @@ func Test_uriDecoder_LoadAmmo(t *testing.T) {
assert.Equal(t, decoder.config.Limit, uint(10))
assert.Equal(t, decoder.config.Passes, uint(0))
}

func Benchmark_uriDecoder_Scan(b *testing.B) {
decoder := newURIDecoder(
strings.NewReader(uriDecoderInput), config.Config{},
http.Header{"Content-Type": []string{"application/json"}},
)
ctx := context.Background()

b.ResetTimer()
for i := 0; i < b.N; i++ {
_, err := decoder.Scan(ctx)
require.NoError(b, err)
}
}
20 changes: 17 additions & 3 deletions components/providers/http/decoders/uripost_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
"github.com/yandex/pandora/components/providers/http/decoders/ammo"
)

const uripostInput = `5 /0
const uripostDecoderInput = `5 /0
class
[A:b]
5 /1
Expand Down Expand Up @@ -46,7 +46,7 @@ func getUripostAmmoWants(t *testing.T) []DecodedAmmo {

func Test_uripostDecoder_Scan(t *testing.T) {

decoder := newURIPostDecoder(strings.NewReader(uripostInput), config.Config{
decoder := newURIPostDecoder(strings.NewReader(uripostDecoderInput), config.Config{
Limit: 8,
}, http.Header{"Content-Type": []string{"application/json"}})

Expand All @@ -69,7 +69,7 @@ func Test_uripostDecoder_Scan(t *testing.T) {
}

func Test_uripostDecoder_LoadAmmo(t *testing.T) {
decoder := newURIPostDecoder(strings.NewReader(uripostInput), config.Config{
decoder := newURIPostDecoder(strings.NewReader(uripostDecoderInput), config.Config{
Limit: 8,
}, http.Header{"Content-Type": []string{"application/json"}})

Expand All @@ -84,3 +84,17 @@ func Test_uripostDecoder_LoadAmmo(t *testing.T) {
assert.Equal(t, decoder.config.Limit, uint(8))
assert.Equal(t, decoder.config.Passes, uint(0))
}

func Benchmark_uripostDecoder_Scan(b *testing.B) {
decoder := newURIPostDecoder(
strings.NewReader(uripostDecoderInput), config.Config{},
http.Header{"Content-Type": []string{"application/json"}},
)
ctx := context.Background()

b.ResetTimer()
for i := 0; i < b.N; i++ {
_, err := decoder.Scan(ctx)
require.NoError(b, err)
}
}
6 changes: 3 additions & 3 deletions components/providers/http/provider/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,15 +98,15 @@ func (p *Provider) runFullScan(ctx context.Context) error {
return err
}
ammo, err := p.Decoder.Scan(ctx)
if !confutil.IsChosenCase(ammo.Tag(), p.Config.ChosenCases) {
continue
}
if err != nil {
if errors.Is(err, decoders.ErrAmmoLimit) || errors.Is(err, decoders.ErrPassLimit) {
err = nil
}
return err
}
if !confutil.IsChosenCase(ammo.Tag(), p.Config.ChosenCases) {
continue
}

select {
case <-ctx.Done():
Expand Down
2 changes: 1 addition & 1 deletion core/schedule/composite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ var _ = Describe("composite", func() {

unlimitedFinish := startAt.Add(unlimitedDuration)
sched := testee.(*compositeSchedule).scheds[0]
Expect(sched.(*unlimitedSchedule).finish).To(Equal(unlimitedFinish))
Expect(sched.(*unlimitedSchedule).finish.Load()).To(Equal(unlimitedFinish))

Expect(testee.Left()).To(Equal(3))

Expand Down
25 changes: 8 additions & 17 deletions core/schedule/unlilmited.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@
package schedule

import (
"sync"
"time"

"github.com/yandex/pandora/core"
"go.uber.org/atomic"
)

// NewUnlimited returns schedule that generates unlimited ops for passed duration.
func NewUnlimited(duration time.Duration) core.Schedule {
return &unlimitedSchedule{duration: duration}
return &unlimitedSchedule{duration: duration, finish: atomic.NewTime(time.Now())}
}

type UnlimitedConfig struct {
Expand All @@ -29,39 +29,30 @@ type unlimitedSchedule struct {
duration time.Duration

StartSync
finish time.Time
mx sync.RWMutex
finish *atomic.Time
}

func (s *unlimitedSchedule) Start(startAt time.Time) {
s.MarkStarted()
s.startOnce.Do(func() {
s.finish = startAt.Add(s.duration)
s.finish.Store(startAt.Add(s.duration))
})
}

func (s *unlimitedSchedule) Next() (tx time.Time, ok bool) {
s.startOnce.Do(func() {
s.MarkStarted()
s.mx.Lock()
s.finish = time.Now().Add(s.duration)
s.mx.Unlock()
s.finish.Store(time.Now().Add(s.duration))
})
now := time.Now()
if now.Before(s.finish) {
if now.Before(s.finish.Load()) {
return now, true
}
s.mx.RLock()
f := s.finish
s.mx.RUnlock()
return f, false
return s.finish.Load(), false
}

func (s *unlimitedSchedule) Left() int {
s.mx.RLock()
f := s.finish
s.mx.RUnlock()
if !s.IsStarted() || time.Now().Before(f) {
if !s.IsStarted() || time.Now().Before(s.finish.Load()) {
return -1
}
return 0
Expand Down
19 changes: 2 additions & 17 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ require (
github.com/google/uuid v1.3.1 // indirect
github.com/hashicorp/errwrap v1.1.0 // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/huandu/xstrings v1.3.3 // indirect
github.com/huandu/xstrings v1.4.0 // indirect
github.com/imdario/mergo v0.3.13 // indirect
github.com/kylelemons/godebug v1.1.0 // indirect
github.com/magiconair/properties v1.8.7 // indirect
Expand All @@ -77,7 +77,7 @@ require (
golang.org/x/sync v0.3.0 // indirect
golang.org/x/sys v0.12.0 // indirect
golang.org/x/text v0.13.0 // indirect
golang.org/x/tools v0.11.2-0.20230810185051-cc6b5804b8cf // indirect
golang.org/x/tools v0.12.1-0.20230825192346-2191a27a6dc5 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20230711160842-782d3b101e98 // indirect
google.golang.org/protobuf v1.31.0 // indirect
gopkg.in/go-playground/assert.v1 v1.2.1 // indirect
Expand All @@ -88,21 +88,6 @@ require (

replace github.com/insomniacslk/dhcp => github.com/insomniacslk/dhcp v0.0.0-20210120172423-cc9239ac6294

// yo: update cloud.google.com/go/pubsub v1.30.0 => v1.32.0
// yo: failed to generate ya.make files for module "cloud.google.com/go/pubsub": cannot query module due to -mod=vendor
// (Go version in go.mod is at least 1.14 and vendor directory exists.)
replace cloud.google.com/go/pubsub => cloud.google.com/go/pubsub v1.30.0

replace google.golang.org/grpc => google.golang.org/grpc v1.56.2

// Workaround weird go.mod shipped with k8s.io submodules.
// For the reasoning see
// https://suraj.io/post/2021/05/k8s-import/
//
// The list was generated automatically with:
//
// ya grep --remote -f='vendor/k8s.io/.*/go.mod' 'v0.0.0$' | cut -d : -f 3 | sort | uniq

// replace github.com/docker/docker => github.com/docker/docker v17.12.0-ce-rc1.0.20190822180741-9552f2b2fdde+incompatible

// k8s.io replacement list ends here
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -800,8 +800,8 @@ github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T
github.com/hashicorp/hcl/v2 v2.16.2 h1:mpkHZh/Tv+xet3sy3F9Ld4FyI2tUpWe9x3XtPx9f1a0=
github.com/hashicorp/hcl/v2 v2.16.2/go.mod h1:JRmR89jycNkrrqnMmvPDMd56n1rQJ2Q6KocSLCMCXng=
github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU=
github.com/huandu/xstrings v1.3.3 h1:/Gcsuc1x8JVbJ9/rlye4xZnVAbEkGauT8lbebqcQws4=
github.com/huandu/xstrings v1.3.3/go.mod h1:y5/lhBue+AyNmUVz9RLU9xbLR0o4KIIExikq4ovT0aE=
github.com/huandu/xstrings v1.4.0 h1:D17IlohoQq4UcpqD7fDk80P7l+lwAmlFaBHgOipl2FU=
github.com/huandu/xstrings v1.4.0/go.mod h1:y5/lhBue+AyNmUVz9RLU9xbLR0o4KIIExikq4ovT0aE=
github.com/iancoleman/strcase v0.2.0/go.mod h1:iwCmte+B7n89clKwxIoIXy/HfoL7AsD47ZCWhYzw7ho=
github.com/ianlancetaylor/demangle v0.0.0-20181102032728-5e5cf60278f6/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc=
github.com/ianlancetaylor/demangle v0.0.0-20200824232613-28f6c0f3b639/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc=
Expand Down Expand Up @@ -1295,8 +1295,8 @@ golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc
golang.org/x/tools v0.3.0/go.mod h1:/rWhSS2+zyEVwoJf8YAX6L2f0ntZ7Kn/mGgAWcipA5k=
golang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU=
golang.org/x/tools v0.7.0/go.mod h1:4pg6aUX35JBAogB10C9AtvVL+qowtN4pT3CGSQex14s=
golang.org/x/tools v0.11.2-0.20230810185051-cc6b5804b8cf h1:Oush7UwPamr2/iNeNFBuNFj89YyHn0YY69EKDdvANnk=
golang.org/x/tools v0.11.2-0.20230810185051-cc6b5804b8cf/go.mod h1:anzJrxPjNtfgiYQYirP2CPGzGLxrH2u2QBhn6Bf3qY8=
golang.org/x/tools v0.12.1-0.20230825192346-2191a27a6dc5 h1:Vk4mysSz+GqQK2eqgWbo4zEO89wkeAjJiFIr9bpqa8k=
golang.org/x/tools v0.12.1-0.20230825192346-2191a27a6dc5/go.mod h1:Sc0INKfu04TlqNoRA1hgpFZbhYXHPr4V5DzpSBTPqQM=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
Expand Down

0 comments on commit fcd376e

Please sign in to comment.