Add setUserWriteBlockMode tests#658
Conversation
|
🤖 Auto-triaged by documentdb-triage-tool. Applied: Reasoningcomponent 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 |
| "DiskUseThresholdExceeded", | ||
| ]: | ||
| try: | ||
| admin.command({"setUserWriteBlockMode": 1, "global": False, "reason": reason}) |
There was a problem hiding this comment.
why will this work not the previous whouldnt work?
There was a problem hiding this comment.
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( |
There was a problem hiding this comment.
should we additional test with actual write whether its blocking or not
There was a problem hiding this comment.
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", |
There was a problem hiding this comment.
DiskUseThresholdExceeded add this test case well
There was a problem hiding this comment.
Added test_setUserWriteBlockMode_same_reason_disk_threshold_idempotent test
| result, | ||
| ILLEGAL_OPERATION_ERROR, | ||
| msg="setUserWriteBlockMode should reject mismatched reason on disable", | ||
| ) |
There was a problem hiding this comment.
DiskUseThresholdExceeded this here as well
There was a problem hiding this comment.
added test_setUserWriteBlockMode_disable_mismatched_reason_disk_threshold_fails test
| 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"), | ||
| ] | ||
| ] |
There was a problem hiding this comment.
removed GLOBAL_VALID_TESTS and REASON_VALID_TESTS
| ("disk_threshold", "DiskUseThresholdExceeded"), | ||
| ] | ||
| ] | ||
|
|
There was a problem hiding this comment.
consider write operation as assertion criteria
There was a problem hiding this comment.
added reason_null_treated_as_omitted to verify that write can succeed after setUserWriteBlockMode is disabled.
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>
34389ff to
4987209
Compare
Signed-off-by: Alina (Xi) Li <Alina.Li@improving.com>
Signed-off-by: Alina (Xi) Li <Alina.Li@improving.com>
alinaliBQ
left a comment
There was a problem hiding this comment.
addressed comments
| 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"), | ||
| ] | ||
| ] |
There was a problem hiding this comment.
removed GLOBAL_VALID_TESTS and REASON_VALID_TESTS
| "DiskUseThresholdExceeded", | ||
| ]: | ||
| try: | ||
| admin.command({"setUserWriteBlockMode": 1, "global": False, "reason": reason}) |
There was a problem hiding this comment.
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( |
There was a problem hiding this comment.
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", |
There was a problem hiding this comment.
Added test_setUserWriteBlockMode_same_reason_disk_threshold_idempotent test
| result, | ||
| ILLEGAL_OPERATION_ERROR, | ||
| msg="setUserWriteBlockMode should reject mismatched reason on disable", | ||
| ) |
There was a problem hiding this comment.
added test_setUserWriteBlockMode_disable_mismatched_reason_disk_threshold_fails test
| ("disk_threshold", "DiskUseThresholdExceeded"), | ||
| ] | ||
| ] | ||
|
|
There was a problem hiding this comment.
added reason_null_treated_as_omitted to verify that write can succeed after setUserWriteBlockMode is disabled.
Add command operator tests for setUserWriteBlockMode. Tests database setUserWriteBlockMode behavior, output collection, syntax, and errors. This PR adds
AdminTestCase. Uses helper functionforce_disable_write_block.Worked with @vic-tsang to get initial set of tests to work with.