Chuyển tới nội dung chính

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).

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)​

TestChứng minhCase
TestAcceptsVotesAtWindowBoundaries[starts_at, ends_at): biên dưới inclusive, biên trên exclusiveC6
TestAcceptsVotesAtByStatusChỉ SCHEDULED/ACTIVE nhận voteC6
TestDecideRejectionsThứ tự và mã rejectionC4, C8
TestDecideAcceptedProducesSortedClaimsClaims sort theo ScopeKeyC3
TestQuotaPeriodStartUsesCampaignTimezoneKỳ "ngày" theo timezone campaignC4
TestFingerprintFingerprint ổn định, nhạy với payloadC2
TestCommandValidate, TestSnapshotValidateValidation cấu trúcC7
TestDecidePaidVotesGiá, điểm, cap paidC4, C10

Go: internal/voting/pgstore (integration)​

TestChứng minhCase
TestAcceptedVoteWritesAllRecordsAtomicallyVote + ledger + outbox + idempotency cùng commitC5
TestRetryWithSameKeyReplaysOriginalVoteReplayC1
TestSameKeyWithDifferentPayloadIsRejectedFingerprint mismatch ⇒ 422C2
TestConcurrentRetriesWithSameKeyAcceptExactlyOnce100 request cùng key ⇒ 1 voteC1
TestConcurrentVotesNeverExceedQuota5 × 40 song song, quota 10 ⇒ đúng 10/actorC3
TestFailedCandidateClaimRollsBackCampaignClaimSAVEPOINTC4
TestZeroQuotaNeverCreatesCounterRowPre-check nhánh INSERTC3
TestRejectionIsFinalForItsKeyRejection finalC1
TestVotesOutsideWindowAreRejectedWindowC6
TestUnknownCampaignIsNotRecorded404 không lưuC1
TestUnknownAndWithdrawnCandidatesCandidate not found / not eligibleC9
TestStaleSnapshotIsIgnoredVersion guardC7
TestActorHistoryPaginationKeyset pagination
TestPoolEnforcesTransactionTimeouttransaction_timeoutC5, C17
TestAcceptedAtIsUTCUTCC6
TestVoteAndLedgerAreAppendOnlyTrigger append-onlyC18
TestDeleteExpiredIdempotencyRecordsCleanup theo batchC1
TestPaidVoteAcceptedAndCaptureEventEmittedSaga happy pathC10
TestInsufficientCreditIsFinalINSUFFICIENT_CREDIT finalC10
TestUnknownReservationOutcomeIsResumedWithSameKeyResume sau timeoutC10
TestRejectionAfterReservationRequestsReleaseRelease qua outboxC10
TestConcurrentPaidRetriesProduceOneVoteAndOneReservationRetry song song paidC10
TestSweeperAbandonsStuckAttemptsForeverABANDONED terminalC12
TestResolveAttemptCAPTURE / RELEASE / PENDINGC12
TestPaidAntiWhaleCapCap paid riêngC4
TestPaidVotesUnavailableWithoutCreditServiceKhông cấu hình creditC10
TestFinalTallyFollowsTheLedgerAndIsIdempotentTally = ledger, idempotentC17
TestFinalizationWaitsForSnapshotAndBarrierĐiều kiện finalizeC17
TestInvalidationIsIdempotentAndCorrectsFinalTallyCorrection ⇒ version mớiC18

Go: ranking, outbox, consumers​

TestChứng minhCase
TestApplyIsIdempotentDedup theo entry idC16
TestConcurrentOverlappingAppliesKhông deadlock, đúng tổngC16
TestRebuildMatchesProjectionAndIgnoresLaterReplaysRebuild = projectionC16
TestRebuildConcurrentWithAppliesAdvisory lockC16
TestReconcileDetectsLagAndDriftLag vs driftC16
TestLiveRankingSharesRankOnTiesĐồng hạngC16
TestDecode (ranking, campaignsync, finalizer)Decode / poison
TestCacheNeverMovesBackwardsLua version guardC16
TestReaderUsesCacheAndFallsBackToPostgresFallbackC16
TestInvalidationEntriesLowerTheTallyEntry âmC18
TestRelayPublishesEnvelopesOnceRelay
TestPublishFailureLeavesRowsForRetryKhông mark khi lỗi
TestConcurrentRelaysDoNotPublishTheSameRowSKIP LOCKED
TestUnknownEventTypeFailsLoudlyKhông bỏ qua âm thầm
TestFixedWindowRate limiter
TestReserveCredit client mappingC10

