Commit 0245bdf
committed
Add Phase 3 tests for Async Operations
Implement comprehensive test coverage for async coroutine-based
worker jobs that handle image loading and cropping. This phase
ensures async operations handle errors gracefully, manage memory
correctly, and respect lifecycle properly.
**New Test Files (33 tests total):**
TestCoroutineExtensions.kt (Test Helper)
- CoroutineTestRule for managing test dispatchers
- Automatic setup/teardown of Main dispatcher
- TestScope and UnconfinedTestDispatcher for immediate execution
BitmapLoadingWorkerJobTest.kt (19 tests)
- Successful loading flow with EXIF orientation
- Error handling (decode failures, EXIF read failures)
- Density calculation (high DPI adjustment, low DPI passthrough)
- Coroutine lifecycle (start, cancel, isActive checks)
- WeakReference memory management
- EXIF orientation support (0°, 90°, 180°, 270°)
- EXIF flip support (horizontal, vertical, combined)
- Sample size propagation
BitmapCroppingWorkerJobTest.kt (14 tests)
- URI-based cropping with all parameters
- Bitmap-based cropping with OOM handling
- Error handling (cropping failures, write failures)
- Null input handling (empty results)
- Coroutine lifecycle (cancellation prevents callback)
- Memory management (bitmap recycling when callback not invoked)
- Resize operations with RequestSizeOptions
- Compression format support (JPEG, PNG)
- Custom output URI handling
- Sample size propagation
**CI Timeout Configuration:**
Add sensible timeouts to prevent jobs from hanging indefinitely:
- gradle-wrapper-validation: 2 minutes
- Build jobs: 10 minutes each
- License/Lint checks: 5 minutes
- Android Lint: 10 minutes
- Unit Tests: 15 minutes (for all 167 tests)
Timeouts are 2-3x typical execution time to account for runner
variability and cache misses while ensuring faster failure detection.
**PLAN.md Updates:**
- Marked Phase 3 ✅ Complete
- Fixed Phase 2 test count (65 tests, not 45)
- Updated total: 167 tests across 9 test files
- Added completed test files list with Phase 3 entries
**Key Testing Patterns:**
- MockK for mocking BitmapUtils static methods
- Robolectric for Android context
- Coroutine test library for deterministic async testing
- Slot capture for verifying callback parameters
- UnconfinedTestDispatcher for immediate execution (no advanceUntilIdle needed)
This is Phase 3 of the 8-phase plan, focusing on bulletproof
async operation testing with coroutines.1 parent 3bdc72c commit 0245bdf
7 files changed
Lines changed: 1354 additions & 13 deletions
File tree
- .github/workflows
- cropper/src/test/kotlin/com/canhub/cropper
- test
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
| 14 | + | |
14 | 15 | | |
15 | 16 | | |
16 | 17 | | |
| |||
43 | 44 | | |
44 | 45 | | |
45 | 46 | | |
| 47 | + | |
46 | 48 | | |
47 | 49 | | |
48 | 50 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
| 14 | + | |
14 | 15 | | |
15 | 16 | | |
16 | 17 | | |
| |||
32 | 33 | | |
33 | 34 | | |
34 | 35 | | |
| 36 | + | |
35 | 37 | | |
36 | 38 | | |
37 | 39 | | |
| |||
53 | 55 | | |
54 | 56 | | |
55 | 57 | | |
| 58 | + | |
56 | 59 | | |
57 | 60 | | |
58 | 61 | | |
| |||
84 | 87 | | |
85 | 88 | | |
86 | 89 | | |
| 90 | + | |
87 | 91 | | |
88 | 92 | | |
89 | 93 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
| 14 | + | |
14 | 15 | | |
15 | 16 | | |
16 | 17 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
5 | | - | |
| 5 | + | |
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
| |||
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
15 | | - | |
16 | | - | |
| 15 | + | |
| 16 | + | |
17 | 17 | | |
18 | 18 | | |
19 | 19 | | |
20 | 20 | | |
21 | 21 | | |
22 | 22 | | |
23 | | - | |
| 23 | + | |
24 | 24 | | |
25 | 25 | | |
26 | 26 | | |
27 | 27 | | |
28 | 28 | | |
29 | 29 | | |
30 | 30 | | |
31 | | - | |
| 31 | + | |
32 | 32 | | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
33 | 36 | | |
34 | 37 | | |
35 | 38 | | |
| |||
999 | 1002 | | |
1000 | 1003 | | |
1001 | 1004 | | |
1002 | | - | |
| 1005 | + | |
1003 | 1006 | | |
1004 | 1007 | | |
1005 | | - | |
| 1008 | + | |
1006 | 1009 | | |
1007 | 1010 | | |
1008 | 1011 | | |
1009 | | - | |
| 1012 | + | |
1010 | 1013 | | |
1011 | 1014 | | |
1012 | | - | |
1013 | | - | |
1014 | | - | |
1015 | | - | |
| 1015 | + | |
| 1016 | + | |
| 1017 | + | |
| 1018 | + | |
1016 | 1019 | | |
1017 | | - | |
| 1020 | + | |
1018 | 1021 | | |
1019 | 1022 | | |
1020 | 1023 | | |
| |||
0 commit comments