Skip to content

Add setUserWriteBlockMode tests#658

Open
alinaliBQ wants to merge 12 commits into
documentdb:mainfrom
alinaliBQ:setUserWriteBlockMode
Open

Add setUserWriteBlockMode tests#658
alinaliBQ wants to merge 12 commits into
documentdb:mainfrom
alinaliBQ:setUserWriteBlockMode

Conversation

@alinaliBQ

@alinaliBQ alinaliBQ commented Jun 29, 2026

Copy link
Copy Markdown
Contributor

Add command operator tests for setUserWriteBlockMode. Tests database setUserWriteBlockMode behavior, output collection, syntax, and errors. This PR adds AdminTestCase. Uses helper function force_disable_write_block.
Worked with @vic-tsang to get initial set of tests to work with.

@alinaliBQ alinaliBQ marked this pull request as ready for review June 29, 2026 22:27
@alinaliBQ alinaliBQ requested a review from a team as a code owner June 29, 2026 22:27
@documentdb-triage-tool

Copy link
Copy Markdown

🤖 Auto-triaged by documentdb-triage-tool.

Applied: compatibility test, enhancement
Project fields suggested: Component test-coverage · Priority P2 · Effort L · Status Needs Review
Confidence: 0.30 (deterministic)

Reasoning

component from path globs (test-coverage, test-framework); effort from diff stats (796+0 LOC, 11 files); LLM failed: Invalid response body while trying to fetch https://api.anthropic.com/v1/messages: Premature close

If a label is wrong, remove it manually and ping @patty-chow so the rules can be tuned. The bot will not re-label items that already have component labels.

@documentdb-triage-tool documentdb-triage-tool Bot added compatibility test Compatibility test related enhancement New feature or request labels Jun 29, 2026
"DiskUseThresholdExceeded",
]:
try:
admin.command({"setUserWriteBlockMode": 1, "global": False, "reason": reason})

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why will this work not the previous whouldnt work?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This would work because reason is provided. The previous command tries to do it without providing the reason that was used to enable the write block mode.
I added documentation comment for this.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

okay

def test_setUserWriteBlockMode_disable_when_no_block_active(collection):
"""Test setUserWriteBlockMode global:false when no block is active succeeds."""
result = execute_admin_command(collection, {"setUserWriteBlockMode": 1, "global": False})
assertSuccessPartial(

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we additional test with actual write whether its blocking or not

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sure, added "n": 1 check to ensure insert succeeded and it is not blocking. We also have blocking tests in test_setUserWriteBlockMode_write_block_enforcement.py

assertSuccessPartial(
result,
{"ok": 1.0},
msg="setUserWriteBlockMode should be idempotent with same explicit reason",

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

DiskUseThresholdExceeded add this test case well

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added test_setUserWriteBlockMode_same_reason_disk_threshold_idempotent test

result,
ILLEGAL_OPERATION_ERROR,
msg="setUserWriteBlockMode should reject mismatched reason on disable",
)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

DiskUseThresholdExceeded this here as well

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added test_setUserWriteBlockMode_disable_mismatched_reason_disk_threshold_fails test

Comment on lines +37 to +69
GLOBAL_VALID_TESTS: list[AdminTestCase] = [
AdminTestCase(
"global_true",
command=lambda ctx: {"setUserWriteBlockMode": 1, "global": True},
expected={"ok": 1.0},
msg="setUserWriteBlockMode should accept global:true",
),
AdminTestCase(
"global_false",
command=lambda ctx: {"setUserWriteBlockMode": 1, "global": False},
expected={"ok": 1.0},
msg="setUserWriteBlockMode should accept global:false",
),
]

# Property [Reason Field Valid Values]: setUserWriteBlockMode accepts valid reason enum strings.
REASON_VALID_TESTS: list[AdminTestCase] = [
AdminTestCase(
f"reason_{tid}",
command=lambda ctx, r=reason: {
"setUserWriteBlockMode": 1,
"global": True,
"reason": r,
},
expected={"ok": 1.0},
msg=f"setUserWriteBlockMode should accept reason:{reason}",
)
for tid, reason in [
("unspecified", "Unspecified"),
("cluster_migration", "ClusterToClusterMigrationInProgress"),
("disk_threshold", "DiskUseThresholdExceeded"),
]
]

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

already tested.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed GLOBAL_VALID_TESTS and REASON_VALID_TESTS

("disk_threshold", "DiskUseThresholdExceeded"),
]
]

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

