From 9cfb6f558ab7ee520f9194b5cbb0c86a90f677c2 Mon Sep 17 00:00:00 2001 From: Tanner Stirrat Date: Thu, 12 Sep 2024 10:01:39 -0600 Subject: [PATCH] Remaining lint fixes --- internal/cmd/restorer.go | 4 +++- internal/cmd/restorer_test.go | 6 +++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/internal/cmd/restorer.go b/internal/cmd/restorer.go index 666ddda..acf042d 100644 --- a/internal/cmd/restorer.go +++ b/internal/cmd/restorer.go @@ -195,6 +195,8 @@ func (r *restorer) restoreFromDecoder(ctx context.Context) error { } totalTime := time.Since(relationshipWriteStart) + // This shouldn't realistically overflow. + writtenAndSkipped, _ := safecast.ToUint64(r.writtenRels + r.skippedRels) log.Info(). Int64("batches", r.writtenBatches). Int64("relationships_loaded", r.writtenRels). @@ -202,7 +204,7 @@ func (r *restorer) restoreFromDecoder(ctx context.Context) error { Int64("duplicate_relationships", r.duplicateRels). Int64("relationships_filtered_out", r.filteredOutRels). Int64("retried_errors", r.totalRetries). - Uint64("perSecond", perSec(uint64(r.writtenRels+r.skippedRels), totalTime)). + Uint64("perSecond", perSec(writtenAndSkipped, totalTime)). Stringer("duration", totalTime). Msg("finished restore") return nil diff --git a/internal/cmd/restorer_test.go b/internal/cmd/restorer_test.go index 341fe5d..617a5fd 100644 --- a/internal/cmd/restorer_test.go +++ b/internal/cmd/restorer_test.go @@ -174,11 +174,15 @@ func TestRestorer(t *testing.T) { require.Equal(expectedTouchedRels, c.touchedRels, "unexpected number of touched commits") // assert on restorer stats + uintExpectedConflicts, err := safecast.ToUint(expectedConflicts) + require.NoError(err) + uintDuplicateBatches, err := safecast.ToUint(r.duplicateBatches) + require.NoError(err) require.Equal(expectedWrittenRels, int(r.writtenRels), "unexpected number of written relationships") require.Equal(expectedWrittenBatches, int(r.writtenBatches), "unexpected number of written relationships") require.Equal(expectedSkippedBatches, int(r.skippedBatches), "unexpected number of conflicting batches skipped") require.Equal(expectedSkippedRels, int(r.skippedRels), "unexpected number of conflicting relationships skipped") - require.Equal(uint(expectedConflicts)*tt.batchesPerTransaction, uint(r.duplicateBatches), "unexpected number of duplicate batches detected") + require.Equal(uintExpectedConflicts*tt.batchesPerTransaction, uintDuplicateBatches, "unexpected number of duplicate batches detected") require.Equal(expectedConflicts*batchesPerTransaction*tt.batchSize, int(r.duplicateRels), "unexpected number of duplicate relationships detected") require.Equal(int64(expectedRetries+expectedConflicts-expectedSkippedBatches), r.totalRetries, "unexpected number of retries") require.Equal(len(tt.relationships)-len(expectedFilteredRels), int(r.filteredOutRels), "unexpected number of filtered out relationships")