Go: HTTP & end-to-end​

TestChứng minhCase
TestHealth, TestCastVote*, TestListMyVotes*, TestRankingKinds, TestRateLimitedVotes, TestResolveAttemptEndpointRouter (fake services)
TestInternalRoutesAreNotOnThePublicListenerTách listenerC19
TestInternalAPINeedsTheTokenListener nội bộ đòi X-Votee-Internal-Token, kể cả khi path viết lại (//internal, ..)C19
TestMyQuotaIsForTheTokenSubject, TestFinalRankingCarriesNamesAndKeepsTheTallyFields, TestLiveRankingCarriesNamesWhenKnown, TestCachedNamesReadsOncePerTTLAndRemembersUnknownCampaignsme/quota theo sub của token; tên campaign và candidate trong ranking, cache tênC16
TestVoteFlowOverHTTPHTTP thật + Postgres thậtC5
TestPipelineSurvivesDuplicatesPoisonAndReplayRelay crash, poison, replay, rebuildC16
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​

TestChứng minhCase
CampaignTest.fullLifecycleIsTimeDrivenLifecycle theo thời gianC6
CampaignTest.scheduledCampaignWhoseWindowPassedEndsWithoutActivatingSCHEDULED ⇒ ENDEDC6
CampaignTest.finalTallyIsIdempotentAndCorrectionsKeepFinalizedTally idempotentC17, C18
CampaignTest.invalidTransitionsAreRejectedGuardC9
CampaignTest.windowCanOnlyBeExtendedOnceVotingStartedRescheduleC9
CampaignTest.earlyEndCutsTheWindowAtNowEND sớmC6
CampaignTest.candidatesAreFixedOnceVotingStartsCandidateC9
CampaignTest.rulesAreValidatedLikeVotingCoreRules mirror GoC9
CampaignServiceIntegrationTest.lifecycleOverHttpWithAuditAndOutboxHTTP + audit + outboxC9
CampaignServiceIntegrationTest.validationErrorsUseTheSharedFormatError format
CampaignServiceIntegrationTest.relayPublishesSnapshotsMatchingTheVotingCoreContractContract với GoC7
CampaignServiceIntegrationTest.finalizationWaitsForTheClosingBarrierThenRecordsTheTallyBarrier + tallyC17
CampaignServiceIntegrationTest.concurrentCommandsChangeStateOnceOptimistic lockC9

Java: identity-service​

TestChứng minhCase
registeredAccountsLogInAndGetTokensOtherServicesCanVerifyToken verify được qua JWKS thậtC19
refreshTokensAreSingleUseAndReplayRevokesTheFamilyRefresh một lần, dùng lại ⇒ thu hồi familyC19
guestsGetAnHttpOnlyCookieAndKeepTheirIdentityGuest cookieC8
keyRotationKeepsOldTokensValidAndPublishesTheNewKeyXoay khoáC19

Java: payment-service​

TestChứng minhCase
aDuplicateWebhookGrantsOnceWebhook trùng ⇒ một eventC13
outOfOrderEventsConvergeSai thứ tự vẫn hội tụC13
aChargebackBlocksPurchasesInThatCampaignUntilTheDebtIsSettledNợ chặn mua đúng campaignC15
theOrderKeepsThePriceItWasCreatedAtSnapshot giáC13

Java: credit-service​

TestChứng minhCase
grantsAreIdempotentByPaymentReferenceGrant idempotentC11
balancesAreIsolatedPerCampaignCredit tách biệt theo campaignC11
refundNeverExceedsTheAvailableBalanceRefund ≤ available, không đụng reservedC14
paymentConfirmedGrantsCreditOnceToTheOrdersCampaignPaymentConfirmed giao lại ⇒ một grantC11, C13
anUnappliablePaymentEventGoesToTheDeadLetterTopicEvent sai hợp đồng vào DLQ
concurrentReservationsNeverOverdrawKhông âm số dưC11
reservationsAreIdempotentByKeyReserve idempotentC11
captureAndReleaseAreIdempotentAndExclusiveSettle idempotent, loại trừ nhauC12
voteEventsSettleReservationsAndPoisonGoesToDlqKafka listener + DLQC12
expiredReservationsAreOnlySettledOnADefinitiveAnswerExpiry an toànC12

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ácConsistency
traceabilityTruy 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.