From 3b50b94f7a0e831bf37e9383ff668aeeb88370e3 Mon Sep 17 00:00:00 2001 From: Aliaksandr Valialkin Date: Thu, 13 Jul 2023 15:01:56 -0700 Subject: [PATCH] lib/storage: fix possible test failure in TestStorageAddRowsConcurrent The number of parts in the snapshot partition may be zero if concurrent goroutine just started creating new partition, but didn't put data into it yet when the current goroutine made a snapshot. --- lib/storage/storage_test.go | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/lib/storage/storage_test.go b/lib/storage/storage_test.go index ca165d4ba..27129b325 100644 --- a/lib/storage/storage_test.go +++ b/lib/storage/storage_test.go @@ -988,7 +988,7 @@ func testStorageAddRows(rng *rand.Rand, s *Storage) error { const addsCount = 10 maxTimestamp := timestampFromTime(time.Now()) - minTimestamp := maxTimestamp - s.retentionMsecs + minTimestamp := maxTimestamp - s.retentionMsecs + 3600*1000 for i := 0; i < addsCount; i++ { mrs := testGenerateMetricRows(rng, rowsPerAdd, minTimestamp, maxTimestamp) if err := s.AddRows(mrs, defaultPrecisionBits); err != nil { @@ -1030,7 +1030,9 @@ func testStorageAddRows(rng *rand.Rand, s *Storage) error { return fmt.Errorf("snapshot %q must contain at least %d rows; got %d", snapshotPath, minRowsExpected, rowsCount) } - // Verify that force merge for the snapshot leaves only a single part per partition. + // Verify that force merge for the snapshot leaves at most a single part per partition. + // Zero parts are possible if the snapshot is created just after the partition has been created + // by concurrent goroutine, but it didn't put the data into it yet. if err := s1.ForceMergePartitions(""); err != nil { return fmt.Errorf("error when force merging partitions: %w", err) } @@ -1039,9 +1041,9 @@ func testStorageAddRows(rng *rand.Rand, s *Storage) error { pws := ptw.pt.GetParts(nil, true) numParts := len(pws) ptw.pt.PutParts(pws) - if numParts != 1 { + if numParts > 1 { s1.tb.PutPartitions(ptws) - return fmt.Errorf("unexpected number of parts for partition %q after force merge; got %d; want 1", ptw.pt.name, numParts) + return fmt.Errorf("unexpected number of parts for partition %q after force merge; got %d; want at most 1", ptw.pt.name, numParts) } } s1.tb.PutPartitions(ptws)