@ -38,6 +38,7 @@ import (
"github.com/prometheus/prometheus/tsdb/tombstones"
"github.com/prometheus/prometheus/tsdb/tsdbutil"
"github.com/prometheus/prometheus/util/annotations"
"github.com/prometheus/prometheus/util/testutil"
)
// TODO(bwplotka): Replace those mocks with remote.concreteSeriesSet.
@ -3638,3 +3639,77 @@ func TestQueryWithOneChunkCompletelyDeleted(t *testing.T) {
require . NoError ( t , css . Err ( ) )
require . Equal ( t , 1 , seriesCount )
}
func TestReader_PostingsForLabelMatchingHonorsContextCancel ( t * testing . T ) {
ir := mockReaderOfLabels { }
failAfter := uint64 ( mockReaderOfLabelsSeriesCount / 2 / checkContextEveryNIterations )
ctx := & testutil . MockContextErrAfter { FailAfter : failAfter }
_ , err := labelValuesWithMatchers ( ctx , ir , "__name__" , labels . MustNewMatcher ( labels . MatchRegexp , "__name__" , ".+" ) )
require . Error ( t , err )
require . Equal ( t , failAfter + 1 , ctx . Count ( ) ) // Plus one for the Err() call that puts the error in the result.
}
func TestReader_InversePostingsForMatcherHonorsContextCancel ( t * testing . T ) {
ir := mockReaderOfLabels { }
failAfter := uint64 ( mockReaderOfLabelsSeriesCount / 2 / checkContextEveryNIterations )
ctx := & testutil . MockContextErrAfter { FailAfter : failAfter }
_ , err := inversePostingsForMatcher ( ctx , ir , labels . MustNewMatcher ( labels . MatchRegexp , "__name__" , ".*" ) )
require . Error ( t , err )
require . Equal ( t , failAfter + 1 , ctx . Count ( ) ) // Plus one for the Err() call that puts the error in the result.
}
type mockReaderOfLabels struct { }
const mockReaderOfLabelsSeriesCount = checkContextEveryNIterations * 10
func ( m mockReaderOfLabels ) LabelValues ( context . Context , string , ... * labels . Matcher ) ( [ ] string , error ) {
return make ( [ ] string , mockReaderOfLabelsSeriesCount ) , nil
}
func ( m mockReaderOfLabels ) LabelValueFor ( context . Context , storage . SeriesRef , string ) ( string , error ) {
panic ( "LabelValueFor called" )
}
func ( m mockReaderOfLabels ) SortedLabelValues ( context . Context , string , ... * labels . Matcher ) ( [ ] string , error ) {
panic ( "SortedLabelValues called" )
}
func ( m mockReaderOfLabels ) Close ( ) error {
return nil
}
func ( m mockReaderOfLabels ) LabelNames ( context . Context , ... * labels . Matcher ) ( [ ] string , error ) {
panic ( "LabelNames called" )
}
func ( m mockReaderOfLabels ) LabelNamesFor ( context . Context , ... storage . SeriesRef ) ( [ ] string , error ) {
panic ( "LabelNamesFor called" )
}
func ( m mockReaderOfLabels ) PostingsForLabelMatching ( context . Context , string , func ( string ) bool ) index . Postings {
panic ( "PostingsForLabelMatching called" )
}
func ( m mockReaderOfLabels ) Postings ( context . Context , string , ... string ) ( index . Postings , error ) {
panic ( "Postings called" )
}
func ( m mockReaderOfLabels ) ShardedPostings ( index . Postings , uint64 , uint64 ) index . Postings {
panic ( "Postings called" )
}
func ( m mockReaderOfLabels ) SortedPostings ( index . Postings ) index . Postings {
panic ( "SortedPostings called" )
}
func ( m mockReaderOfLabels ) Series ( storage . SeriesRef , * labels . ScratchBuilder , * [ ] chunks . Meta ) error {
panic ( "Series called" )
}
func ( m mockReaderOfLabels ) Symbols ( ) index . StringIter {
panic ( "Series called" )
}