Skip to content

Commit b3f4471

Browse files
committed
integration: proxy helper accepts initial request rules
Although the only existing integration test - consistency.rs - does not benefit from this change (as it must create request rules dynamically), this change makes it easier to write future tests that do not need to create request rules dynamically. It will be used in subsequent commits, when we move more tests from the lib crate to the integration tests.
1 parent ad9c0a5 commit b3f4471

File tree

2 files changed

+60
-51
lines changed

2 files changed

+60
-51
lines changed

scylla-rust-wrapper/tests/integration/consistency.rs

Lines changed: 49 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -609,60 +609,63 @@ fn check_for_all_consistencies_and_setting_options(
609609
#[ntest::timeout(60000)]
610610
async fn consistency_is_correctly_set_in_cql_requests() {
611611
setup_tracing();
612-
let res = test_with_3_node_dry_mode_cluster(|proxy_uris, mut running_proxy| {
613-
let request_rules = |tx| {
614-
handshake_rules()
615-
.into_iter()
616-
.chain(drop_metadata_queries_rules())
617-
.chain([
618-
RequestRule(
619-
Condition::and(
620-
Condition::not(Condition::ConnectionRegisteredAnyEvent),
621-
Condition::RequestOpcode(RequestOpcode::Prepare),
612+
let res = test_with_3_node_dry_mode_cluster(
613+
|| None,
614+
|proxy_uris, mut running_proxy| {
615+
let request_rules = |tx| {
616+
handshake_rules()
617+
.into_iter()
618+
.chain(drop_metadata_queries_rules())
619+
.chain([
620+
RequestRule(
621+
Condition::and(
622+
Condition::not(Condition::ConnectionRegisteredAnyEvent),
623+
Condition::RequestOpcode(RequestOpcode::Prepare),
624+
),
625+
// Respond to a PREPARE request with a prepared statement ID.
626+
// This assumes 0 bind variables and 0 returned columns.
627+
RequestReaction::forge_response(Arc::new(forge_prepare_response)),
622628
),
623-
// Respond to a PREPARE request with a prepared statement ID.
624-
// This assumes 0 bind variables and 0 returned columns.
625-
RequestReaction::forge_response(Arc::new(forge_prepare_response)),
626-
),
627-
RequestRule(
628-
Condition::and(
629-
Condition::not(Condition::ConnectionRegisteredAnyEvent),
630-
Condition::or(
631-
Condition::RequestOpcode(RequestOpcode::Execute),
629+
RequestRule(
630+
Condition::and(
631+
Condition::not(Condition::ConnectionRegisteredAnyEvent),
632632
Condition::or(
633-
Condition::RequestOpcode(RequestOpcode::Batch),
634-
Condition::and(
635-
Condition::RequestOpcode(RequestOpcode::Query),
636-
Condition::BodyContainsCaseSensitive(Box::new(
637-
*b"INTO consistency_tests",
638-
)),
633+
Condition::RequestOpcode(RequestOpcode::Execute),
634+
Condition::or(
635+
Condition::RequestOpcode(RequestOpcode::Batch),
636+
Condition::and(
637+
Condition::RequestOpcode(RequestOpcode::Query),
638+
Condition::BodyContainsCaseSensitive(Box::new(
639+
*b"INTO consistency_tests",
640+
)),
641+
),
639642
),
640643
),
641644
),
645+
RequestReaction::forge()
646+
.server_error()
647+
.with_feedback_when_performed(tx),
642648
),
643-
RequestReaction::forge()
644-
.server_error()
645-
.with_feedback_when_performed(tx),
646-
),
647-
])
648-
.collect::<Vec<_>>()
649-
};
650-
651-
// Set the rules for the requests.
652-
// This has the following effect:
653-
// 1. PREPARE requests will be answered with a forged response.
654-
// 2. EXECUTE, BATCH and QUERY requests will be replied with a forged error response,
655-
// but additionally will send a feedback to the channel `tx`, which will be used
656-
// to verify the consistency and serial consistency set in the request.
657-
let (request_tx, request_rx) = mpsc::unbounded_channel();
658-
for running_node in running_proxy.running_nodes.iter_mut() {
659-
running_node.change_request_rules(Some(request_rules(request_tx.clone())));
660-
}
649+
])
650+
.collect::<Vec<_>>()
651+
};
652+
653+
// Set the rules for the requests.
654+
// This has the following effect:
655+
// 1. PREPARE requests will be answered with a forged response.
656+
// 2. EXECUTE, BATCH and QUERY requests will be replied with a forged error response,
657+
// but additionally will send a feedback to the channel `tx`, which will be used
658+
// to verify the consistency and serial consistency set in the request.
659+
let (request_tx, request_rx) = mpsc::unbounded_channel();
660+
for running_node in running_proxy.running_nodes.iter_mut() {
661+
running_node.change_request_rules(Some(request_rules(request_tx.clone())));
662+
}
661663

662-
check_for_all_consistencies_and_setting_options(request_rx, proxy_uris);
664+
check_for_all_consistencies_and_setting_options(request_rx, proxy_uris);
663665

664-
running_proxy
665-
})
666+
running_proxy
667+
},
668+
)
666669
.await;
667670

668671
match res {

scylla-rust-wrapper/tests/integration/utils.rs

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,12 @@ pub(crate) fn setup_tracing() {
2525
.try_init();
2626
}
2727

28-
pub(crate) async fn test_with_3_node_dry_mode_cluster<F>(test: F) -> Result<(), ProxyError>
28+
pub(crate) async fn test_with_3_node_dry_mode_cluster<I, F>(
29+
initial_request_rules: impl Fn() -> I,
30+
test: F,
31+
) -> Result<(), ProxyError>
2932
where
33+
I: IntoIterator<Item = RequestRule>,
3034
F: FnOnce([String; 3], RunningProxy) -> RunningProxy + Send + 'static,
3135
{
3236
let proxy1_uri = format!("{}:9042", scylla_proxy::get_exclusive_local_address());
@@ -37,10 +41,12 @@ where
3741
let proxy2_addr = SocketAddr::from_str(proxy2_uri.as_str()).unwrap();
3842
let proxy3_addr = SocketAddr::from_str(proxy3_uri.as_str()).unwrap();
3943

40-
let proxy = Proxy::new(
41-
[proxy1_addr, proxy2_addr, proxy3_addr]
42-
.map(|proxy_addr| Node::builder().proxy_address(proxy_addr).build_dry_mode()),
43-
);
44+
let proxy = Proxy::new([proxy1_addr, proxy2_addr, proxy3_addr].map(|proxy_addr| {
45+
Node::builder()
46+
.proxy_address(proxy_addr)
47+
.request_rules(Vec::from_iter(initial_request_rules()))
48+
.build_dry_mode()
49+
}));
4450

4551
let running_proxy = proxy.run().await.unwrap();
4652

0 commit comments

Comments
 (0)