This is an automated email from the ASF dual-hosted git repository. hanahmily pushed a commit to branch measure-flusher in repository https://gitbox.apache.org/repos/asf/skywalking-banyandb.git
commit a17c43b5d8b2359eb412209c1b7f4d33e64fd744 Author: Gao Hongtao <[email protected]> AuthorDate: Sat Dec 23 08:56:46 2023 +0800 Fix part test Signed-off-by: Gao Hongtao <[email protected]> --- banyand/measure/part_iter_test.go | 62 ++++++++++++++++++++++++--------------- 1 file changed, 38 insertions(+), 24 deletions(-) diff --git a/banyand/measure/part_iter_test.go b/banyand/measure/part_iter_test.go index 37579062..4aa6d7a9 100644 --- a/banyand/measure/part_iter_test.go +++ b/banyand/measure/part_iter_test.go @@ -23,8 +23,11 @@ import ( "github.com/google/go-cmp/cmp" "github.com/google/go-cmp/cmp/cmpopts" + "github.com/stretchr/testify/require" "github.com/apache/skywalking-banyandb/api/common" + "github.com/apache/skywalking-banyandb/pkg/fs" + "github.com/apache/skywalking-banyandb/pkg/test" ) // TODO: test more scenarios. @@ -108,36 +111,47 @@ func Test_partIter_nextBlock(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - mp := generateMemPart() - releaseMemPart(mp) - mp.mustInitFromDataPoints(dps) + verifyPart := func(p *part) { + defer p.close() + pi := partIter{} + pi.init(p, tt.sids, tt.opt.minTimestamp, tt.opt.maxTimestamp) - p := openMemPart(mp) - - pi := partIter{} - pi.init(p, tt.sids, tt.opt.minTimestamp, tt.opt.maxTimestamp) + var got []blockMetadata + for pi.nextBlock() { + if pi.curBlock.seriesID == 0 { + t.Errorf("Expected currBlock to be initialized, but it was nil") + } + got = append(got, pi.curBlock) + } - var got []blockMetadata - for pi.nextBlock() { - if pi.curBlock.seriesID == 0 { - t.Errorf("Expected currBlock to be initialized, but it was nil") + if !errors.Is(pi.error(), tt.wantErr) { + t.Errorf("Unexpected error: got %v, want %v", pi.err, tt.wantErr) } - got = append(got, pi.curBlock) - } - if !errors.Is(pi.error(), tt.wantErr) { - t.Errorf("Unexpected error: got %v, want %v", pi.err, tt.wantErr) + if diff := cmp.Diff(got, tt.want, + cmpopts.IgnoreFields(blockMetadata{}, "uncompressedSizeBytes"), + cmpopts.IgnoreFields(blockMetadata{}, "timestamps"), + cmpopts.IgnoreFields(blockMetadata{}, "field"), + cmpopts.IgnoreFields(blockMetadata{}, "tagFamilies"), + cmp.AllowUnexported(blockMetadata{}), + ); diff != "" { + t.Errorf("Unexpected blockMetadata (-got +want):\n%s", diff) + } } + mp := generateMemPart() + releaseMemPart(mp) + mp.mustInitFromDataPoints(dps) - if diff := cmp.Diff(got, tt.want, - cmpopts.IgnoreFields(blockMetadata{}, "uncompressedSizeBytes"), - cmpopts.IgnoreFields(blockMetadata{}, "timestamps"), - cmpopts.IgnoreFields(blockMetadata{}, "field"), - cmpopts.IgnoreFields(blockMetadata{}, "tagFamilies"), - cmp.AllowUnexported(blockMetadata{}), - ); diff != "" { - t.Errorf("Unexpected blockMetadata (-got +want):\n%s", diff) - } + p := openMemPart(mp) + verifyPart(p) + tmpDir, defFn := test.Space(require.New(t)) + defer defFn() + epoch := uint64(1) + partPath := partPath(tmpDir, epoch) + fileSystem := fs.NewLocalFileSystem() + mp.mustFlush(fileSystem, partPath) + p = mustOpenFilePart(partPath, fileSystem) + verifyPart(p) }) } }