consider write operation as assertion criteria

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added reason_null_treated_as_omitted to verify that write can succeed after setUserWriteBlockMode is disabled.

alinaliBQ added 10 commits July 3, 2026 10:48
Signed-off-by: Alina (Xi) Li <Alina.Li@improving.com>
Signed-off-by: Alina (Xi) Li <Alina.Li@improving.com>
Signed-off-by: Alina (Xi) Li <Alina.Li@improving.com>
Signed-off-by: Alina (Xi) Li <Alina.Li@improving.com>
Signed-off-by: Alina (Xi) Li <Alina.Li@improving.com>
Signed-off-by: Alina (Xi) Li <Alina.Li@improving.com>
Signed-off-by: Alina (Xi) Li <Alina.Li@improving.com>
Signed-off-by: Alina (Xi) Li <Alina.Li@improving.com>
Signed-off-by: Alina (Xi) Li <Alina.Li@improving.com>
Signed-off-by: Alina (Xi) Li <Alina.Li@improving.com>
@alinaliBQ alinaliBQ force-pushed the setUserWriteBlockMode branch from 34389ff to 4987209 Compare July 3, 2026 17:48
alinaliBQ added 2 commits July 3, 2026 12:18
Signed-off-by: Alina (Xi) Li <Alina.Li@improving.com>
Signed-off-by: Alina (Xi) Li <Alina.Li@improving.com>

@alinaliBQ alinaliBQ left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

addressed comments

Comment on lines +37 to +69
GLOBAL_VALID_TESTS: list[AdminTestCase] = [
AdminTestCase(
"global_true",
command=lambda ctx: {"setUserWriteBlockMode": 1, "global": True},
expected={"ok": 1.0},
msg="setUserWriteBlockMode should accept global:true",
),
AdminTestCase(
"global_false",
command=lambda ctx: {"setUserWriteBlockMode": 1, "global": False},
expected={"ok": 1.0},
msg="setUserWriteBlockMode should accept global:false",
),
]

# Property [Reason Field Valid Values]: setUserWriteBlockMode accepts valid reason enum strings.
REASON_VALID_TESTS: list[AdminTestCase] = [
AdminTestCase(
f"reason_{tid}",
command=lambda ctx, r=reason: {
"setUserWriteBlockMode": 1,
"global": True,
"reason": r,
},
expected={"ok": 1.0},
msg=f"setUserWriteBlockMode should accept reason:{reason}",
)
for tid, reason in [
("unspecified", "Unspecified"),
("cluster_migration", "ClusterToClusterMigrationInProgress"),
("disk_threshold", "DiskUseThresholdExceeded"),
]
]

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed GLOBAL_VALID_TESTS and REASON_VALID_TESTS

"DiskUseThresholdExceeded",
]:
try:
admin.command({"setUserWriteBlockMode": 1, "global": False, "reason": reason})

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This would work because reason is provided. The previous command tries to do it without providing the reason that was used to enable the write block mode.
I added documentation comment for this.

def test_setUserWriteBlockMode_disable_when_no_block_active(collection):
"""Test setUserWriteBlockMode global:false when no block is active succeeds."""
result = execute_admin_command(collection, {"setUserWriteBlockMode": 1, "global": False})
assertSuccessPartial(

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sure, added "n": 1 check to ensure insert succeeded and it is not blocking. We also have blocking tests in test_setUserWriteBlockMode_write_block_enforcement.py

assertSuccessPartial(
result,
{"ok": 1.0},
msg="setUserWriteBlockMode should be idempotent with same explicit reason",

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added test_setUserWriteBlockMode_same_reason_disk_threshold_idempotent test

result,
ILLEGAL_OPERATION_ERROR,
msg="setUserWriteBlockMode should reject mismatched reason on disable",
)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added test_setUserWriteBlockMode_disable_mismatched_reason_disk_threshold_fails test

("disk_threshold", "DiskUseThresholdExceeded"),
]
]

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added reason_null_treated_as_omitted to verify that write can succeed after setUserWriteBlockMode is disabled.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

compatibility test Compatibility test related enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants