Commit e77620a
perf: optimize test database cleanup for faster CI (#981)
## Summary
- **MySQL**: Replace 14+ individual `TRUNCATE TABLE` statements per test
with a single query: `SET FOREIGN_KEY_CHECKS=0; DELETE FROM t1; DELETE
FROM t2; ...; SET FOREIGN_KEY_CHECKS=1;`
- **PostgreSQL**: Replace 14+ individual `TRUNCATE TABLE` statements
with a single `TRUNCATE TABLE t1, t2, ... CASCADE;`
## Why
Current CI test suite (123 files, 786 tests) takes **5m27s** (321.55s
wall clock). The vitest timing breakdown shows:
| Phase | Cumulative Time |
|-------|----------------|
| Import | 461.53s |
| **Setup** | **179.37s** |
| Tests | 194.23s |
| Transform | 27.59s |
The setup phase (179.37s cumulative) includes `afterEach` hooks that run
`TRUNCATE TABLE` on **every table individually** after **every test**.
With 786 tests × 14+ tables = ~11,000 TRUNCATE operations.
`TRUNCATE TABLE` is a DDL operation in MySQL that acquires metadata
locks and rebuilds table structures. `DELETE` is DML and much faster for
small tables (test data is small by nature). PostgreSQL natively
supports multi-table TRUNCATE in a single statement.
## Test plan
- [ ] CI passes on MySQL (all 4 matrix combinations)
- [ ] CI passes on PostgreSQL (both Node versions)
- [ ] Compare CI duration before/after
🤖 Generated with [Claude Code](https://claude.com/claude-code)
<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit
* **Chores**
* Improved test cleanup: consolidated and reused a prebuilt,
cross-database cleanup query to more reliably truncate data and speed
teardown.
* **Tests**
* Updated tests to use unique cache keys and added clarifying comments
to avoid cross-test interference with background tasks.
* Increased several mock wait times to better accommodate longer
operations and reduce timing-related flakiness.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
---------
Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>1 parent b55de1b commit e77620a
File tree
3 files changed
+30
-12
lines changed- test
- core/service
- port/controller/package
3 files changed
+30
-12
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
66 | 66 | | |
67 | 67 | | |
68 | 68 | | |
| 69 | + | |
69 | 70 | | |
70 | 71 | | |
71 | 72 | | |
| |||
157 | 158 | | |
158 | 159 | | |
159 | 160 | | |
160 | | - | |
161 | | - | |
162 | | - | |
163 | | - | |
164 | | - | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
165 | 176 | | |
166 | 177 | | |
167 | 178 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
45 | 45 | | |
46 | 46 | | |
47 | 47 | | |
| 48 | + | |
48 | 49 | | |
49 | 50 | | |
50 | | - | |
| 51 | + | |
51 | 52 | | |
52 | 53 | | |
53 | 54 | | |
54 | 55 | | |
55 | 56 | | |
56 | 57 | | |
57 | | - | |
| 58 | + | |
58 | 59 | | |
59 | 60 | | |
60 | 61 | | |
| |||
73 | 74 | | |
74 | 75 | | |
75 | 76 | | |
| 77 | + | |
76 | 78 | | |
77 | 79 | | |
78 | | - | |
| 80 | + | |
79 | 81 | | |
80 | 82 | | |
81 | 83 | | |
82 | 84 | | |
83 | 85 | | |
84 | 86 | | |
85 | 87 | | |
86 | | - | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
87 | 93 | | |
88 | 94 | | |
89 | 95 | | |
| |||
Lines changed: 4 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
113 | 113 | | |
114 | 114 | | |
115 | 115 | | |
116 | | - | |
| 116 | + | |
117 | 117 | | |
118 | 118 | | |
119 | 119 | | |
| |||
125 | 125 | | |
126 | 126 | | |
127 | 127 | | |
128 | | - | |
| 128 | + | |
| 129 | + | |
129 | 130 | | |
130 | 131 | | |
131 | 132 | | |
| |||
139 | 140 | | |
140 | 141 | | |
141 | 142 | | |
142 | | - | |
| 143 | + | |
143 | 144 | | |
144 | 145 | | |
145 | 146 | | |
| |||
0 commit comments