forked from anacrolix/torrent
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathworse-conns_test.go
44 lines (41 loc) · 1.2 KB
/
worse-conns_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package torrent
import (
"testing"
"time"
qt "github.com/frankban/quicktest"
)
func TestWorseConnLastHelpful(t *testing.T) {
c := qt.New(t)
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{
LastHelpful: time.Now(),
}).Less(&worseConnInput{
LastHelpful: time.Now(),
CompletedHandshake: time.Now(),
}), qt.IsTrue)
now := time.Now()
c.Check((&worseConnInput{
LastHelpful: now,
}).Less(&worseConnInput{
LastHelpful: now.Add(-time.Nanosecond),
CompletedHandshake: now,
}), qt.IsFalse)
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)
}