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

Code before:
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package validate

import (
	"encoding/json"
	"fmt"
	"testing"
	"time"

	"github.com/anishathalye/porcupine"
	"github.com/stretchr/testify/require"
	"go.uber.org/zap"

	"go.etcd.io/etcd/tests/v3/robustness/model"
	"go.etcd.io/etcd/tests/v3/robustness/report"
)

func ValidateAndReturnVisualize(t *testing.T, lg *zap.Logger, cfg Config, reports []report.ClientReport, persistedRequests []model.EtcdRequest, timeout time.Duration) Results {
	err := checkValidationAssumptions(reports, persistedRequests)
	require.NoErrorf(t, err, "Broken validation assumptions")
	_ /* patchedReport */, linearizableOperations, serializableOperations := prepareAndCategorizeOperations(reports, persistedRequests)

	results := validateLinearizableOperationsAndVisualize(lg, linearizableOperations, timeout)
	if results.Linearizable != porcupine.Ok {
		t.Error("Failed linearization, skipping further validation")
		return results
	}

	// 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
}


Review comment (suggestion):
```suggestion
	linearizableOperations, serializableOperations := prepareAndCategorizeOperations(reports, persistedRequests)
	patchedLinearizableOperations := patchLinearizableOperations(report, persistedRequests)
```

Code after:
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package validate

import (
	"encoding/json"
	"fmt"
	"math"
	"testing"
	"time"

	"github.com/anishathalye/porcupine"
	"github.com/stretchr/testify/require"
	"go.uber.org/zap"

	"go.etcd.io/etcd/tests/v3/robustness/model"
	"go.etcd.io/etcd/tests/v3/robustness/report"
)

func ValidateAndReturnVisualize(t *testing.T, lg *zap.Logger, cfg Config, reports []report.ClientReport, persistedRequests []model.EtcdRequest, timeout time.Duration) Results {
	err := checkValidationAssumptions(reports, persistedRequests)
	require.NoErrorf(t, err, "Broken validation assumptions")
	linearizableOperations, serializableOperations := prepareAndCategorizeOperations(reports)
	// We are passing in the original reports and linearizableOperations with modified return time.
	// The reason is that linearizableOperations are those dedicated for linearization, which requires them to have returnTime set to infinity as required by pourcupine.
	// As for the report, the original report is used so the consumer doesn't need to track what patching was done or not.
	patchedLinearizableOperations := patchLinearizableOperations(linearizableOperations, reports, persistedRequests)

	results := validateLinearizableOperationsAndVisualize(lg, patchedLinearizableOperations, timeout)
	if results.Linearizable != porcupine.Ok {
		t.Error("Failed linearization, skipping further validation")
		return results
	}

	// 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
}