satellite/repair: Fix flaky test
Don't use global monkit.Default in Queue Stat test, or it can fail due to concurrently-executing tests. Change-Id: I061d626f26220705c8dd0de17ac7e14c81831d7f
This commit is contained in:
parent
5094100e21
commit
c87f380e2e
@ -594,7 +594,7 @@ func New(log *zap.Logger, full *identity.FullIdentity, db DB,
|
||||
|
||||
{
|
||||
if config.RepairQueueCheck.Interval.Seconds() > 0 {
|
||||
peer.RepairQueueStat.Chore = repairer.NewQueueStat(log, placement.SupportedPlacements(), db.RepairQueue(), config.RepairQueueCheck.Interval)
|
||||
peer.RepairQueueStat.Chore = repairer.NewQueueStat(log, monkit.Default, placement.SupportedPlacements(), db.RepairQueue(), config.RepairQueueCheck.Interval)
|
||||
|
||||
peer.Services.Add(lifecycle.Item{
|
||||
Name: "queue-stat",
|
||||
|
@ -27,6 +27,7 @@ type QueueStatConfig struct {
|
||||
type QueueStat struct {
|
||||
db queue.RepairQueue
|
||||
log *zap.Logger
|
||||
mon *monkit.Scope
|
||||
Loop *sync2.Cycle
|
||||
mu sync.Mutex
|
||||
stats map[string]queue.Stat
|
||||
@ -37,21 +38,22 @@ type QueueStat struct {
|
||||
var _ monkit.StatSource = &QueueStat{}
|
||||
|
||||
// NewQueueStat creates a chore to stat repair queue statistics.
|
||||
func NewQueueStat(log *zap.Logger, placements []storj.PlacementConstraint, db queue.RepairQueue, checkInterval time.Duration) *QueueStat {
|
||||
func NewQueueStat(log *zap.Logger, registry *monkit.Registry, placements []storj.PlacementConstraint, db queue.RepairQueue, checkInterval time.Duration) *QueueStat {
|
||||
|
||||
chore := &QueueStat{
|
||||
db: db,
|
||||
log: log,
|
||||
mon: registry.Package(),
|
||||
Loop: sync2.NewCycle(checkInterval),
|
||||
placements: placements,
|
||||
}
|
||||
mon.Chain(chore)
|
||||
chore.mon.Chain(chore)
|
||||
return chore
|
||||
}
|
||||
|
||||
// Run logs the current version information.
|
||||
func (c *QueueStat) Run(ctx context.Context) (err error) {
|
||||
defer mon.Task()(&ctx)(&err)
|
||||
defer c.mon.Task()(&ctx)(&err)
|
||||
return c.Loop.Run(ctx, func(ctx context.Context) error {
|
||||
c.RunOnce(ctx)
|
||||
return nil
|
||||
|
@ -41,11 +41,12 @@ func TestStatChore(t *testing.T) {
|
||||
})
|
||||
require.NoError(t, err)
|
||||
|
||||
chore := repairer.NewQueueStat(zaptest.NewLogger(t), []storj.PlacementConstraint{0, 1, 2}, db.RepairQueue(), 100*time.Hour)
|
||||
registry := monkit.NewRegistry()
|
||||
chore := repairer.NewQueueStat(zaptest.NewLogger(t), registry, []storj.PlacementConstraint{0, 1, 2}, db.RepairQueue(), 100*time.Hour)
|
||||
|
||||
collectMonkitStat := func() map[string]float64 {
|
||||
monkitValues := map[string]float64{}
|
||||
monkit.Default.Stats(func(key monkit.SeriesKey, field string, val float64) {
|
||||
registry.Stats(func(key monkit.SeriesKey, field string, val float64) {
|
||||
if key.Measurement != "repair_queue" {
|
||||
return
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user