github.com/anacrolix/torrent@v1.61.0/worse-conns_test.go (about)

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