Speed up TestCreditLines by avoiding CouchDB user operations#37428
Speed up TestCreditLines by avoiding CouchDB user operations#37428dannyroberts wants to merge 2 commits intomasterfrom
Conversation
Replace CouchDB CommCareUser creation and calculate_users_in_all_domains calls with direct DomainUserHistory SQL records. The invoicing code only reads DomainUserHistory, so creating CouchDB users just to count them is unnecessary overhead causing 200+ second setup times in CI. Also removes dead code (_generate_users_fee_to_credit_against was never called). Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
952d61d to
fdd1f05
Compare
|
(This comment was generated by Claude, but I've reviewed it and stand behind it—this is my current best understanding.) Investigation resultsThe 200+ second setup time attributed to Evidence: all three shards show the same ~200s setup on their first DB test, regardless of which test it is:
The changes in this PR (replacing CouchDB Closing since the original premise (TestCreditLines setup being unusually slow) turned out to be a misattribution. |
Product Description
N/A — test-only change.
Technical Summary
TestCreditLineswas taking 200+ seconds in CI due to CouchDB operations:creating
CommCareUserdocuments, querying CouchDB views to count them viacalculate_users_in_all_domains, and deleting them in teardown.The invoicing code only reads
DomainUserHistorySQL records, so we cancreate those directly instead of round-tripping through CouchDB. This follows
the same pattern already used by
TestSubscriptionChangeTransfersSubscriptionLevelCreditin the same file.
Also removes
_generate_users_fee_to_credit_againstwhich was dead code(defined but never called).
Feature Flag
N/A
Safety Assurance
Safety story
Test-only change. The refactored tests exercise the same invoicing and credit
line logic — the only difference is how
DomainUserHistoryrecords arecreated (directly via SQL instead of via CouchDB user creation + counting).
Automated test coverage
The 5 test methods in
TestCreditLinesthemselves verify the behavior isunchanged.
QA Plan
CI passing is sufficient.
Rollback instructions
Labels & Review