2022-06-14 18:03:38 +00:00
|
|
|
package sealer
|
2020-05-07 23:38:05 +00:00
|
|
|
|
|
|
|
import (
|
2020-07-27 11:20:18 +00:00
|
|
|
"fmt"
|
2020-05-07 23:38:05 +00:00
|
|
|
"testing"
|
|
|
|
|
2022-06-14 18:03:38 +00:00
|
|
|
"github.com/filecoin-project/lotus/storage/sealer/sealtasks"
|
2020-05-07 23:38:05 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestRequestQueue(t *testing.T) {
|
2022-05-18 13:47:08 +00:00
|
|
|
rq := &RequestQueue{}
|
2020-05-07 23:38:05 +00:00
|
|
|
|
2022-05-18 13:47:08 +00:00
|
|
|
rq.Push(&WorkerRequest{TaskType: sealtasks.TTAddPiece})
|
|
|
|
rq.Push(&WorkerRequest{TaskType: sealtasks.TTPreCommit1})
|
|
|
|
rq.Push(&WorkerRequest{TaskType: sealtasks.TTPreCommit2})
|
|
|
|
rq.Push(&WorkerRequest{TaskType: sealtasks.TTPreCommit1})
|
|
|
|
rq.Push(&WorkerRequest{TaskType: sealtasks.TTAddPiece})
|
2020-05-07 23:38:05 +00:00
|
|
|
|
2020-07-27 11:20:18 +00:00
|
|
|
dump := func(s string) {
|
|
|
|
fmt.Println("---")
|
|
|
|
fmt.Println(s)
|
|
|
|
|
|
|
|
for sqi := 0; sqi < rq.Len(); sqi++ {
|
|
|
|
task := (*rq)[sqi]
|
2022-05-18 13:47:08 +00:00
|
|
|
fmt.Println(sqi, task.TaskType)
|
2020-07-27 11:20:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
dump("start")
|
|
|
|
|
|
|
|
pt := rq.Remove(0)
|
|
|
|
|
|
|
|
dump("pop 1")
|
2020-05-07 23:38:05 +00:00
|
|
|
|
2022-05-18 13:47:08 +00:00
|
|
|
if pt.TaskType != sealtasks.TTPreCommit2 {
|
|
|
|
t.Error("expected precommit2, got", pt.TaskType)
|
2020-05-07 23:38:05 +00:00
|
|
|
}
|
|
|
|
|
2020-07-27 11:20:18 +00:00
|
|
|
pt = rq.Remove(0)
|
|
|
|
|
|
|
|
dump("pop 2")
|
|
|
|
|
2022-05-18 13:47:08 +00:00
|
|
|
if pt.TaskType != sealtasks.TTPreCommit1 {
|
|
|
|
t.Error("expected precommit1, got", pt.TaskType)
|
2020-07-27 11:20:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
pt = rq.Remove(1)
|
|
|
|
|
|
|
|
dump("pop 3")
|
|
|
|
|
2022-05-18 13:47:08 +00:00
|
|
|
if pt.TaskType != sealtasks.TTAddPiece {
|
|
|
|
t.Error("expected addpiece, got", pt.TaskType)
|
2020-07-27 11:20:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
pt = rq.Remove(0)
|
|
|
|
|
|
|
|
dump("pop 4")
|
2020-05-07 23:38:05 +00:00
|
|
|
|
2022-05-18 13:47:08 +00:00
|
|
|
if pt.TaskType != sealtasks.TTPreCommit1 {
|
|
|
|
t.Error("expected precommit1, got", pt.TaskType)
|
2020-05-07 23:38:05 +00:00
|
|
|
}
|
|
|
|
}
|