fix sched_test

This commit is contained in:
Łukasz Magiera 2022-11-28 18:02:16 +01:00
parent 5881edb75e
commit 5a458a60c2
4 changed files with 27 additions and 8 deletions

View File

@ -87,7 +87,7 @@ type Scheduler struct {
type WorkerHandle struct {
workerRpc Worker
Info storiface.WorkerInfo
preparing *ActiveResources // use with WorkerHandle.lk

View File

@ -2,7 +2,6 @@ package sealer
import (
"context"
"github.com/filecoin-project/lotus/storage/sealer/storiface"
"math/rand"
"sort"
"sync"
@ -10,6 +9,7 @@ import (
"go.opencensus.io/stats"
"github.com/filecoin-project/lotus/metrics"
"github.com/filecoin-project/lotus/storage/sealer/storiface"
)
type WindowSelector func(sh *Scheduler, queueLen int, acceptableWindows [][]int, windows []SchedWindow) int

View File

@ -1,9 +1,10 @@
package sealer
import (
"sync"
"github.com/filecoin-project/lotus/storage/sealer/sealtasks"
"github.com/filecoin-project/lotus/storage/sealer/storiface"
"sync"
)
type ActiveResources struct {

View File

@ -19,6 +19,7 @@ import (
"github.com/filecoin-project/go-state-types/abi"
prooftypes "github.com/filecoin-project/go-state-types/proof"
"github.com/filecoin-project/lotus/api"
"github.com/filecoin-project/lotus/storage/paths"
"github.com/filecoin-project/lotus/storage/sealer/fsutil"
"github.com/filecoin-project/lotus/storage/sealer/sealtasks"
@ -587,18 +588,24 @@ func TestSched(t *testing.T) {
type slowishSelector bool
func (s slowishSelector) Ok(ctx context.Context, task sealtasks.TaskType, spt abi.RegisteredSealProof, a *WorkerHandle) (bool, bool, error) {
time.Sleep(200 * time.Microsecond)
func (s slowishSelector) Ok(ctx context.Context, task sealtasks.TaskType, spt abi.RegisteredSealProof, a SchedWorker) (bool, bool, error) {
_, _ = a.Paths(ctx)
_, _ = a.TaskTypes(ctx)
return bool(s), false, nil
}
func (s slowishSelector) Cmp(ctx context.Context, task sealtasks.TaskType, a, b *WorkerHandle) (bool, error) {
time.Sleep(100 * time.Microsecond)
func (s slowishSelector) Cmp(ctx context.Context, task sealtasks.TaskType, a, b SchedWorker) (bool, error) {
_, _ = a.Paths(ctx)
return true, nil
}
var _ WorkerSelector = slowishSelector(true)
type tw struct {
api.Worker
io.Closer
}
func BenchmarkTrySched(b *testing.B) {
logging.SetAllLoggers(logging.LevelInfo)
defer logging.SetAllLoggers(logging.LevelDebug)
@ -609,14 +616,25 @@ func BenchmarkTrySched(b *testing.B) {
for i := 0; i < b.N; i++ {
b.StopTimer()
var whnd api.WorkerStruct
whnd.Internal.TaskTypes = func(p0 context.Context) (map[sealtasks.TaskType]struct{}, error) {
time.Sleep(100 * time.Microsecond)
return nil, nil
}
whnd.Internal.Paths = func(p0 context.Context) ([]storiface.StoragePath, error) {
time.Sleep(100 * time.Microsecond)
return nil, nil
}
sched, err := newScheduler(ctx, "")
require.NoError(b, err)
sched.Workers[storiface.WorkerID{}] = &WorkerHandle{
workerRpc: nil,
workerRpc: &tw{Worker: &whnd},
Info: storiface.WorkerInfo{
Hostname: "t",
Resources: decentWorkerResources,
},
Enabled: true,
preparing: NewActiveResources(),
active: NewActiveResources(),
}