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

honor time option #6

Merged
merged 1 commit into from
Aug 31, 2020
Merged
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
25 changes: 21 additions & 4 deletions grpcreplay/grpcreplay.go
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,7 @@ type Resender struct {
streams []*stream
r io.Reader
srp SendRequestProcessor
opts *ResenderOptions
}

type SendRequestProcessor interface {
Expand All @@ -272,16 +273,20 @@ type SendRequestProcessor interface {
NextClose(i int)
}

func NewSender(filename string, srp SendRequestProcessor) (*Resender, error) {
type ResenderOptions struct {
HonorTime bool
}

func NewSender(filename string, srp SendRequestProcessor, opts *ResenderOptions) (*Resender, error) {
f, err := os.Open(filename)
if err != nil {
return nil, err
}
return NewResenderReader(f, srp)
return NewResenderReader(f, srp, opts)
}

func NewResenderReader(r io.Reader, srp SendRequestProcessor) (*Resender, error) {
return &Resender{srp: srp, r: bufio.NewReader(r)}, nil
func NewResenderReader(r io.Reader, srp SendRequestProcessor, opts *ResenderOptions) (*Resender, error) {
return &Resender{srp: srp, r: bufio.NewReader(r), opts: opts}, nil
}

func (rep *Resender) Run() error {
Expand All @@ -304,19 +309,28 @@ func (rep *Resender) Run() error {
}
switch e.kind {
case pb.Entry_REQUEST:
if rep.opts.HonorTime {
time.Sleep(time.Duration(e.delay))
}
rep.srp.NextCall(e.method, e.msg.msg)

case pb.Entry_RESPONSE:
continue

case pb.Entry_CREATE_STREAM:
if rep.opts.HonorTime {
time.Sleep(time.Duration(e.delay))
}
rep.srp.NextStream(e.method, i)
s := &stream{method: e.method, createIndex: i}
s.createErr = e.msg.err
streamsByIndex[i] = s
rep.streams = append(rep.streams, s)

case pb.Entry_SEND:
if rep.opts.HonorTime {
time.Sleep(time.Duration(e.delay))
}
s := streamsByIndex[e.refIndex]
if s == nil {
return fmt.Errorf("resender: no stream for send #%d", i)
Expand All @@ -327,6 +341,9 @@ func (rep *Resender) Run() error {
continue

case pb.Entry_CLOSE:
if rep.opts.HonorTime {
time.Sleep(time.Duration(e.delay))
}
rep.srp.NextClose(e.refIndex)

default:
Expand Down