@@ -92,6 +92,7 @@ func Test_Unordered_InsertRetrieval(t *testing.T) {
9292 input , exp []entry
9393 dir logproto.Direction
9494 hasDup bool
95+ forFormat HeadBlockFmt
9596 }{
9697 {
9798 desc : "simple forward" ,
@@ -131,6 +132,50 @@ func Test_Unordered_InsertRetrieval(t *testing.T) {
131132 },
132133 dir : logproto .BACKWARD ,
133134 },
135+ {
136+ desc : "different structured metadata forward" ,
137+ input : []entry {
138+ {0 , "a" , labels .EmptyLabels ()}, {1 , "b" , labels .EmptyLabels ()}, {0 , "a" , labels .FromStrings ("a" , "b" )},
139+ },
140+ exp : []entry {
141+ {0 , "a" , labels .FromStrings ("a" , "b" )}, {0 , "a" , labels .EmptyLabels ()}, {1 , "b" , labels .EmptyLabels ()},
142+ },
143+ forFormat : UnorderedWithStructuredMetadataHeadBlockFmt ,
144+ },
145+ {
146+ desc : "different structured metadata backward" ,
147+ input : []entry {
148+ {0 , "a" , labels .EmptyLabels ()}, {1 , "b" , labels .EmptyLabels ()}, {0 , "a" , labels .FromStrings ("a" , "b" )},
149+ },
150+ exp : []entry {
151+ {1 , "b" , labels .EmptyLabels ()}, {0 , "a" , labels .EmptyLabels ()}, {0 , "a" , labels .FromStrings ("a" , "b" )},
152+ },
153+ dir : logproto .BACKWARD ,
154+ forFormat : UnorderedWithStructuredMetadataHeadBlockFmt ,
155+ },
156+ {
157+ desc : "different structured metadata forward" ,
158+ input : []entry {
159+ {0 , "a" , labels .EmptyLabels ()}, {1 , "b" , labels .EmptyLabels ()}, {0 , "a" , labels .FromStrings ("a" , "b" )},
160+ },
161+ exp : []entry {
162+ {0 , "a" , labels .EmptyLabels ()}, {1 , "b" , labels .EmptyLabels ()},
163+ },
164+ hasDup : true ,
165+ forFormat : UnorderedHeadBlockFmt ,
166+ },
167+ {
168+ desc : "different structured metadata backward" ,
169+ input : []entry {
170+ {0 , "a" , labels .EmptyLabels ()}, {1 , "b" , labels .EmptyLabels ()}, {0 , "a" , labels .FromStrings ("a" , "b" )},
171+ },
172+ exp : []entry {
173+ {1 , "b" , labels .EmptyLabels ()}, {0 , "a" , labels .EmptyLabels ()},
174+ },
175+ dir : logproto .BACKWARD ,
176+ hasDup : true ,
177+ forFormat : UnorderedHeadBlockFmt ,
178+ },
134179 {
135180 desc : "ts collision forward" ,
136181 input : []entry {
@@ -153,7 +198,7 @@ func Test_Unordered_InsertRetrieval(t *testing.T) {
153198 {
154199 desc : "ts remove exact dupe forward" ,
155200 input : []entry {
156- {0 , "a" , labels .EmptyLabels ()}, {0 , "b" , labels .EmptyLabels ()}, {1 , "c" , labels .EmptyLabels ()}, {0 , "b" , labels .FromStrings ( "a" , "b" )},
201+ {0 , "a" , labels .EmptyLabels ()}, {0 , "b" , labels .EmptyLabels ()}, {1 , "c" , labels .EmptyLabels ()}, {0 , "b" , labels .EmptyLabels ( )},
157202 },
158203 exp : []entry {
159204 {0 , "a" , labels .EmptyLabels ()}, {0 , "b" , labels .EmptyLabels ()}, {1 , "c" , labels .EmptyLabels ()},
@@ -164,7 +209,7 @@ func Test_Unordered_InsertRetrieval(t *testing.T) {
164209 {
165210 desc : "ts remove exact dupe backward" ,
166211 input : []entry {
167- {0 , "a" , labels .EmptyLabels ()}, {0 , "b" , labels .EmptyLabels ()}, {1 , "c" , labels .EmptyLabels ()}, {0 , "b" , labels .FromStrings ( "a" , "b" )},
212+ {0 , "a" , labels .EmptyLabels ()}, {0 , "b" , labels .EmptyLabels ()}, {1 , "c" , labels .EmptyLabels ()}, {0 , "b" , labels .EmptyLabels ( )},
168213 },
169214 exp : []entry {
170215 {1 , "c" , labels .EmptyLabels ()}, {0 , "b" , labels .EmptyLabels ()}, {0 , "a" , labels .EmptyLabels ()},
@@ -178,38 +223,40 @@ func Test_Unordered_InsertRetrieval(t *testing.T) {
178223 UnorderedHeadBlockFmt ,
179224 UnorderedWithStructuredMetadataHeadBlockFmt ,
180225 } {
181- t .Run (format .String (), func (t * testing.T ) {
182- hb := newUnorderedHeadBlock (format , newSymbolizer ())
183- dup := false
184- for _ , e := range tc .input {
185- tmpdup , err := hb .Append (e .t , e .s , e .structuredMetadata )
186- if ! dup { // only set dup if it's not already true
187- if tmpdup { // can't examine duplicates until we start getting all the data
188- dup = true
226+ if tc .forFormat == 0 || tc .forFormat == format {
227+ t .Run (format .String (), func (t * testing.T ) {
228+ hb := newUnorderedHeadBlock (format , newSymbolizer ())
229+ dup := false
230+ for _ , e := range tc .input {
231+ tmpdup , err := hb .Append (e .t , e .s , e .structuredMetadata )
232+ if ! dup { // only set dup if it's not already true
233+ if tmpdup { // can't examine duplicates until we start getting all the data
234+ dup = true
235+ }
189236 }
237+ require .Nil (t , err )
190238 }
191- require .Nil (t , err )
192- }
193- require .Equal (t , tc .hasDup , dup )
194-
195- itr := hb .Iterator (
196- context .Background (),
197- tc .dir ,
198- 0 ,
199- math .MaxInt64 ,
200- noopStreamPipeline ,
201- )
202-
203- expected := make ([]entry , len (tc .exp ))
204- copy (expected , tc .exp )
205- if format < UnorderedWithStructuredMetadataHeadBlockFmt {
206- for i := range expected {
207- expected [i ].structuredMetadata = labels .EmptyLabels ()
239+ require .Equal (t , tc .hasDup , dup )
240+
241+ itr := hb .Iterator (
242+ context .Background (),
243+ tc .dir ,
244+ 0 ,
245+ math .MaxInt64 ,
246+ noopStreamPipeline ,
247+ )
248+
249+ expected := make ([]entry , len (tc .exp ))
250+ copy (expected , tc .exp )
251+ if format < UnorderedWithStructuredMetadataHeadBlockFmt {
252+ for i := range expected {
253+ expected [i ].structuredMetadata = labels .EmptyLabels ()
254+ }
208255 }
209- }
210256
211- iterEq (t , expected , itr )
212- })
257+ iterEq (t , expected , itr )
258+ })
259+ }
213260 }
214261 })
215262 }
0 commit comments