Skip to content

Commit

Permalink
tests: Fix return time for failed requests globally
Browse files Browse the repository at this point in the history
Signed-off-by: Marek Siarkowicz <siarkowicz@google.com>
  • Loading branch information
serathius committed Dec 5, 2022
1 parent ec72022 commit 9d03a46
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 14 deletions.
4 changes: 2 additions & 2 deletions tests/linearizability/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import (

type recordingClient struct {
client clientv3.Client
history *history
history *appendableHistory
}

func NewClient(endpoints []string, ids idProvider) (*recordingClient, error) {
Expand All @@ -39,7 +39,7 @@ func NewClient(endpoints []string, ids idProvider) (*recordingClient, error) {
}
return &recordingClient{
client: *cc,
history: NewHistory(ids),
history: newAppendableHistory(ids),
}, nil
}

Expand Down
38 changes: 28 additions & 10 deletions tests/linearizability/history.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,25 +21,26 @@ import (
clientv3 "go.etcd.io/etcd/client/v3"
)

type history struct {
type appendableHistory struct {
// id of the next write operation. If needed a new id might be requested from idProvider.
id int
idProvider idProvider

operations []porcupine.Operation
failed []porcupine.Operation
history
}

func NewHistory(ids idProvider) *history {
return &history{
func newAppendableHistory(ids idProvider) *appendableHistory {
return &appendableHistory{
id: ids.ClientId(),
idProvider: ids,
operations: []porcupine.Operation{},
failed: []porcupine.Operation{},
history: history{
operations: []porcupine.Operation{},
failed: []porcupine.Operation{},
},
}
}

func (h *history) AppendGet(key string, start, end time.Time, resp *clientv3.GetResponse) {
func (h *appendableHistory) AppendGet(key string, start, end time.Time, resp *clientv3.GetResponse) {
var readData string
if len(resp.Kvs) == 1 {
readData = string(resp.Kvs[0].Value)
Expand All @@ -53,7 +54,7 @@ func (h *history) AppendGet(key string, start, end time.Time, resp *clientv3.Get
})
}

func (h *history) AppendPut(key, value string, start, end time.Time, resp *clientv3.PutResponse, err error) {
func (h *appendableHistory) AppendPut(key, value string, start, end time.Time, resp *clientv3.PutResponse, err error) {
if err != nil {
h.failed = append(h.failed, porcupine.Operation{
ClientId: h.id,
Expand All @@ -79,7 +80,24 @@ func (h *history) AppendPut(key, value string, start, end time.Time, resp *clien
})
}

func (h *history) Operations() []porcupine.Operation {
type history struct {
operations []porcupine.Operation
failed []porcupine.Operation
}

func (h history) Merge(h2 history) history {
result := history{
operations: make([]porcupine.Operation, 0, len(h.operations)+len(h2.operations)),
failed: make([]porcupine.Operation, 0, len(h.failed)+len(h2.failed)),
}
result.operations = append(result.operations, h.operations...)
result.operations = append(result.operations, h2.operations...)
result.failed = append(result.failed, h.failed...)
result.failed = append(result.failed, h2.failed...)
return result
}

func (h history) Operations() []porcupine.Operation {
operations := make([]porcupine.Operation, 0, len(h.operations)+len(h.failed))
var maxTime int64
for _, op := range h.operations {
Expand Down
6 changes: 4 additions & 2 deletions tests/linearizability/linearizability_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,11 +140,12 @@ type FailpointConfig struct {
waitBetweenTriggers time.Duration
}

func simulateTraffic(ctx context.Context, t *testing.T, clus *e2e.EtcdProcessCluster, config trafficConfig) (operations []porcupine.Operation) {
func simulateTraffic(ctx context.Context, t *testing.T, clus *e2e.EtcdProcessCluster, config trafficConfig) []porcupine.Operation {
mux := sync.Mutex{}
endpoints := clus.EndpointsV3()

ids := newIdProvider()
h := history{}
limiter := rate.NewLimiter(rate.Limit(config.maximalQPS), 200)

startTime := time.Now()
Expand All @@ -162,12 +163,13 @@ func simulateTraffic(ctx context.Context, t *testing.T, clus *e2e.EtcdProcessClu

config.traffic.Run(ctx, c, limiter, ids)
mux.Lock()
operations = append(operations, c.history.Operations()...)
h = h.Merge(c.history.history)
mux.Unlock()
}(c)
}
wg.Wait()
endTime := time.Now()
operations := h.Operations()
t.Logf("Recorded %d operations", len(operations))

qps := float64(len(operations)) / float64(endTime.Sub(startTime)) * float64(time.Second)
Expand Down

0 comments on commit 9d03a46

Please sign in to comment.