Repository navigation
test: move RawSimulator-internals unit tests onto b2-simulator hooks - #775
Draft
sophiecarreras wants to merge 1 commit into
Draft
sophiecarreras wants to merge 1 commit into
sophiecarreras wants to merge 1 commit into
Conversation
…-simulator Tests that reached into RawSimulator's state now use test/unit/simulator_hooks.py. Each hook uses RawSimulator's test methods in the default run and b2-simulator's control plane under --b2-simulator: - Upload errors: POST /faults on b2_upload_file (503, 408, 400). On RawSimulator the upload raises what the SDK's HTTP layer raises for that answer. The fatal-error tests now expect BadRequest (code bad_request) instead of a test-only exception. Tests that recover from an injected error also check that it fired. - Upload timeout: a stall wire fault longer than a shortened upload timeout; the SDK sees B2RequestTimeout, the exception requests' timeout becomes. - Token expiry: POST /clock past the token lifetime. The reauthorization test now also checks that a new token was issued for the same key. - Truncated downloads (parallel): a reset-mid-response wire fault on both download endpoints, with a check that a download was cut short. - Corrupted stored SHA-1: POST /files/content-sha1. - Notification rule suspension: POST /notification-rules/suspend. - Second account: @pytest.mark.b2_simulator_config(extraAccounts=1); the harness's second create_account() returns account 2's credentials. Rewritten without simulator state, valid on both: - The empty-page listings use a client-side raw API wrapper instead of a BucketSimulator subclass, and a new test checks that empty pages are served. - SSE-C downloads pass the key instead of bypassing the encryption check. - The retention upload enables file lock and uses a future date. - File lock state is read back with list_buckets. - The source-replication test uses an existing destination bucket and key. - The unverified-checksum test uploads with an "unverified:" SHA-1 on b2-simulator (RawSimulator refuses the prefix, so it keeps the old edit). - The c8 test bucket name is 6 characters or more, as B2 requires. The simple-downloader truncation tests and test_testing_api_helpers.py stay on RawSimulator. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Important Draft PR not reviewedDraft PRs are not automatically reviewed by default.
To automatically review draft PRs, update your CodeRabbit configuration: reviews:
auto_review:
drafts: true
|
This was referenced Nov 27, 2026
ffumero2003
requested changes
Nov 29, 2026
ffumero2003
left a comment
Contributor
There was a problem hiding this comment.
Requesting changes for the red check — otherwise this is a sound migration of the RawSimulator-internals tests onto b2-simulator hooks. No rush, you're out; just flagging what to settle before undraft.
code/snykis failing: "1 new Code Analysis issue found" on this PR. Needs a look before it leaves draft — may well be a false positive on test code, but it should be resolved or dismissed with justification.- (decision) The fatal-upload test changes from
assertRaises(CanRetry)topytest.raises(BadRequest)(code == 'bad_request'), so the default run no longer exercises theCanRetry(False)branch. TheCanRetry(True)path now goes through real interpreted 503/408, which is arguably more faithful — but please decide whether to keep explicitCanRetry(False)coverage somewhere. - Stacking: base
test/b2-simulator-harness(#769); no GitHub Actions ran, so no CI evidence beyond the body. - (non-blocking) Timing hooks:
upload_times_out_once(0.5s timeout, 1500ms stall, 10s_wait_for) carries flake risk on slow runners, though it has post-conditions.expire_account_tokenadvances the global virtual clock 24h+1ms (expires every token, not one) — documented, but note the interaction if combined with a time-relative retention date. - (non-blocking, disclosed)
TestTruncatedDownloadSimplestays on RawSimulator becauseSimpleDownloaderdoesn't catchrequests.ChunkedEncodingError— a real SDK gap surfaced, not a test problem. Source-replication test still fails under the flag (F-85).
Happy to approve once Snyk is resolved and the CanRetry coverage question is settled, with a real CI run.
Open
3 tasks
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Paused while the author is away (back Dec 16).
Stacked on #769 (
test/b2-simulator-harness). The migrated tests need backblaze-labs/b2-simulator v0.6.0 (4052c6f8f45350486460d19bc796866cbdcdd3bc) for the control routes they use (/faults,/wire-faults,/clock,/files/content-sha1,/notification-rules/suspend,extraAccounts). This branch adds no CI pin;--b2-simulatoris still opt-in.What changes
Unit tests that read or set
RawSimulatorstate now go throughtest/unit/simulator_hooks.py. Each hook usesRawSimulator's test methods in the default run and b2-simulator's control plane under--b2-simulator. Test code only: nothing underb2sdk/changes.--b2-simulatorset_upload_errors([CanRetry(...)]),RequestTimeoutPOST /faultsonb2_upload_file(503, 408, 400). OnRawSimulatorthe upload raises what the SDK's HTTP layer raises for the same answer. Tests that recover also check that the fault firedset_upload_errors([B2RequestTimeoutDuringUpload()])stallwire fault longer than a shortened upload timeout. The SDK raisesB2RequestTimeoutexpire_auth_tokenPOST /clockpast the token lifetime. The test also checks that a new token was issuedTruncatedDownloadRawSimulator(parallel downloader)reset-mid-responsewire fault on both download endpoints, plus a check that a download was cut shortcontent_sha1 = 'f' * 40POST /files/content-sha1simulate_notification_rule_suspensionPOST /notification-rules/suspendcreate_account()@pytest.mark.b2_simulator_config(extraAccounts=1); the harness's secondcreate_account()returns account 2upload_url_counter = itertools.count()These tests were rewritten so they pass on both simulators without touching simulator state:
EmptyListSimulatoris replaced by a raw API wrapper on the client side. A newtest_empty_pages_are_servedfails if the wrapper serves no empty page.dont_check_encryption().list_buckets.RawSimulatorcannot do either, so in the default run they keep the old simulator edit.Changing a fault from a test-only exception to an HTTP answer changes one assertion: the fatal upload error now expects
BadRequestwith codebad_requestinstead ofCanRetry(False).Still on RawSimulator
TestTruncatedDownloadSimple(bothtest_bucket.pyfiles).SimpleDownloaderresumes only after a body that ends cleanly short. Over HTTP a short body raisesrequests.ChunkedEncodingError, because urllib3 enforces Content-Length, andSimpleDownloaderdoesn't catch it. Fixing that means changing the SDK, which this PR doesn't do.test_testing_api_helpers.py. By design it forbids HTTP and buildsRawSimulator()directly.test_raw_simulator.pyandtest_simulator_encryption_context.pytestRawSimulatoritself.Known failures under
--b2-simulatorin the touched teststest_is_file_lock_enabled_source_replication(v2, v3). b2-simulator answers400 bad_request"Operation not supported for buckets with source replication". b2sdk maps onlysource_replication_conflict, orbad_requestwith the text "Turning on file lock for an existing bucket having source replication configuration is not allowed.", toSourceReplicationConflict. The real code is unverified in the simulator's fidelity ledger (F-85).test_upload_large_file_with_restricted_api_key(v1, v2) andtest_c55_...[*-different](v2). Thev2apiver authorizes over API v3, and b2-simulator refuses bucket-restricted keys there, as real B2 did in a measured probe (F-120). Whether real B2 refuses every key shape on v3 is unverified.TestLs,TestListVersionsandDownloadTeststhat also fail in their plain classes because of test data (file lock,contentType: null, the v1 return-type literals). Those fixes are separate test-data work.Verification
pytest --api=vX -n 8 test/unit: v3 1665, v2 1636, v1 1653, v0 1491 passed, 0 failed.--b2-simulator, same command: failures fell from 103 / 113 / 102 / 69 to 66 / 84 / 79 / 59 (v3 / v2 / v1 / v0). No test that passed before fails now. Subtest ids are renumbered, so failing-subtest counts were compared per test.ruff check,ruff format --check,pytest test/static: pass.🤖 Generated with Claude Code