Skip to content

Commit

Permalink
tests: Refactor append failed requests
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 6, 2022
1 parent 619ca4f commit 16fdca7
Showing 1 changed file with 15 additions and 20 deletions.
35 changes: 15 additions & 20 deletions tests/linearizability/history.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,16 +56,7 @@ func (h *appendableHistory) AppendGet(key string, start, end time.Time, resp *cl

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,
Input: EtcdRequest{Op: Put, Key: key, PutData: value},
Call: start.UnixNano(),
Output: EtcdResponse{Err: err},
Return: 0, // For failed writes we don't know when request has really finished.
})
// Operations of single client needs to be sequential.
// As we don't know return time of failed operations, all new writes need to be done with new client id.
h.id = h.idProvider.ClientId()
h.appendFailed(Put, key, start, err)
return
}
var revision int64
Expand All @@ -83,16 +74,7 @@ func (h *appendableHistory) AppendPut(key, value string, start, end time.Time, r

func (h *appendableHistory) AppendDelete(key string, start, end time.Time, resp *clientv3.DeleteResponse, err error) {
if err != nil {
h.failed = append(h.failed, porcupine.Operation{
ClientId: h.id,
Input: EtcdRequest{Op: Delete, Key: key},
Call: start.UnixNano(),
Output: EtcdResponse{Err: err},
Return: 0, // For failed writes we don't know when request has really finished.
})
// Operations of single client needs to be sequential.
// As we don't know return time of failed operations, all new writes need to be done with new client id.
h.id = h.idProvider.ClientId()
h.appendFailed(Delete, key, start, err)
return
}
var revision int64
Expand All @@ -110,6 +92,19 @@ func (h *appendableHistory) AppendDelete(key string, start, end time.Time, resp
})
}

func (h *appendableHistory) appendFailed(op Operation, key string, start time.Time, err error) {
h.failed = append(h.failed, porcupine.Operation{
ClientId: h.id,
Input: EtcdRequest{Op: op, Key: key},
Call: start.UnixNano(),
Output: EtcdResponse{Err: err},
Return: 0, // For failed writes we don't know when request has really finished.
})
// Operations of single client needs to be sequential.
// As we don't know return time of failed operations, all new writes need to be done with new client id.
h.id = h.idProvider.ClientId()
}

type history struct {
successful []porcupine.Operation
// failed requests are kept separate as we don't know return time of failed operations.
Expand Down

0 comments on commit 16fdca7

Please sign in to comment.