Repository: etcd-io/etcd
File: tests/robustness/model/history.go (Go)

Code before:
}

func (h *AppendableHistory) appendFailed(request EtcdRequest, start, end time.Duration, err error) {
	op := porcupine.Operation{
		ClientId: h.streamID,
		Input:    request,
		Call:     start.Nanoseconds(),
		Output:   failedResponse(err),
		Return:   end.Nanoseconds(),
	}
	isRead := request.IsRead()
	if !isRead {
		// Failed writes can still be persisted, setting -1 for now as don't know when request has took effect.
		op.Return = math.MaxInt64
		// 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 stream id.
		h.streamID = h.idProvider.NewStreamID()
	}
	h.append(op)
}

func (h *AppendableHistory) append(op porcupine.Operation) {
	if op.Return != math.MaxInt64 && op.Call >= op.Return {
		panic(fmt.Sprintf("Invalid operation, call(%d) >= return(%d)", op.Call, op.Return))
	}
	if len(h.operations) > 0 {
		// TODO: check the client ID
		prev := h.operations[len(h.operations)-1]
		if op.Call <= prev.Call {
			panic(fmt.Sprintf("Out of order append, new.call(%d) <= prev.call(%d)", op.Call, prev.Call))
		}
		// if op.Call <= prev.Return {
		// 	panic(fmt.Sprintf("Overlapping operations, new.call(%d) <= prev.return(%d)", op.Call, prev.Return))
		// }
	}
	h.operations = append(h.operations, op)
}

func getRequest(key string) EtcdRequest {
	return rangeRequest(key, "", 0)
}

func staleGetRequest(key string, revision int64) EtcdRequest {
	return staleRangeRequest(key, "", 0, revision)
}

func rangeRequest(start, end string, limit int64) EtcdRequest {
	return staleRangeRequest(start, end, limit, 0)
}

func listRequest(key string, limit int64) EtcdRequest {

Review comment (suggestion):
```suggestion
	if len(h.operations) > 0 && op.ClientId == h.operations[len(h.operations)-1].ClientId {
```

Code after:
}

func (h *AppendableHistory) appendFailed(request EtcdRequest, start, end time.Duration, err error) {
	op := porcupine.Operation{
		ClientId: h.streamID,
		Input:    request,
		Call:     start.Nanoseconds(),
		Output:   failedResponse(err),
		Return:   end.Nanoseconds(),
	}
	isRead := request.IsRead()
	if !isRead {
		// Failed writes can still be persisted, setting -1 for now as don't know when request has took effect.
		op.Return = math.MaxInt64
		// 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 stream id.
		h.streamID = h.idProvider.NewStreamID()
	}
	h.append(op)
}

func (h *AppendableHistory) append(op porcupine.Operation) {
	if op.Return != math.MaxInt64 && op.Call >= op.Return {
		panic(fmt.Sprintf("Invalid operation, call(%d) >= return(%d)", op.Call, op.Return))
	}

	if len(h.operations) > 0 && op.ClientId == h.operations[len(h.operations)-1].ClientId {
		prev := h.operations[len(h.operations)-1]
		if op.Call <= prev.Call {
			panic(fmt.Sprintf("Out of order append, new.call(%d) <= prev.call(%d)", op.Call, prev.Call))
		}
		if op.Call <= prev.Return {
			panic(fmt.Sprintf("Overlapping operations, new.call(%d) <= prev.return(%d)", op.Call, prev.Return))
		}
	}
	h.operations = append(h.operations, op)
}

func getRequest(key string) EtcdRequest {
	return rangeRequest(key, "", 0)
}

func staleGetRequest(key string, revision int64) EtcdRequest {
	return staleRangeRequest(key, "", 0, revision)
}

func rangeRequest(start, end string, limit int64) EtcdRequest {
	return staleRangeRequest(start, end, limit, 0)
}

func listRequest(key string, limit int64) EtcdRequest {