Skip to content

Commit

Permalink
protocol: return an error if no requests have been received by the proxy
Browse files Browse the repository at this point in the history
  • Loading branch information
roobre committed Aug 24, 2023
1 parent daa6376 commit 420ffa3
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions pkg/agent/protocol/protocol.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,16 @@ package protocol

import (
"context"
"errors"
"fmt"
"time"

"github.com/grafana/xk6-disruptor/pkg/runtime"
)

// ErrNoRequests is returned when a proxy supports MetricRequests and returns a value of 0 for it.
var ErrNoRequests = errors.New("disruptor did not receive any request")

// TrafficRedirector defines the interface for a traffic redirector
type TrafficRedirector interface {
// Start initiates the redirection of traffic and resets existing connections
Expand Down Expand Up @@ -103,6 +107,11 @@ func (d *disruptor) Apply(ctx context.Context, duration time.Duration) error {
return fmt.Errorf(" proxy ended with error: %w", err)
}
case <-time.After(duration):
requests, hasMetric := d.proxy.Metrics()[MetricRequests]
if hasMetric && requests == 0 {
return ErrNoRequests
}

return nil
case <-ctx.Done():
return ctx.Err()
Expand Down

0 comments on commit 420ffa3

Please sign in to comment.