Fix non-deterministic test

This commit is contained in:
Matt Joiner 2021-05-14 10:23:18 +10:00
parent b80e2b08b5
commit 9dd85e5bd2
1 changed files with 10 additions and 15 deletions

View File

@ -86,6 +86,11 @@ func TestStealingFromSlowerPeer(t *testing.T) {
check(secondStealer.Id, 2) check(secondStealer.Id, 2)
} }
func checkNumRequestsAndInterest(c *qt.C, next PeerNextRequestState, num int, interest bool) {
c.Check(next.Requests, qt.HasLen, num)
c.Check(next.Interested, qt.Equals, interest)
}
func TestStealingFromSlowerPeersBasic(t *testing.T) { func TestStealingFromSlowerPeersBasic(t *testing.T) {
c := qt.New(t) c := qt.New(t)
order := ClientPieceOrder{} order := ClientPieceOrder{}
@ -106,7 +111,7 @@ func TestStealingFromSlowerPeersBasic(t *testing.T) {
firstStealer.Id = intPeerId(2) firstStealer.Id = intPeerId(2)
secondStealer := basePeer secondStealer := basePeer
secondStealer.Id = intPeerId(3) secondStealer.Id = intPeerId(3)
c.Assert(order.DoRequests([]*Torrent{{ results := order.DoRequests([]*Torrent{{
Pieces: []Piece{{ Pieces: []Piece{{
Request: true, Request: true,
NumPendingChunks: 2, NumPendingChunks: 2,
@ -117,20 +122,10 @@ func TestStealingFromSlowerPeersBasic(t *testing.T) {
firstStealer, firstStealer,
secondStealer, secondStealer,
}, },
}}), qt.ContentEquals, map[PeerId]PeerNextRequestState{ }})
intPeerId(2): { checkNumRequestsAndInterest(c, results[firstStealer.Id], 1, true)
Interested: true, checkNumRequestsAndInterest(c, results[secondStealer.Id], 1, true)
Requests: requestSetFromSlice(r(0, 0)), checkNumRequestsAndInterest(c, results[stealee.Id], 0, false)
},
intPeerId(3): {
Interested: true,
Requests: requestSetFromSlice(r(0, 1)),
},
stealee.Id: {
Interested: false,
Requests: requestSetFromSlice(),
},
})
} }
func TestPeerKeepsExistingIfReasonable(t *testing.T) { func TestPeerKeepsExistingIfReasonable(t *testing.T) {