fix: improve core:network module quality and test coverage - #1493
Open
lihenggui wants to merge 7 commits into
Open
fix: improve core:network module quality and test coverage#1493lihenggui wants to merge 7 commits into
lihenggui wants to merge 7 commits into
Conversation
- Fix integer division bug in BinaryFileWriter progress calculation
(totalBytes.toDouble() / length instead of totalBytes / length)
- Fix response body leak in downloadRules (use response.use{})
- Fix downloadRules using blocking .execute() instead of async .await()
- Inject DI-provided Json instance instead of using global default
- Replace silent error swallowing with NetworkException for proper
error propagation to callers
- Remove unused Retrofit dependencies (only OkHttp is used)
- Rename RetrofitBlockerNetwork to OkHttpBlockerNetwork
- Remove unused FakeAssetManager from production DI graph
- Increase BinaryFileWriter chunk size from 1KB to 8KB
- Update SyncWorker to handle network exceptions properly
- Add comprehensive tests for JSON parsing, progress tracking,
model mappers, and edge cases
- Update dependency guard baseline
NetworkException belongs in the top-level network package, not the retrofit subpackage, since Retrofit has been removed.
Move ContinuationCallback, OkHttpBlockerNetwork, and its test from the retrofit subpackage to okhttp, completing the Retrofit removal.
Use the project's @dispatcher(IO) qualifier to inject the IO dispatcher, consistent with the rest of the codebase and testable with UnconfinedTestDispatcher.
Change-Id: Icaeaa6549d2f53c35f3da6a4f7bbf48f8ef69007
…provements # Conflicts: # app-compose/dependencies/marketReleaseRuntimeClasspath.txt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Comprehensive fixes for the
core:networkmodule addressing bugs, design issues, and test coverage gaps.Bug Fixes
BinaryFileWriterreported 0% progress until the very end due toLong / Longinteger division. Changed tototalBytes.toDouble() / length * 100.0downloadRules()never closed the OkHttp response body, causing connection pool leaks. Now usesresponse.use { ... }downloadRules()used synchronous.execute()instead of the async.await()coroutine bridge, blocking the caller's threadRetrofitBlockerNetworkused the globalJsondefault instead of the Hilt-provided instance configured withignoreUnknownKeys = trueDesign Improvements
NetworkException, allowing callers (e.g.,SyncWorker) to catch, retry, or surface errorsRetrofitBlockerNetwork→OkHttpBlockerNetwork— name now matches the actual implementationFakeAssetManagerfrom production DI — it was registered inSingletonComponentbut never injected anywhereBinaryFileWriterchunk size from 1KB to 8KB for better throughputSyncWorker— consolidated error handling to properly catch network exceptions from the new throwing APITest Coverage
BinaryFileWriterUnitTest— 7 tests covering: basic write, empty input, multi-chunk large files, progress reporting accuracy, integer division regression, negative length edge caseOkHttpBlockerNetworkTest— 10 tests covering: GitHub/GitLab JSON parsing, empty/blank/invalid JSON, missing fields, extra fields, multiple commits, blank SHANetworkModelMapperTest— 6 tests covering: full field mapping, null preservation, round-trip conversion forNetworkComponentDetailandNetworkGeneralRuleTest plan
./gradlew :core:network:testFossDebugUnitTest— all 23 tests pass./gradlew assembleFossDebug— full build succeeds./gradlew :sync:work:compileFossDebugKotlin— sync module compiles with SyncWorker changes./gradlew :core:network:spotlessCheck— code formatting verified./gradlew :app-compose:dependencyGuardBaseline— baseline updated (Retrofit removed)