Skip to content

Fix flaky IAP flow test: spurious async and mock delays#32

Draft
Copilot wants to merge 2 commits into
masterfrom
copilot/improve-iap-flow-test-reliability
Draft

Fix flaky IAP flow test: spurious async and mock delays#32
Copilot wants to merge 2 commits into
masterfrom
copilot/improve-iap-flow-test-reliability

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented May 4, 2026

The IAP flow test suite was non-deterministic due to two compounding bugs that caused it to exceed tap's 30-second per-file timeout on slower CI machines.

Root causes

1. should_iap_transaction_history_be_refreshed incorrectly declared async

The function had no await inside it but was declared async, and its call site omitted await. This meant the guard check received a Promise (always truthy) instead of a boolean — so !should_iap_transaction_history_be_refreshed(account) was always false and the early-return never fired. Every GET /accounts/:pubkey call triggered a full Apple IAP refresh, even for active accounts that needed no refresh.

// Before — returns Promise, guard never fires
async function should_iap_transaction_history_be_refreshed(account) {  }

// After — returns boolean, guard works correctly
function should_iap_transaction_history_be_refreshed(account) {  }

2. Artificial 500ms delays in the mock IAP controller

getTransactionHistory and verifyAndDecodeTransaction each used setTimeout(…, 500). Combined with the always-refresh bug, every GET call added 500ms (fetch) + 500ms × N (decode), pushing the test file from ~3s to ~17s — near the timeout limit. The reject() calls also lacked a return, falling through to a subsequent resolve().

// Before
return new Promise((resolve, reject) => {
  setTimeout(() => {
    if (!this.mock_controller.mock_transaction_data[transactionId]) {
      reject(new APIException(400, 4000006))  // no return — falls through to resolve
    }
    resolve({ signedTransactions: , hasMore: false })
  }, 500)
})

// After
if (!this.mock_controller.mock_transaction_data[transactionId]) {
  return Promise.reject(new APIException(400, 4000006))
}
return Promise.resolve({ signedTransactions: , hasMore: false })

Impact

Before After
IAP flow test suite time ~17s ~3s
Full test suite time ~44s ~32s

Copilot AI linked an issue May 4, 2026 that may be closed by this pull request
Agent-Logs-Url: https://github.com/damus-io/api/sessions/9ac7edf6-1445-487b-8ab5-4e8a3fac7d03

Co-authored-by: danieldaquino <24692108+danieldaquino@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix flaky IAP flow test for consistent results Fix flaky IAP flow test: spurious async and mock delays May 4, 2026
Copilot AI requested a review from danieldaquino May 4, 2026 17:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

IAP flow test is flaky/unreliable

2 participants