lib/logstorage: fix make test-pure tests

This commit is contained in:
Aliaksandr Valialkin 2023-07-04 13:14:30 -07:00
parent d1dd25122a
commit 6d35d21f60
No known key found for this signature in database
GPG key ID: A72BEC6CD3D0DED1
2 changed files with 9 additions and 2 deletions

View file

@ -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()

View file

@ -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)
}
}