test: remove random test in pieceDispatcherTest (#2106)

Signed-off-by: bigerous <cuidajun.cdj@alibaba-inc.com>
This commit is contained in:
cuidajun 2023-02-22 10:35:30 +08:00 committed by Gaius
parent 58034e4b1f
commit e8822c144b
No known key found for this signature in database
GPG Key ID: 8B4E5D1290FA2FFB
1 changed files with 0 additions and 80 deletions

View File

@ -22,7 +22,6 @@ import (
"testing" "testing"
"time" "time"
"github.com/stretchr/testify/assert"
"golang.org/x/exp/maps" "golang.org/x/exp/maps"
"golang.org/x/exp/slices" "golang.org/x/exp/slices"
@ -124,53 +123,6 @@ func (pc *pieceTestManager) Order() []string {
return peerIDs return peerIDs
} }
func TestPieceDispatcher(t *testing.T) {
type args struct {
randomRatio float64
peers []peerDesc
pieceNum int
}
tests := []struct {
name string
args args
want []string
}{
{
name: "no random",
args: args{
randomRatio: 0,
peers: []peerDesc{
{"bad", time.Second * 10, nil},
{"good", time.Second * 2, nil},
},
pieceNum: 10000,
},
want: []string{"good", "bad"},
},
{
name: "with 0.5 randomRatio",
args: args{
randomRatio: 0.5,
peers: []peerDesc{
{"bad", time.Second * 10, nil},
{"good", time.Second * 2, nil},
},
pieceNum: 10000,
},
want: []string{"good", "bad"},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
pieceDispatcher := NewPieceDispatcher(tt.args.randomRatio, logger.With())
pieceTestManager := newPieceTestManager(pieceDispatcher, tt.args.peers, tt.args.pieceNum)
pieceTestManager.Run()
result := pieceTestManager.Order()
assert.Equal(t, tt.want, result)
})
}
}
func TestPieceDispatcherCount(t *testing.T) { func TestPieceDispatcherCount(t *testing.T) {
type args struct { type args struct {
randomRatio float64 randomRatio float64
@ -196,38 +148,6 @@ func TestPieceDispatcherCount(t *testing.T) {
want: map[string]int{ want: map[string]int{
"bad": 0, "bad": 0,
"mid": 0, "mid": 0,
"good": 7000,
},
},
{
name: "with 0.5 randomRatio",
args: args{
randomRatio: 0.5,
peers: []peerDesc{
{"bad", time.Second * 4, nil},
{"mid", time.Second * 3, nil},
{"good", time.Second * 2, nil},
},
pieceNum: 10000,
},
want: map[string]int{
"bad": 1000,
"mid": 1000,
"good": 5500,
},
},
{
name: "total random",
args: args{
randomRatio: 1,
peers: []peerDesc{
{"bad", time.Second * 10, nil},
{"good", time.Second * 2, nil},
},
pieceNum: 10000,
},
want: map[string]int{
"bad": 4000,
"good": 4000, "good": 4000,
}, },
}, },