Skip to content

Commit 288a9a7

Browse files
RUST-439 Return errors when unacknowledged write concerns are passed in (#184)
1 parent fbca7d0 commit 288a9a7

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

src/client/executor.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,13 @@ impl Client {
3838
/// an implicit session will be created if the operation and write concern are compatible with
3939
/// sessions.
4040
pub(crate) async fn execute_operation<T: Operation>(&self, op: T) -> Result<T::O> {
41+
// TODO RUST-9: allow unacknowledged write concerns
42+
if !op.is_acknowledged() {
43+
return Err(ErrorKind::ArgumentError {
44+
message: "Unacknowledged write concerns are not supported".to_string(),
45+
}
46+
.into());
47+
}
4148
let mut implicit_session = self.start_implicit_session(&op).await?;
4249
self.select_server_and_execute_operation(op, implicit_session.as_mut())
4350
.await

src/concern/test.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,3 +122,25 @@ async fn inconsistent_write_concern_rejected() {
122122
.expect_err("insert should fail");
123123
assert!(matches!(error.kind.as_ref(), ErrorKind::ArgumentError { .. }));
124124
}
125+
126+
#[cfg_attr(feature = "tokio-runtime", tokio::test)]
127+
#[cfg_attr(feature = "async-std-runtime", async_std::test)]
128+
#[function_name::named]
129+
async fn unacknowledged_write_concern_rejected() {
130+
let _guard = LOCK.run_concurrently().await;
131+
132+
let client = TestClient::new().await;
133+
let db = client.database(function_name!());
134+
let error = db
135+
.run_command(
136+
doc! {
137+
"insert": function_name!(),
138+
"documents": [ {} ],
139+
"writeConcern": { "w": 0 }
140+
},
141+
None,
142+
)
143+
.await
144+
.expect_err("insert should fail");
145+
assert!(matches!(error.kind.as_ref(), ErrorKind::ArgumentError { .. }));
146+
}

0 commit comments

Comments
 (0)