diff --git a/lib/logstorage/encoding_test.go b/lib/logstorage/encoding_test.go index 3050e531b..ee9ce808f 100644 --- a/lib/logstorage/encoding_test.go +++ b/lib/logstorage/encoding_test.go @@ -2,11 +2,18 @@ package logstorage import ( "fmt" + "math" "reflect" "strings" "testing" ) +func isAlmostEqual(a, b int) bool { + fa := float64(a) + fb := float64(b) + return math.Abs(fa-fb) <= math.Abs(fa+fb)*0.17 +} + func TestMarshalUnmarshalStringsBlock(t *testing.T) { f := func(logs string, blockLenExpected int) { t.Helper() @@ -15,7 +22,7 @@ func TestMarshalUnmarshalStringsBlock(t *testing.T) { a = strings.Split(logs, "\n") } data := marshalStringsBlock(nil, a) - if len(data) != blockLenExpected { + if !isAlmostEqual(len(data), blockLenExpected) { t.Fatalf("unexpected block length; got %d; want %d; block=%q", len(data), blockLenExpected, data) } sbu := getStringsBlockUnmarshaler() diff --git a/lib/logstorage/inmemory_part_test.go b/lib/logstorage/inmemory_part_test.go index 85b2c9f78..0f4fc1147 100644 --- a/lib/logstorage/inmemory_part_test.go +++ b/lib/logstorage/inmemory_part_test.go @@ -93,7 +93,7 @@ func TestInmemoryPartMustInitFromRows(t *testing.T) { func checkCompressionRate(t *testing.T, ph *partHeader, compressionRateExpected float64) { t.Helper() compressionRate := float64(ph.UncompressedSizeBytes) / float64(ph.CompressedSizeBytes) - if math.Abs(compressionRate-compressionRateExpected) > 0.1 { + if math.Abs(compressionRate-compressionRateExpected) > math.Abs(compressionRate+compressionRateExpected) * 0.05 { t.Fatalf("unexpected compression rate; got %.1f; want %.1f", compressionRate, compressionRateExpected) } }