-
Notifications
You must be signed in to change notification settings - Fork 59
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix TorrentDownloadController #1208
base: main
Are you sure you want to change the base?
Conversation
will also close #1205 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add unit tests
totalSize = 1000.kb, | ||
pieceSize = 1.kb, | ||
initialDataOffset = 0, | ||
initialPieceIndex = 0, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
还需要测试有这个 initialPieceIndex 的情况, 否则你没有测试这个 PR 尝试解决的问题 #1205
torrent/api/src/commonMain/kotlin/api/pieces/TorrentDownloadController.kt
Show resolved
Hide resolved
torrent/api/src/commonTest/kotlin/api/pieces/TorrentDownloadControllerTest.kt
Show resolved
Hide resolved
torrent/api/src/commonTest/kotlin/api/pieces/TorrentDownloadControllerTest.kt
Show resolved
Hide resolved
torrent/api/src/commonTest/kotlin/api/pieces/TorrentDownloadControllerTest.kt
Show resolved
Hide resolved
finishPiece(100) | ||
assertEquals(listOf(2, 3, 4, 6, 7, 8, 9, 10, 11, 13, 997, 998, 999), currentDownloadingPieces.sorted()) | ||
|
||
// 不会重复请求已经完成的 piece |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
separate case
(10..99).forEach { finishPiece(it) } | ||
assertEquals(listOf(2, 3, 4, 6, 7, 8, 9, 101, 102, 103, 997, 998, 999), currentDownloadingPieces.sorted()) | ||
|
||
// seek 到 200, seek 后面的地方不会请求 footer |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
separate case
torrent/api/src/commonTest/kotlin/api/pieces/TorrentDownloadControllerTest.kt
Show resolved
Hide resolved
torrent/api/src/commonTest/kotlin/api/pieces/TorrentDownloadControllerTest.kt
Show resolved
Hide resolved
finishPiece(996) | ||
controller.onSeek(100) | ||
assertEquals(listOf(995, 997), currentDownloadingPieces.sorted()) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
没有测试有 overlap 的 seek.
例如:
- seek 100 -> seek 102
- seek 100 -> seek 98
- seek 990 (footer 范围内) -> seek 985. 期望 footer 仍然在 window 内
- seek 1 (header 范围内) -> seek 20. 期望 header 仍然在 window 内
TorrentDownloaderController 无法工作