Repository: dgraph-io/dgraph
File: dgraph/cmd/dgraphimport/import_test.go (Go)

Code before:
		maxRetries = 10
	}

	retryDelay := time.Second
	hasAllPredicates := true

	// Get expected predicates first
	var expectedSchemaObj map[string]interface{}
	require.NoError(t, json.Unmarshal([]byte(expectedSchema), &expectedSchemaObj))
	expectedPredicates := getPredicateMap(expectedSchemaObj)

	for i := 0; i < maxRetries; i++ {
		// Checking client connection again here because an import operation may be in progress on the rejoined alpha
		require.NoError(t, validateClientConnection(t, gc, 30*time.Second))

		schemaResp, err := gc.Query("schema{}")
		require.NoError(t, err)

		// Parse schema response
		var actualSchema map[string]interface{}
		require.NoError(t, json.Unmarshal(schemaResp.Json, &actualSchema))

		// Get actual predicates
		actualPredicates := getPredicateMap(actualSchema)

		hasAllPredicates := true
		// Check if all expected predicates are present
		for predName := range expectedPredicates {
			if _, exists := actualPredicates[predName]; !exists {
				hasAllPredicates = false
				break
			}
		}

		if hasAllPredicates {
			break
		}

		if i < maxRetries-1 {
			t.Logf("Not all predicates found yet, retrying in %v", retryDelay)
			time.Sleep(retryDelay)
			retryDelay *= 2
		}
	}

	if !hasAllPredicates {
		t.Fatalf("Not all predicates found in schema")
	}

	for _, tt := range common.OneMillionTCs {
		resp, err := gc.Query(tt.Query)

Review comment (suggestion):
This inline variable declaration shadows the one declared on line 382. When it's set on line 407 it has no effect on the test at 423, right? In essence this will always pass because the var on 382 is really never effected in this loop.

Code after:
	// Return cluster and client (cleanup will be handled by the caller)
	return cluster, gc, cleanup
}

// verifyImportResults validates the result of an import operation with retry logic
func verifyImportResults(t *testing.T, gc *dgraphapi.GrpcClient, downAlphas int) {
	maxRetries := 5
	if downAlphas > 0 {
		maxRetries = 10
	}

	retryDelay := time.Second

	// Get expected predicates first
	var expectedSchemaObj map[string]interface{}
	require.NoError(t, json.Unmarshal([]byte(expectedSchema), &expectedSchemaObj))
	expectedPredicates := getPredicateMap(expectedSchemaObj)
	var hasAllPredicates bool

	for i := 0; i < maxRetries; i++ {
		// Checking client connection again here because an import operation may be in progress on the rejoined alpha
		require.NoError(t, validateClientConnection(t, gc, 30*time.Second))

		schemaResp, err := gc.Query("schema{}")
		require.NoError(t, err)

		// Parse schema response
		var actualSchema map[string]interface{}
		require.NoError(t, json.Unmarshal(schemaResp.Json, &actualSchema))

		// Get actual predicates
		actualPredicates := getPredicateMap(actualSchema)

		hasAllPredicates = true
		for predName := range expectedPredicates {
			if _, exists := actualPredicates[predName]; !exists {
				hasAllPredicates = false
				break
			}
		}

		if hasAllPredicates {
			break
		}

		if i < maxRetries-1 {
			t.Logf("Not all predicates found yet, retrying in %v", retryDelay)
			time.Sleep(retryDelay)
			retryDelay *= 2
		}
	}