Skip to content

Commit 96f1c21

Browse files
committed
session: introduce mock_init_rules
As this set of rules is going to be useful for more than one test, it makes sense to make it a separate function.
1 parent 04784a5 commit 96f1c21

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

scylla-rust-wrapper/src/session.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -840,6 +840,8 @@ mod tests {
840840
unsafe { cass_future_free(fut) };
841841
}
842842

843+
/// A set of rules that are needed to negotiate connections.
844+
// All connections are successfully negotiated.
843845
fn handshake_rules() -> impl IntoIterator<Item = RequestRule> {
844846
[
845847
RequestRule(
@@ -868,6 +870,23 @@ mod tests {
868870
)]
869871
}
870872

873+
/// A set of rules that are needed to finish session initialization.
874+
// They are used in tests that require a session to be connected.
875+
// All connections are successfully negotiated.
876+
// All requests are replied with a server error.
877+
fn mock_init_rules() -> impl IntoIterator<Item = RequestRule> {
878+
handshake_rules()
879+
.into_iter()
880+
.chain(std::iter::once(RequestRule(
881+
Condition::RequestOpcode(RequestOpcode::Query)
882+
.or(Condition::RequestOpcode(RequestOpcode::Prepare))
883+
.or(Condition::RequestOpcode(RequestOpcode::Batch)),
884+
// We won't respond to any queries (including metadata fetch),
885+
// but the driver will manage to continue with dummy metadata.
886+
RequestReaction::forge().server_error(),
887+
)))
888+
}
889+
871890
pub(crate) async fn test_with_one_proxy(
872891
test: impl FnOnce(SocketAddr, RunningProxy) -> RunningProxy + Send + 'static,
873892
rules: impl IntoIterator<Item = RequestRule>,

0 commit comments

Comments
 (0)