]> Sergey Matveev's repositories - btrtrc.git/blob - worse-conns_test.go
Drop support for go 1.20
[btrtrc.git] / worse-conns_test.go
1 package torrent
2
3 import (
4         "testing"
5         "time"
6
7         qt "github.com/frankban/quicktest"
8 )
9
10 func TestWorseConnLastHelpful(t *testing.T) {
11         c := qt.New(t)
12         c.Check((&worseConnInput{}).Less(&worseConnInput{LastHelpful: time.Now()}), qt.IsTrue)
13         c.Check((&worseConnInput{}).Less(&worseConnInput{CompletedHandshake: time.Now()}), qt.IsTrue)
14         c.Check((&worseConnInput{LastHelpful: time.Now()}).Less(&worseConnInput{CompletedHandshake: time.Now()}), qt.IsFalse)
15         c.Check((&worseConnInput{
16                 LastHelpful: time.Now(),
17         }).Less(&worseConnInput{
18                 LastHelpful:        time.Now(),
19                 CompletedHandshake: time.Now(),
20         }), qt.IsTrue)
21         now := time.Now()
22         c.Check((&worseConnInput{
23                 LastHelpful: now,
24         }).Less(&worseConnInput{
25                 LastHelpful:        now.Add(-time.Nanosecond),
26                 CompletedHandshake: now,
27         }), qt.IsFalse)
28         readyPeerPriority := func() (peerPriority, error) {
29                 return 42, nil
30         }
31         c.Check((&worseConnInput{
32                 GetPeerPriority: readyPeerPriority,
33         }).Less(&worseConnInput{
34                 GetPeerPriority: readyPeerPriority,
35                 Pointer:         1,
36         }), qt.IsTrue)
37         c.Check((&worseConnInput{
38                 GetPeerPriority: readyPeerPriority,
39                 Pointer:         2,
40         }).Less(&worseConnInput{
41                 GetPeerPriority: readyPeerPriority,
42                 Pointer:         1,
43         }), qt.IsFalse)
44 }