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

Code before:
	clientCompactCount := countClientCompacts(reports)

	putReturnTime, delReturnTime, compactReturnTime := uniqueOperationReturnTime(operations, persistedRequests, clientPutCount, clientDeleteCount, clientCompactCount)

	putArgs := make(map[model.PutOptions]patchArgs)
	for opts, c := range clientPutCount {
		putArgs[opts] = patchArgs{
			clientCount:    c,
			persistedCount: persistedPutCount[opts],
			returnTime:     putReturnTime[opts],
			revision:       putRevision[opts],
		}
	}
	delArgs := make(map[model.DeleteOptions]patchArgs)
	for opts, c := range clientDeleteCount {
		delArgs[opts] = patchArgs{
			clientCount:    c,
			persistedCount: persistedDeleteCount[opts],
			returnTime:     delReturnTime[opts],
		}
	}
	compactArgs := make(map[model.CompactOptions]patchArgs)
	for opts, c := range clientCompactCount {
		compactArgs[opts] = patchArgs{
			clientCount:    c,
			persistedCount: persistedCompactCount[opts],
			returnTime:     compactReturnTime[opts],
		}
	}

	return patchOperations(
		operations, putArgs, delArgs, compactArgs,
	)
}

func watchRevisions(reports []report.ClientReport) map[model.PutOptions]int64 {
	putRevisions := map[model.PutOptions]int64{}

	for _, client := range reports {
		for _, watch := range client.Watch {
			for _, resp := range watch.Responses {
				for _, event := range resp.Events {
					switch event.Type {
					case model.RangeOperation:
					case model.PutOperation:
						kv := model.PutOptions{Key: event.Key, Value: event.Value}
						putRevisions[kv] = event.Revision
					case model.DeleteOperation:
						// Don't track delete revisions - they can be triggered by leaseRevoke
						// So we can't reliably attribute them to explicit delete operations
					case model.CompactOperation:

Review comment (suggestion):
Removal of DeleteOptions is a good cleanup regardless of adding a feature. Please consider sending a separate PR to speed up review and merge process.

Code after:
	clientCompactCount := countClientCompacts(reports)

	putReturnTime, delReturnTime, compactReturnTime := uniqueOperationReturnTime(operations, persistedRequests, clientPutCount, clientDeleteCount, clientCompactCount)

	putArgs := make(map[model.PutOptions]patchArgs)
	for opts, c := range clientPutCount {
		putArgs[opts] = patchArgs{
			clientCount:    c,
			persistedCount: persistedPutCount[opts],
			returnTime:     putReturnTime[opts],
			revision:       putRevision[opts],
		}
	}
	delArgs := make(map[model.DeleteOptions]patchArgs)
	for opts, c := range clientDeleteCount {
		delArgs[opts] = patchArgs{
			clientCount:    c,
			persistedCount: persistedDeleteCount[opts],
			returnTime:     delReturnTime[opts],
		}
	}
	compactArgs := make(map[model.CompactRequest]patchArgs)
	for opts, c := range clientCompactCount {
		compactArgs[opts] = patchArgs{
			clientCount:    c,
			persistedCount: persistedCompactCount[opts],
			returnTime:     compactReturnTime[opts],
		}
	}

	return patchOperations(
		operations, putArgs, delArgs, compactArgs,
	)
}

func watchRevisions(reports []report.ClientReport) map[model.PutOptions]int64 {
	putRevisions := map[model.PutOptions]int64{}

	for _, client := range reports {
		for _, watch := range client.Watch {
			for _, resp := range watch.Responses {
				for _, event := range resp.Events {
					switch event.Type {
					case model.RangeOperation:
					case model.PutOperation:
						kv := model.PutOptions{Key: event.Key, Value: event.Value}
						putRevisions[kv] = event.Revision
					case model.DeleteOperation:
						// Delete events are also created by leaseRevoke rquest.
					default:
						panic(fmt.Sprintf("unknown event type %q", event.Type))