Suites: test nào chứng minh gì
TL;DR
Bảng tra cứu: khi sửa một module, chạy các test trong nhóm tương ứng và đọc cột "Chứng minh" để biết thay đổi có thể đang phá invariant nào, và cột "Case" để biết case nghiệp vụ nào bị ảnh hưởng (danh mục case).
- Cần biết trước: Testing strategy.
Tình huống: Một thay đổi vừa sửa quota hoặc idempotency và cần biết chạy test nào, và test đó đang bảo vệ invariant nào.
- Từ khoá:
invariant,traceability
Go: internal/voting (unit)
| Test | Chứng minh | Case |
|---|---|---|
TestAcceptsVotesAtWindowBoundaries | [starts_at, ends_at): biên dưới inclusive, biên trên exclusive | C6 |
TestAcceptsVotesAtByStatus | Chỉ SCHEDULED/ACTIVE nhận vote | C6 |
TestDecideRejections | Thứ tự và mã rejection | C4, C8 |
TestDecideAcceptedProducesSortedClaims | Claims sort theo ScopeKey | C3 |
TestQuotaPeriodStartUsesCampaignTimezone | Kỳ "ngày" theo timezone campaign | C4 |
TestFingerprint | Fingerprint ổn định, nhạy với payload | C2 |
TestCommandValidate, TestSnapshotValidate | Validation cấu trúc | C7 |
TestDecidePaidVotes | Giá, điểm, cap paid | C4, C10 |
Go: internal/voting/pgstore (integration)
| Test | Chứng minh | Case |
|---|---|---|
TestAcceptedVoteWritesAllRecordsAtomically | Vote + ledger + outbox + idempotency cùng commit | C5 |
TestRetryWithSameKeyReplaysOriginalVote | Replay | C1 |
TestSameKeyWithDifferentPayloadIsRejected | Fingerprint mismatch ⇒ 422 | C2 |
TestConcurrentRetriesWithSameKeyAcceptExactlyOnce | 100 request cùng key ⇒ 1 vote | C1 |
TestConcurrentVotesNeverExceedQuota | 5 × 40 song song, quota 10 ⇒ đúng 10/actor | C3 |
TestFailedCandidateClaimRollsBackCampaignClaim | SAVEPOINT | C4 |
TestZeroQuotaNeverCreatesCounterRow | Pre-check nhánh INSERT | C3 |
TestRejectionIsFinalForItsKey | Rejection final | C1 |
TestVotesOutsideWindowAreRejected | Window | C6 |
TestUnknownCampaignIsNotRecorded | 404 không lưu | C1 |
TestUnknownAndWithdrawnCandidates | Candidate not found / not eligible | C9 |
TestStaleSnapshotIsIgnored | Version guard | C7 |
TestActorHistoryPagination | Keyset pagination | |
TestPoolEnforcesTransactionTimeout | transaction_timeout | C5, C17 |
TestAcceptedAtIsUTC | UTC | C6 |
TestVoteAndLedgerAreAppendOnly | Trigger append-only | C18 |
TestDeleteExpiredIdempotencyRecords | Cleanup theo batch | C1 |
TestPaidVoteAcceptedAndCaptureEventEmitted | Saga happy path | C10 |
TestInsufficientCreditIsFinal | INSUFFICIENT_CREDIT final | C10 |
TestUnknownReservationOutcomeIsResumedWithSameKey | Resume sau timeout | C10 |
TestRejectionAfterReservationRequestsRelease | Release qua outbox | C10 |
TestConcurrentPaidRetriesProduceOneVoteAndOneReservation | Retry song song paid | C10 |
TestSweeperAbandonsStuckAttemptsForever | ABANDONED terminal | C12 |
TestResolveAttempt | CAPTURE / RELEASE / PENDING | C12 |
TestPaidAntiWhaleCap | Cap paid riêng | C4 |
TestPaidVotesUnavailableWithoutCreditService | Không cấu hình credit | C10 |
TestFinalTallyFollowsTheLedgerAndIsIdempotent | Tally = ledger, idempotent | C17 |
TestFinalizationWaitsForSnapshotAndBarrier | Điều kiện finalize | C17 |
TestInvalidationIsIdempotentAndCorrectsFinalTally | Correction ⇒ version mới | C18 |
Go: ranking, outbox, consumers
| Test | Chứng minh | Case |
|---|---|---|
TestApplyIsIdempotent | Dedup theo entry id | C16 |
TestConcurrentOverlappingApplies | Không deadlock, đúng tổng | C16 |
TestRebuildMatchesProjectionAndIgnoresLaterReplays | Rebuild = projection | C16 |
TestRebuildConcurrentWithApplies | Advisory lock | C16 |
TestReconcileDetectsLagAndDrift | Lag vs drift | C16 |
TestLiveRankingSharesRankOnTies | Đồng hạng | C16 |
TestDecode (ranking, campaignsync, finalizer) | Decode / poison | |
TestCacheNeverMovesBackwards | Lua version guard | C16 |
TestReaderUsesCacheAndFallsBackToPostgres | Fallback | C16 |
TestInvalidationEntriesLowerTheTally | Entry âm | C18 |
TestRelayPublishesEnvelopesOnce | Relay | |
TestPublishFailureLeavesRowsForRetry | Không mark khi lỗi | |
TestConcurrentRelaysDoNotPublishTheSameRow | SKIP LOCKED | |
TestUnknownEventTypeFailsLoudly | Không bỏ qua âm thầm | |
TestFixedWindow | Rate limiter | |
TestReserve | Credit client mapping | C10 |
Go: HTTP & end-to-end
| Test | Chứng minh | Case |
|---|---|---|
TestHealth, TestCastVote*, TestListMyVotes*, TestRankingKinds, TestRateLimitedVotes, TestResolveAttemptEndpoint | Router (fake services) | |
TestInternalRoutesAreNotOnThePublicListener | Tách listener | C19 |
TestInternalAPINeedsTheToken | Listener nội bộ đòi X-Votee-Internal-Token, kể cả khi path viết lại (//internal, ..) | C19 |
TestMyQuotaIsForTheTokenSubject, TestFinalRankingCarriesNamesAndKeepsTheTallyFields, TestLiveRankingCarriesNamesWhenKnown, TestCachedNamesReadsOncePerTTLAndRemembersUnknownCampaigns | me/quota theo sub của token; tên campaign và candidate trong ranking, cache tên | C16 |
TestVoteFlowOverHTTP | HTTP thật + Postgres thật | C5 |
TestPipelineSurvivesDuplicatesPoisonAndReplay | Relay crash, poison, replay, rebuild | C16 |
TestFullFlow (smoke) | Toàn hệ thống, chạy qua gateway khi đặt SMOKE_GATEWAY_URL (make smoke trong network của stack) | C10, C17, C18 |
TestGateway (smoke) | Gateway: đường dẫn đóng trả 404, %2F bị từ chối, preflight CORS, giới hạn body, catalog package của payment-service |
Java: campaign-service
| Test | Chứng minh | Case |
|---|---|---|
CampaignTest.fullLifecycleIsTimeDriven | Lifecycle theo thời gian | C6 |
CampaignTest.scheduledCampaignWhoseWindowPassedEndsWithoutActivating | SCHEDULED ⇒ ENDED | C6 |
CampaignTest.finalTallyIsIdempotentAndCorrectionsKeepFinalized | Tally idempotent | C17, C18 |
CampaignTest.invalidTransitionsAreRejected | Guard | C9 |
CampaignTest.windowCanOnlyBeExtendedOnceVotingStarted | Reschedule | C9 |
CampaignTest.earlyEndCutsTheWindowAtNow | END sớm | C6 |
CampaignTest.candidatesAreFixedOnceVotingStarts | Candidate | C9 |
CampaignTest.rulesAreValidatedLikeVotingCore | Rules mirror Go | C9 |
CampaignServiceIntegrationTest.lifecycleOverHttpWithAuditAndOutbox | HTTP + audit + outbox | C9 |
CampaignServiceIntegrationTest.validationErrorsUseTheSharedFormat | Error format | |
CampaignServiceIntegrationTest.relayPublishesSnapshotsMatchingTheVotingCoreContract | Contract với Go | C7 |
CampaignServiceIntegrationTest.finalizationWaitsForTheClosingBarrierThenRecordsTheTally | Barrier + tally | C17 |
CampaignServiceIntegrationTest.concurrentCommandsChangeStateOnce | Optimistic lock | C9 |
Java: identity-service
| Test | Chứng minh | Case |
|---|---|---|
registeredAccountsLogInAndGetTokensOtherServicesCanVerify | Token verify được qua JWKS thật | C19 |
refreshTokensAreSingleUseAndReplayRevokesTheFamily | Refresh một lần, dùng lại ⇒ thu hồi family | C19 |
guestsGetAnHttpOnlyCookieAndKeepTheirIdentity | Guest cookie | C8 |
keyRotationKeepsOldTokensValidAndPublishesTheNewKey | Xoay khoá | C19 |
Java: payment-service
| Test | Chứng minh | Case |
|---|---|---|
aDuplicateWebhookGrantsOnce | Webhook trùng ⇒ một event | C13 |
outOfOrderEventsConverge | Sai thứ tự vẫn hội tụ | C13 |
aChargebackBlocksPurchasesInThatCampaignUntilTheDebtIsSettled | Nợ chặn mua đúng campaign | C15 |
theOrderKeepsThePriceItWasCreatedAt | Snapshot giá | C13 |
Java: credit-service
| Test | Chứng minh | Case |
|---|---|---|
grantsAreIdempotentByPaymentReference | Grant idempotent | C11 |
balancesAreIsolatedPerCampaign | Credit tách biệt theo campaign | C11 |
refundNeverExceedsTheAvailableBalance | Refund ≤ available, không đụng reserved | C14 |
paymentConfirmedGrantsCreditOnceToTheOrdersCampaign | PaymentConfirmed giao lại ⇒ một grant | C11, C13 |
anUnappliablePaymentEventGoesToTheDeadLetterTopic | Event sai hợp đồng vào DLQ | |
concurrentReservationsNeverOverdraw | Không âm số dư | C11 |
reservationsAreIdempotentByKey | Reserve idempotent | C11 |
captureAndReleaseAreIdempotentAndExclusive | Settle idempotent, loại trừ nhau | C12 |
voteEventsSettleReservationsAndPoisonGoesToDlq | Kafka listener + DLQ | C12 |
expiredReservationsAreOnlySettledOnADefinitiveAnswer | Expiry an toàn | C12 |
Rút ra & từ khoá
Điều đáng nhớ: mỗi test có tên mô tả hành vi và gắn với một case, nên đọc tên test cũng là đọc đặc tả.
| Từ khoá | Nghĩa (một câu) | Nơi khác trong Votee dùng lại |
|---|---|---|
invariant | Điều luôn đúng sau mọi thao tác | Consistency |
traceability | Truy từ case tới test chứng minh nó | Bài toán & các case |
Đọc tiếp: Observability, nơi các hành vi này được theo dõi khi hệ thống đang chạy.