File tree Expand file tree Collapse file tree 2 files changed +29
-0
lines changed Expand file tree Collapse file tree 2 files changed +29
-0
lines changed Original file line number Diff line number Diff line change @@ -38,6 +38,13 @@ impl Client {
38
38
/// an implicit session will be created if the operation and write concern are compatible with
39
39
/// sessions.
40
40
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
+ }
41
48
let mut implicit_session = self . start_implicit_session ( & op) . await ?;
42
49
self . select_server_and_execute_operation ( op, implicit_session. as_mut ( ) )
43
50
. await
Original file line number Diff line number Diff line change @@ -122,3 +122,25 @@ async fn inconsistent_write_concern_rejected() {
122
122
. expect_err ( "insert should fail" ) ;
123
123
assert ! ( matches!( error. kind. as_ref( ) , ErrorKind :: ArgumentError { .. } ) ) ;
124
124
}
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
+ }
You can’t perform that action at this time.
0 commit comments