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

Code before:
	replay := model.NewReplay(persistedRequests)

	err = validateWatch(lg, cfg, reports, replay)
	if err != nil {
		t.Errorf("Failed validating watch history, err: %s", err)
	}
	err = validateSerializableOperations(lg, serializableOperations, replay)
	if err != nil {
		t.Errorf("Failed validating serializable operations, err: %s", err)
	}
	return results
}

type Config struct {
	ExpectRevisionUnique bool
}

func prepareAndCategorizeOperations(reports []report.ClientReport) ([]porcupine.Operation, []porcupine.Operation) {
	patchedOperations := patchFailedRequestWithInfiniteReturnTime(reports)
	return relevantOperations(patchedOperations), filterSerializableOperations(patchedOperations)
}

func relevantOperations(operations []porcupine.Operation) []porcupine.Operation {
	var ops []porcupine.Operation
	for _, op := range operations {
		request := op.Input.(model.EtcdRequest)
		resp := op.Output.(model.MaybeEtcdResponse)
		// Remove failed read requests as they are not relevant for linearization.
		if resp.Error == "" || !request.IsRead() {
			ops = append(ops, op)
		}
	}
	return ops
}

func filterSerializableOperations(operations []porcupine.Operation) []porcupine.Operation {
	resp := []porcupine.Operation{}
	for _, op := range operations {
		request := op.Input.(model.EtcdRequest)
		if request.Type == model.Range && request.Range.Revision != 0 {
			resp = append(resp, op)
		}
	}
	return resp
}

func patchFailedRequestWithInfiniteReturnTime(reports []report.ClientReport) []porcupine.Operation {
	operations := make([]porcupine.Operation, 0)
	for _, report := range reports {
		for _, operation := range report.KeyValue {
			// Failed writes can still be persisted, setting to infinite for now as we don't know when request has taken effect.

Review comment (suggestion):
```suggestion
func filterLinearizableOperations(operations []porcupine.Operation) []porcupine.Operation {
```

Code after:
	}

	// TODO: Use requests from linearization for replay.
	replay := model.NewReplay(persistedRequests)

	err = validateWatch(lg, cfg, reports, replay)
	if err != nil {
		t.Errorf("Failed validating watch history, err: %s", err)
	}
	err = validateSerializableOperations(lg, serializableOperations, replay)
	if err != nil {
		t.Errorf("Failed validating serializable operations, err: %s", err)
	}
	return results
}

type Config struct {
	ExpectRevisionUnique bool
}

func prepareAndCategorizeOperations(reports []report.ClientReport) ([]porcupine.Operation, []porcupine.Operation) {
	patchedOperations := patchFailedRequestWithInfiniteReturnTime(reports)
	return relevantOperations(patchedOperations), filterSerializableOperations(patchedOperations)
}

func relevantOperations(operations []porcupine.Operation) []porcupine.Operation {
	var ops []porcupine.Operation
	for _, op := range operations {
		request := op.Input.(model.EtcdRequest)
		resp := op.Output.(model.MaybeEtcdResponse)
		// Remove failed read requests as they are not relevant for linearization.
		if resp.Error == "" || !request.IsRead() {
			ops = append(ops, op)
		}
	}
	return ops
}

func filterSerializableOperations(operations []porcupine.Operation) []porcupine.Operation {
	resp := []porcupine.Operation{}
	for _, op := range operations {
		request := op.Input.(model.EtcdRequest)
		if request.Type == model.Range && request.Range.Revision != 0 {
			resp = append(resp, op)
		}
	}
	return resp
}

func patchFailedRequestWithInfiniteReturnTime(reports []report.ClientReport) []porcupine.Operation {
	operations := make([]porcupine.Operation, 0)