-
Notifications
You must be signed in to change notification settings - Fork 64
/
utils.rs
682 lines (596 loc) · 20.3 KB
/
utils.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
#![allow(unused_macros)]
#![allow(unused_imports)]
#![allow(dead_code)]
#![allow(unused_variables)]
#![allow(clippy::match_like_matches_macro)]
use fred::{
clients::Client,
error::Error,
interfaces::*,
types::{
config::{
ClusterDiscoveryPolicy,
Config,
ConnectionConfig,
PerformanceConfig,
ReconnectPolicy,
Server,
ServerConfig,
UnresponsiveConfig,
},
Builder,
ConnectHandle,
InfoKind,
},
};
use redis_protocol::resp3::types::RespVersion;
use std::{
convert::TryInto,
default::Default,
env,
fmt,
fmt::{Debug, Formatter},
fs,
future::Future,
time::Duration,
};
const RECONNECT_DELAY: u32 = 1000;
#[cfg(any(
feature = "enable-rustls",
feature = "enable-native-tls",
feature = "enable-rustls-ring"
))]
use fred::types::config::{TlsConfig, TlsConnector, TlsHostMapping};
#[cfg(feature = "enable-native-tls")]
use tokio_native_tls::native_tls::{
Certificate as NativeTlsCertificate,
Identity,
TlsConnector as NativeTlsConnector,
};
#[cfg(any(feature = "enable-rustls", feature = "enable-rustls-ring"))]
use tokio_rustls::rustls::{ClientConfig, ConfigBuilder, RootCertStore, WantsVerifier};
pub fn read_env_var(name: &str) -> Option<String> {
env::var_os(name).and_then(|s| s.into_string().ok())
}
pub fn should_use_sentinel_config() -> bool {
read_env_var("FRED_SENTINEL_TESTS")
.map(|s| match s.as_ref() {
"1" | "t" | "true" | "yes" => true,
_ => false,
})
.unwrap_or(false)
}
pub fn should_flushall_between_tests() -> bool {
read_env_var("FRED_NO_FLUSHALL_DURING_TESTS")
.map(|s| match s.as_ref() {
"1" | "t" | "true" | "yes" => false,
_ => true,
})
.unwrap_or(true)
}
pub fn read_ci_tls_env() -> bool {
match env::var_os("FRED_CI_TLS") {
Some(s) => match s.into_string() {
Ok(s) => match s.as_ref() {
"t" | "true" | "TRUE" | "1" => true,
_ => false,
},
Err(_) => false,
},
None => false,
}
}
fn read_fail_fast_env() -> bool {
match env::var_os("FRED_FAIL_FAST") {
Some(s) => match s.into_string() {
Ok(s) => match s.as_ref() {
"f" | "false" | "FALSE" | "0" => false,
_ => true,
},
Err(_) => true,
},
None => true,
}
}
#[cfg(feature = "i-redis-stack")]
pub fn read_redis_centralized_host() -> (String, u16) {
let host = read_env_var("FRED_REDIS_STACK_HOST").unwrap_or("redis-main".into());
let port = read_env_var("FRED_REDIS_STACK_PORT")
.and_then(|s| s.parse::<u16>().ok())
.unwrap_or(6379);
(host, port)
}
#[cfg(not(feature = "i-redis-stack"))]
pub fn read_redis_centralized_host() -> (String, u16) {
let host = read_env_var("FRED_REDIS_CENTRALIZED_HOST").unwrap_or("redis-main".into());
let port = read_env_var("FRED_REDIS_CENTRALIZED_PORT")
.and_then(|s| s.parse::<u16>().ok())
.unwrap_or(6379);
(host, port)
}
#[cfg(not(any(
feature = "enable-native-tls",
feature = "enable-rustls",
feature = "enable-rustls-ring"
)))]
pub fn read_redis_cluster_host() -> (String, u16) {
let host = read_env_var("FRED_REDIS_CLUSTER_HOST").unwrap_or("redis-cluster-1".into());
let port = read_env_var("FRED_REDIS_CLUSTER_PORT")
.and_then(|s| s.parse::<u16>().ok())
.unwrap_or(30001);
(host, port)
}
#[cfg(any(
feature = "enable-native-tls",
feature = "enable-rustls",
feature = "enable-rustls-ring"
))]
pub fn read_redis_cluster_host() -> (String, u16) {
let host = read_env_var("FRED_REDIS_CLUSTER_TLS_HOST").unwrap_or("redis-cluster-tls-1".into());
let port = read_env_var("FRED_REDIS_CLUSTER_TLS_PORT")
.and_then(|s| s.parse::<u16>().ok())
.unwrap_or(40001);
(host, port)
}
pub fn read_redis_password() -> String {
read_env_var("REDIS_PASSWORD").expect("Failed to read REDIS_PASSWORD env")
}
#[cfg(not(feature = "i-redis-stack"))]
pub fn read_redis_username() -> String {
read_env_var("REDIS_USERNAME").expect("Failed to read REDIS_USERNAME env")
}
// the CI settings for redis-stack don't set up custom ACL rules
#[cfg(feature = "i-redis-stack")]
pub fn read_redis_username() -> String {
read_env_var("REDIS_USERNAME").unwrap_or("default".into())
}
#[cfg(feature = "sentinel-auth")]
pub fn read_sentinel_password() -> String {
read_env_var("REDIS_SENTINEL_PASSWORD").expect("Failed to read REDIS_SENTINEL_PASSWORD env")
}
#[cfg(feature = "unix-sockets")]
pub fn read_unix_socket_path() -> String {
let dir = read_env_var("REDIS_UNIX_SOCK_CONTAINER_DIR").expect("Failed to read REDIS_UNIX_SOCK_CONTAINER_DIR");
let sock = read_env_var("REDIS_UNIX_SOCK").expect("Failed to read REDIS_UNIX_SOCK");
format!("{}/{}", dir, sock)
}
pub fn read_sentinel_server() -> (String, u16) {
let host = read_env_var("FRED_REDIS_SENTINEL_HOST").unwrap_or("127.0.0.1".into());
let port = read_env_var("FRED_REDIS_SENTINEL_PORT")
.and_then(|s| s.parse::<u16>().ok())
.unwrap_or(26379);
(host, port)
}
#[cfg(any(
feature = "enable-rustls",
feature = "enable-native-tls",
feature = "enable-rustls-ring"
))]
#[allow(dead_code)]
struct TlsCreds {
root_cert_der: Vec<u8>,
root_cert_pem: Vec<u8>,
client_cert_der: Vec<u8>,
client_cert_pem: Vec<u8>,
client_key_der: Vec<u8>,
client_key_pem: Vec<u8>,
}
#[cfg(any(
feature = "enable-rustls",
feature = "enable-native-tls",
feature = "enable-rustls-ring"
))]
fn check_file_contents(value: &[u8], msg: &str) {
if value.is_empty() {
panic!("Invalid empty TLS file: {}", msg);
}
}
/// Read the (root cert.pem, root cert.der, client cert.pem, client cert.der, client key.pem, client key.der) tuple
/// from the test/tmp/creds directory.
#[cfg(any(
feature = "enable-native-tls",
feature = "enable-rustls",
feature = "enable-rustls-ring"
))]
fn read_tls_creds() -> TlsCreds {
let creds_path = read_env_var("FRED_TEST_TLS_CREDS").expect("Failed to read TLS path from env");
let root_cert_pem_path = format!("{}/ca.pem", creds_path);
let root_cert_der_path = format!("{}/ca.crt", creds_path);
let client_cert_pem_path = format!("{}/client.pem", creds_path);
let client_cert_der_path = format!("{}/client.crt", creds_path);
let client_key_der_path = format!("{}/client_key.der", creds_path);
let client_key_pem_path = format!("{}/client.key8", creds_path);
let root_cert_pem = fs::read(&root_cert_pem_path).expect("Failed to read root cert pem");
let root_cert_der = fs::read(&root_cert_der_path).expect("Failed to read root cert der");
let client_cert_pem = fs::read(&client_cert_pem_path).expect("Failed to read client cert pem");
let client_cert_der = fs::read(&client_cert_der_path).expect("Failed to read client cert der");
let client_key_der = fs::read(&client_key_der_path).expect("Failed to read client key der");
let client_key_pem = fs::read(&client_key_pem_path).expect("Failed to read client key pem");
check_file_contents(&root_cert_pem, "root cert pem");
check_file_contents(&root_cert_der, "root cert der");
check_file_contents(&client_cert_pem, "client cert pem");
check_file_contents(&client_cert_der, "client cert der");
check_file_contents(&client_key_pem, "client key pem");
check_file_contents(&client_key_der, "client key der");
TlsCreds {
root_cert_pem,
root_cert_der,
client_cert_der,
client_cert_pem,
client_key_pem,
client_key_der,
}
}
#[cfg(any(feature = "enable-rustls", feature = "enable-rustls-ring"))]
fn create_rustls_config() -> TlsConnector {
use rustls::pki_types::PrivatePkcs8KeyDer;
let creds = read_tls_creds();
let mut root_store = RootCertStore::empty();
root_store
.add(creds.root_cert_der.clone().into())
.expect("Failed adding to rustls root cert store");
let cert_chain = vec![creds.client_cert_der.into(), creds.root_cert_der.into()];
ClientConfig::builder()
.with_root_certificates(root_store)
.with_client_auth_cert(cert_chain, PrivatePkcs8KeyDer::from(creds.client_key_der).into())
.expect("Failed to build rustls client config")
.into()
}
#[cfg(feature = "enable-native-tls")]
fn create_native_tls_config() -> TlsConnector {
let creds = read_tls_creds();
let root_cert = NativeTlsCertificate::from_pem(&creds.root_cert_pem).expect("Failed to parse root cert");
let mut builder = NativeTlsConnector::builder();
builder.add_root_certificate(root_cert);
let mut client_cert_chain = Vec::with_capacity(creds.client_cert_pem.len() + creds.root_cert_pem.len());
client_cert_chain.extend(&creds.client_cert_pem);
client_cert_chain.extend(&creds.root_cert_pem);
let identity =
Identity::from_pkcs8(&client_cert_chain, &creds.client_key_pem).expect("Failed to create client identity");
builder.identity(identity);
builder.try_into().expect("Failed to build native-tls connector")
}
fn reconnect_settings() -> (Option<ReconnectPolicy>, u32, bool) {
(Some(ReconnectPolicy::new_constant(300, RECONNECT_DELAY)), 3, true)
}
#[cfg(feature = "unix-sockets")]
fn create_server_config(cluster: bool) -> ServerConfig {
ServerConfig::Unix {
path: read_unix_socket_path().into(),
}
}
#[cfg(not(feature = "unix-sockets"))]
fn create_server_config(cluster: bool) -> ServerConfig {
if cluster {
let (host, port) = read_redis_cluster_host();
ServerConfig::Clustered {
hosts: vec![Server::new(host, port)],
policy: ClusterDiscoveryPolicy::default(),
}
} else {
let (host, port) = read_redis_centralized_host();
ServerConfig::Centralized {
server: Server::new(host, port),
}
}
}
fn create_normal_redis_config(cluster: bool, resp3: bool) -> (Config, PerformanceConfig) {
let config = Config {
fail_fast: read_fail_fast_env(),
server: create_server_config(cluster),
version: if resp3 { RespVersion::RESP3 } else { RespVersion::RESP2 },
username: Some(read_redis_username()),
password: Some(read_redis_password()),
..Default::default()
};
let perf = PerformanceConfig {
default_command_timeout: Duration::from_secs(20),
..Default::default()
};
(config, perf)
}
#[cfg(not(any(
feature = "enable-rustls",
feature = "enable-native-tls",
feature = "enable-rustls-ring"
)))]
fn create_redis_config(cluster: bool, resp3: bool) -> (Config, PerformanceConfig) {
create_normal_redis_config(cluster, resp3)
}
#[cfg(all(
feature = "enable-native-tls",
any(feature = "enable-rustls", feature = "enable-rustls-ring")
))]
fn create_redis_config(cluster: bool, resp3: bool) -> (Config, PerformanceConfig) {
// if both are enabled then don't use either since all the tests assume one or the other
create_normal_redis_config(cluster, resp3)
}
#[cfg(all(
any(feature = "enable-rustls", feature = "enable-rustls-ring"),
not(feature = "enable-native-tls")
))]
fn create_redis_config(cluster: bool, resp3: bool) -> (Config, PerformanceConfig) {
if !read_ci_tls_env() {
return create_normal_redis_config(cluster, resp3);
}
debug!("Creating rustls test config...");
let config = Config {
fail_fast: read_fail_fast_env(),
server: create_server_config(cluster),
version: if resp3 { RespVersion::RESP3 } else { RespVersion::RESP2 },
tls: Some(TlsConfig {
connector: create_rustls_config(),
hostnames: TlsHostMapping::DefaultHost,
}),
username: Some(read_redis_username()),
password: Some(read_redis_password()),
..Default::default()
};
let perf = PerformanceConfig {
default_command_timeout: Duration::from_secs(20),
..Default::default()
};
(config, perf)
}
#[cfg(all(
feature = "enable-native-tls",
not(any(feature = "enable-rustls", feature = "enable-rustls-ring"))
))]
fn create_redis_config(cluster: bool, resp3: bool) -> (Config, PerformanceConfig) {
if !read_ci_tls_env() {
return create_normal_redis_config(cluster, resp3);
}
debug!("Creating native-tls test config...");
let config = Config {
fail_fast: read_fail_fast_env(),
server: create_server_config(cluster),
version: if resp3 { RespVersion::RESP3 } else { RespVersion::RESP2 },
tls: Some(TlsConfig {
connector: create_native_tls_config(),
hostnames: TlsHostMapping::DefaultHost,
}),
username: Some(read_redis_username()),
password: Some(read_redis_password()),
..Default::default()
};
let perf = PerformanceConfig {
default_command_timeout: Duration::from_secs(20),
..Default::default()
};
(config, perf)
}
async fn flushall_between_tests(client: &Client) -> Result<(), Error> {
if should_flushall_between_tests() {
client.flushall_cluster().await
} else {
Ok(())
}
}
async fn check_panic(client: &Client, jh: ConnectHandle, err: Error) {
println!("Checking panic after: {:?}", err);
let _ = client.quit().await;
jh.await.unwrap().unwrap();
panic!("{:?}", err);
}
pub async fn run_sentinel<F, Fut>(func: F, resp3: bool)
where
F: Fn(Client, Config) -> Fut,
Fut: Future<Output = Result<(), Error>>,
{
let policy = ReconnectPolicy::new_constant(300, RECONNECT_DELAY);
let connection = ConnectionConfig::default();
let config = Config {
fail_fast: read_fail_fast_env(),
version: if resp3 { RespVersion::RESP3 } else { RespVersion::RESP2 },
server: ServerConfig::Sentinel {
hosts: vec![read_sentinel_server().into()],
service_name: "redis-sentinel-main".into(),
#[cfg(feature = "sentinel-auth")]
username: None,
#[cfg(feature = "sentinel-auth")]
password: Some(read_sentinel_password()),
},
password: Some(read_redis_password()),
..Default::default()
};
let perf = PerformanceConfig::default();
let client = Client::new(config.clone(), Some(perf), Some(connection), Some(policy));
let _client = client.clone();
let jh = client.connect();
client.wait_for_connect().await.expect("Failed to connect client");
if let Err(err) = flushall_between_tests(&client).await {
check_panic(&client, jh, err).await;
} else if let Err(err) = func(_client, config.clone()).await {
check_panic(&client, jh, err).await;
} else {
let _ = client.quit().await;
jh.await.unwrap().unwrap();
}
}
pub async fn run_cluster<F, Fut>(func: F, resp3: bool)
where
F: Fn(Client, Config) -> Fut,
Fut: Future<Output = Result<(), Error>>,
{
let (policy, cmd_attempts, fail_fast) = reconnect_settings();
let mut connection = ConnectionConfig::default();
let (mut config, perf) = create_redis_config(true, resp3);
connection.max_command_attempts = cmd_attempts;
connection.max_redirections = 10;
connection.unresponsive = UnresponsiveConfig {
max_timeout: Some(Duration::from_secs(10)),
interval: Duration::from_millis(400),
};
config.fail_fast = fail_fast;
let client = Client::new(config.clone(), Some(perf), Some(connection), policy);
let _client = client.clone();
let jh = client.connect();
client.wait_for_connect().await.expect("Failed to connect client");
if let Err(err) = flushall_between_tests(&client).await {
check_panic(&client, jh, err).await;
} else if let Err(err) = func(_client, config.clone()).await {
check_panic(&client, jh, err).await;
} else {
let _ = client.quit().await;
jh.await.unwrap().unwrap();
}
}
pub async fn run_centralized<F, Fut>(func: F, resp3: bool)
where
F: Fn(Client, Config) -> Fut,
Fut: Future<Output = Result<(), Error>>,
{
if should_use_sentinel_config() {
return run_sentinel(func, resp3).await;
}
let (policy, cmd_attempts, fail_fast) = reconnect_settings();
let mut connection = ConnectionConfig::default();
let (mut config, perf) = create_redis_config(false, resp3);
connection.max_command_attempts = cmd_attempts;
connection.unresponsive = UnresponsiveConfig {
max_timeout: Some(Duration::from_secs(10)),
interval: Duration::from_millis(400),
};
config.fail_fast = fail_fast;
let client = Client::new(config.clone(), Some(perf), Some(connection), policy);
let _client = client.clone();
let jh = client.connect();
client.wait_for_connect().await.expect("Failed to connect client");
if let Err(err) = flushall_between_tests(&client).await {
check_panic(&client, jh, err).await;
} else if let Err(err) = func(_client, config.clone()).await {
check_panic(&client, jh, err).await;
} else {
let _ = client.quit().await;
jh.await.unwrap().unwrap();
}
}
/// Check whether the server is Valkey.
pub async fn check_valkey(client: &Client) -> bool {
let info: String = match client.info(Some(InfoKind::Server)).await {
Ok(val) => val,
Err(e) => {
warn!("Failed to check valkey server: {:?}", e);
return false;
},
};
for line in info.lines() {
let parts: Vec<_> = line.split(":").collect();
if parts.len() == 2 && parts[0] == "server_name" && parts[1] == "valkey" {
return true;
}
}
false
}
macro_rules! centralized_test_panic(
($module:tt, $name:tt) => {
#[cfg(not(any(feature = "enable-rustls", feature = "enable-native-tls", feature = "enable-rustls-ring")))]
mod $name {
#[tokio::test(flavor = "multi_thread")]
#[should_panic]
async fn resp2() {
if crate::integration::utils::read_ci_tls_env() {
panic!("");
}
let _ = pretty_env_logger::try_init();
crate::integration::utils::run_centralized(crate::integration::$module::$name, false).await;
}
#[tokio::test(flavor = "multi_thread")]
#[should_panic]
async fn resp3() {
if crate::integration::utils::read_ci_tls_env() {
panic!("");
}
let _ = pretty_env_logger::try_init();
crate::integration::utils::run_centralized(crate::integration::$module::$name, true).await;
}
}
}
);
macro_rules! cluster_test_panic(
($module:tt, $name:tt) => {
mod $name {
#[cfg(not(any(feature = "i-redis-stack", feature = "unix-sockets")))]
#[tokio::test(flavor = "multi_thread")]
#[should_panic]
async fn resp2() {
if crate::integration::utils::should_use_sentinel_config() {
panic!("");
}
let _ = pretty_env_logger::try_init();
crate::integration::utils::run_cluster(crate::integration::$module::$name, false).await;
}
#[cfg(not(any(feature = "i-redis-stack", feature = "unix-sockets")))]
#[tokio::test(flavor = "multi_thread")]
#[should_panic]
async fn resp3() {
if crate::integration::utils::should_use_sentinel_config() {
panic!("");
}
let _ = pretty_env_logger::try_init();
crate::integration::utils::run_cluster(crate::integration::$module::$name, true).await;
}
}
}
);
macro_rules! centralized_test(
($module:tt, $name:tt) => {
#[cfg(not(any(feature = "enable-rustls", feature = "enable-native-tls", feature = "enable-rustls-ring")))]
mod $name {
#[tokio::test(flavor = "multi_thread")]
async fn resp2() {
if crate::integration::utils::read_ci_tls_env() {
return;
}
let _ = pretty_env_logger::try_init();
crate::integration::utils::run_centralized(crate::integration::$module::$name, false).await;
}
#[tokio::test(flavor = "multi_thread")]
async fn resp3() {
if crate::integration::utils::read_ci_tls_env() {
return;
}
let _ = pretty_env_logger::try_init();
crate::integration::utils::run_centralized(crate::integration::$module::$name, true).await;
}
}
}
);
macro_rules! cluster_test(
($module:tt, $name:tt) => {
mod $name {
#[cfg(not(any(feature = "i-redis-stack", feature = "unix-sockets")))]
#[tokio::test(flavor = "multi_thread")]
async fn resp2() {
if crate::integration::utils::should_use_sentinel_config() {
return;
}
let _ = pretty_env_logger::try_init();
crate::integration::utils::run_cluster(crate::integration::$module::$name, false).await;
}
#[cfg(not(any(feature = "i-redis-stack", feature = "unix-sockets")))]
#[tokio::test(flavor = "multi_thread")]
async fn resp3() {
if crate::integration::utils::should_use_sentinel_config() {
return;
}
let _ = pretty_env_logger::try_init();
crate::integration::utils::run_cluster(crate::integration::$module::$name, true).await;
}
}
}
);
macro_rules! return_err(
($($arg:tt)*) => { {
return Err(fred::error::Error::new(
fred::error::ErrorKind::Unknown, format!($($arg)*)
));
} }
);
macro_rules! check_redis_7 (
($client:ident) => {
if $client.server_version().unwrap().major < 7 {
return Ok(());
}
}
);