tests: Refactor append failed requests

Signed-off-by: Marek Siarkowicz <siarkowicz@google.com>
This commit is contained in:
Marek Siarkowicz 2022-12-06 10:11:15 +01:00
parent 619ca4f5cf
commit 5ff9202027

View File

@ -55,17 +55,9 @@ 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) { func (h *appendableHistory) AppendPut(key, value string, start, end time.Time, resp *clientv3.PutResponse, err error) {
request := EtcdRequest{Op: Put, Key: key, PutData: value}
if err != nil { if err != nil {
h.failed = append(h.failed, porcupine.Operation{ h.appendFailed(request, start, err)
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()
return return
} }
var revision int64 var revision int64
@ -82,17 +74,9 @@ 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) { func (h *appendableHistory) AppendDelete(key string, start, end time.Time, resp *clientv3.DeleteResponse, err error) {
request := EtcdRequest{Op: Delete, Key: key}
if err != nil { if err != nil {
h.failed = append(h.failed, porcupine.Operation{ h.appendFailed(request, start, err)
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()
return return
} }
var revision int64 var revision int64
@ -103,13 +87,26 @@ func (h *appendableHistory) AppendDelete(key string, start, end time.Time, resp
} }
h.successful = append(h.successful, porcupine.Operation{ h.successful = append(h.successful, porcupine.Operation{
ClientId: h.id, ClientId: h.id,
Input: EtcdRequest{Op: Delete, Key: key}, Input: request,
Call: start.UnixNano(), Call: start.UnixNano(),
Output: EtcdResponse{Revision: revision, Deleted: deleted, Err: err}, Output: EtcdResponse{Revision: revision, Deleted: deleted, Err: err},
Return: end.UnixNano(), Return: end.UnixNano(),
}) })
} }
func (h *appendableHistory) appendFailed(request EtcdRequest, start time.Time, err error) {
h.failed = append(h.failed, porcupine.Operation{
ClientId: h.id,
Input: request,
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 { type history struct {
successful []porcupine.Operation successful []porcupine.Operation
// failed requests are kept separate as we don't know return time of failed operations. // failed requests are kept separate as we don't know return time of failed operations.