mirror of
https://github.com/VictoriaMetrics/VictoriaMetrics.git
synced 2024-11-21 14:44:00 +00:00
lib/logstorage: fix make test-pure
tests
This commit is contained in:
parent
f2f9532fa5
commit
5a12a518a3
2 changed files with 9 additions and 2 deletions
|
@ -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()
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue