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
d1dd25122a
commit
6d35d21f60
2 changed files with 9 additions and 2 deletions
|
@ -2,11 +2,18 @@ package logstorage
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"math"
|
||||||
"reflect"
|
"reflect"
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"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) {
|
func TestMarshalUnmarshalStringsBlock(t *testing.T) {
|
||||||
f := func(logs string, blockLenExpected int) {
|
f := func(logs string, blockLenExpected int) {
|
||||||
t.Helper()
|
t.Helper()
|
||||||
|
@ -15,7 +22,7 @@ func TestMarshalUnmarshalStringsBlock(t *testing.T) {
|
||||||
a = strings.Split(logs, "\n")
|
a = strings.Split(logs, "\n")
|
||||||
}
|
}
|
||||||
data := marshalStringsBlock(nil, a)
|
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)
|
t.Fatalf("unexpected block length; got %d; want %d; block=%q", len(data), blockLenExpected, data)
|
||||||
}
|
}
|
||||||
sbu := getStringsBlockUnmarshaler()
|
sbu := getStringsBlockUnmarshaler()
|
||||||
|
|
|
@ -93,7 +93,7 @@ func TestInmemoryPartMustInitFromRows(t *testing.T) {
|
||||||
func checkCompressionRate(t *testing.T, ph *partHeader, compressionRateExpected float64) {
|
func checkCompressionRate(t *testing.T, ph *partHeader, compressionRateExpected float64) {
|
||||||
t.Helper()
|
t.Helper()
|
||||||
compressionRate := float64(ph.UncompressedSizeBytes) / float64(ph.CompressedSizeBytes)
|
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)
|
t.Fatalf("unexpected compression rate; got %.1f; want %.1f", compressionRate, compressionRateExpected)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue