Skip to content

Commit 01b1475

Browse files
CopilotMossaka
andauthored
feat(ci): implement test parallelization to reduce CI time (#255)
* Initial plan * feat(ci): implement test parallelization to reduce CI time Co-authored-by: Mossaka <5447827+Mossaka@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: Mossaka <5447827+Mossaka@users.noreply.github.com> Co-authored-by: Jiaxiao (mossaka) Zhou <duibao55328@gmail.com>
1 parent 26246a8 commit 01b1475

2 files changed

Lines changed: 37 additions & 0 deletions

File tree

TESTING.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,40 @@ CI checks include:
197197
4. Coverage report generation
198198
5. Coverage threshold validation
199199

200+
### Test Parallelization Strategy
201+
202+
The project uses a multi-level parallelization strategy to optimize CI time:
203+
204+
#### Unit Tests (Jest Workers)
205+
- Unit tests run in parallel using Jest's worker pool
206+
- Configuration: `maxWorkers: '50%'` uses half of available CPU cores
207+
- Tests are isolated and have no shared state, making them safe to parallelize
208+
- Run time: ~6-8 seconds for 549 tests
209+
210+
#### Integration Tests (GitHub Actions Matrix)
211+
- Integration tests run in separate GitHub Actions runners using a matrix strategy
212+
- Each test file runs in its own isolated environment to avoid Docker conflicts
213+
- Test files run in parallel across multiple runners:
214+
- `basic-firewall.test.ts` - Core firewall functionality
215+
- `robustness.test.ts` - Comprehensive edge cases
216+
- `volume-mounts.test.ts` - Volume mount functionality
217+
- `container-workdir.test.ts` - Working directory configuration
218+
- `no-docker.test.ts` - Docker-in-Docker removal verification
219+
220+
**Why Integration Tests Can't Use Jest Workers:**
221+
- Integration tests use Docker containers that share network resources
222+
- Running multiple tests simultaneously would cause:
223+
- Docker network subnet pool exhaustion
224+
- Container name conflicts
225+
- Port binding conflicts
226+
- The `maxWorkers: 1` setting in `jest.integration.config.js` ensures sequential execution within each runner
227+
228+
**Benefits of Matrix Strategy:**
229+
- Each test file runs on a dedicated runner (full isolation)
230+
- All test files run in parallel (reduces wall-clock time)
231+
- `fail-fast: false` ensures all tests complete even if one fails
232+
- Individual test artifacts are captured for failed tests
233+
200234
## Debugging Tests
201235

202236
### Running Tests in Debug Mode

jest.config.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,7 @@ module.exports = {
2222
statements: 38,
2323
},
2424
},
25+
// Parallel test execution - use 50% of available CPUs to balance speed and resource usage
26+
// Unit tests are isolated and safe to run in parallel
27+
maxWorkers: '50%',
2528
};

0 commit comments

Comments
 (0)