[#149] selector: Add read timeout #151

Merged
dstepanov-yadro merged 1 commit from dstepanov-yadro/xk6-frostfs:feat/selector_timeout into master 2024-06-24 14:45:48 +00:00
Showing only changes of commit 335c45c578 - Show all commits

View file

@ -9,6 +9,8 @@ import (
"go.etcd.io/bbolt"
)
const nextObjectTimeout = 10 * time.Second
type ObjFilter struct {
Status string
Age int
@ -57,7 +59,16 @@ func NewObjSelector(registry *ObjRegistry, selectionSize int, kind SelectorKind,
// - underlying registry context is done, nil objects will be returned on the
// currently blocked and every further NextObject calls.
func (o *ObjSelector) NextObject() *ObjectInfo {
if o.kind == SelectorOneshot {
return <-o.objChan
}
select {
case <-time.After(nextObjectTimeout):
return nil
case obj := <-o.objChan:
return obj
}
}
// Count returns total number of objects that match filter of the selector.