2021-11-28 14:06:10 +08:00
|
|
|
package torrent
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
qt "github.com/frankban/quicktest"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestWorseConnLastHelpful(t *testing.T) {
|
|
|
|
c := qt.New(t)
|
2021-11-29 07:07:48 +08:00
|
|
|
c.Check((&worseConnInput{}).Less(&worseConnInput{LastHelpful: time.Now()}), qt.IsTrue)
|
|
|
|
c.Check((&worseConnInput{}).Less(&worseConnInput{CompletedHandshake: time.Now()}), qt.IsTrue)
|
|
|
|
c.Check((&worseConnInput{LastHelpful: time.Now()}).Less(&worseConnInput{CompletedHandshake: time.Now()}), qt.IsFalse)
|
|
|
|
c.Check((&worseConnInput{
|
2021-11-28 14:06:10 +08:00
|
|
|
LastHelpful: time.Now(),
|
2021-11-29 07:07:48 +08:00
|
|
|
}).Less(&worseConnInput{
|
2021-11-28 14:06:10 +08:00
|
|
|
LastHelpful: time.Now(),
|
|
|
|
CompletedHandshake: time.Now(),
|
|
|
|
}), qt.IsTrue)
|
|
|
|
now := time.Now()
|
2021-11-29 07:07:48 +08:00
|
|
|
c.Check((&worseConnInput{
|
2021-11-28 14:06:10 +08:00
|
|
|
LastHelpful: now,
|
2021-11-29 07:07:48 +08:00
|
|
|
}).Less(&worseConnInput{
|
2021-11-28 14:06:10 +08:00
|
|
|
LastHelpful: now.Add(-time.Nanosecond),
|
|
|
|
CompletedHandshake: now,
|
|
|
|
}), qt.IsFalse)
|
2021-11-29 07:07:48 +08:00
|
|
|
readyPeerPriority := func() (peerPriority, error) {
|
|
|
|
return 42, nil
|
|
|
|
}
|
|
|
|
c.Check((&worseConnInput{
|
|
|
|
GetPeerPriority: readyPeerPriority,
|
|
|
|
}).Less(&worseConnInput{
|
|
|
|
GetPeerPriority: readyPeerPriority,
|
|
|
|
Pointer: 1,
|
|
|
|
}), qt.IsTrue)
|
|
|
|
c.Check((&worseConnInput{
|
|
|
|
GetPeerPriority: readyPeerPriority,
|
|
|
|
Pointer: 2,
|
|
|
|
}).Less(&worseConnInput{
|
|
|
|
GetPeerPriority: readyPeerPriority,
|
|
|
|
Pointer: 1,
|
|
|
|
}), qt.IsFalse)
|
2021-11-28 14:06:10 +08:00
|
|
|
}
|