@@ -8,25 +8,80 @@ use crate::{
88 error:: Result ,
99 event:: cmap:: CmapEvent ,
1010 serde_util,
11- test:: { util:: fail_point:: FailPoint , RunOn } ,
11+ test:: {
12+ get_topology,
13+ log_uncaptured,
14+ server_version_matches,
15+ util:: fail_point:: FailPoint ,
16+ Serverless ,
17+ Topology ,
18+ } ,
1219} ;
1320
1421#[ derive( Debug , Deserialize ) ]
1522#[ serde( rename_all = "camelCase" , deny_unknown_fields) ]
16- pub struct TestFile {
23+ pub ( super ) struct TestFile {
1724 #[ serde( rename = "version" ) ]
1825 _version : u8 , // can ignore this field as there's only one version
1926 #[ serde( rename = "style" ) ]
2027 _style : TestStyle , // we use the presence of fail_point / run_on to determine this
21- pub description : String ,
22- pub ( crate ) pool_options : Option < ConnectionPoolOptions > ,
23- pub operations : Vec < ThreadedOperation > ,
24- pub error : Option < Error > ,
25- pub ( crate ) events : Vec < CmapEvent > ,
28+ pub ( super ) description : String ,
29+ pub ( super ) pool_options : Option < ConnectionPoolOptions > ,
30+ pub ( super ) operations : Vec < ThreadedOperation > ,
31+ pub ( super ) error : Option < Error > ,
32+ pub ( super ) events : Vec < CmapEvent > ,
2633 #[ serde( default ) ]
27- pub ignore : Vec < String > ,
28- pub fail_point : Option < FailPoint > ,
29- pub ( crate ) run_on : Option < Vec < RunOn > > ,
34+ pub ( super ) ignore : Vec < String > ,
35+ pub ( super ) fail_point : Option < FailPoint > ,
36+ pub ( super ) run_on : Option < Vec < RunOn > > ,
37+ }
38+
39+ #[ derive( Debug , Deserialize ) ]
40+ #[ serde( rename_all = "camelCase" , deny_unknown_fields) ]
41+ pub ( super ) struct RunOn {
42+ pub ( super ) min_server_version : Option < String > ,
43+ pub ( super ) max_server_version : Option < String > ,
44+ pub ( super ) topology : Option < Vec < Topology > > ,
45+ pub ( super ) serverless : Option < Serverless > ,
46+ }
47+
48+ impl RunOn {
49+ pub ( super ) async fn can_run_on ( & self ) -> bool {
50+ if let Some ( ref min_version) = self . min_server_version {
51+ if !server_version_matches ( & format ! ( ">= {min_version}" ) ) . await {
52+ log_uncaptured ( format ! (
53+ "runOn mismatch: required server version >= {min_version}" ,
54+ ) ) ;
55+ return false ;
56+ }
57+ }
58+ if let Some ( ref max_version) = self . max_server_version {
59+ if !server_version_matches ( & format ! ( "<= {max_version}" ) ) . await {
60+ log_uncaptured ( format ! (
61+ "runOn mismatch: required server version <= {max_version}" ,
62+ ) ) ;
63+ return false ;
64+ }
65+ }
66+ if let Some ( ref topology) = self . topology {
67+ let actual_topology = get_topology ( ) . await ;
68+ if !topology. contains ( actual_topology) {
69+ log_uncaptured ( format ! (
70+ "runOn mismatch: required topology in {topology:?}, got {actual_topology:?}"
71+ ) ) ;
72+ return false ;
73+ }
74+ }
75+ if let Some ( ref serverless) = self . serverless {
76+ if !serverless. can_run ( ) {
77+ log_uncaptured ( format ! (
78+ "runOn mismatch: required serverless {serverless:?}"
79+ ) ) ;
80+ return false ;
81+ }
82+ }
83+ true
84+ }
3085}
3186
3287#[ derive( Debug , Deserialize ) ]
0 commit comments