@@ -4,7 +4,10 @@ use anyhow::Result;
4
4
use serde:: Deserialize ;
5
5
use tracing:: { error, event, Level } ;
6
6
7
+ use crate :: evergreen:: evg_config_utils:: is_bazel_suite;
8
+
7
9
use super :: { external_cmd:: run_command, resmoke_suite:: ResmokeSuiteConfig } ;
10
+ use std:: collections:: HashMap ;
8
11
9
12
/// Interface for discovering details about test suites.
10
13
pub trait TestDiscovery : Send + Sync {
@@ -45,6 +48,7 @@ pub struct ResmokeProxy {
45
48
skip_covered_tests : bool ,
46
49
/// True if test discovery should include tests that are tagged with fully disabled features.
47
50
include_fully_disabled_feature_tests : bool ,
51
+ bazel_suite_configs : BazelConfigs ,
48
52
}
49
53
50
54
impl ResmokeProxy {
@@ -55,10 +59,12 @@ impl ResmokeProxy {
55
59
/// * `resmoke_cmd` - Command to invoke resmoke.
56
60
/// * `skip_covered_tests` - Whether the generator should skip tests run in more complex suites.
57
61
/// * `include_fully_disabled_feature_tests` - If the generator should include tests that are tagged with fully disabled features.
62
+ /// * `bazel_suite_configs` - Optional bazel suite configurations.
58
63
pub fn new (
59
64
resmoke_cmd : & str ,
60
65
skip_covered_tests : bool ,
61
66
include_fully_disabled_feature_tests : bool ,
67
+ bazel_suite_configs : BazelConfigs ,
62
68
) -> Self {
63
69
let cmd_parts: Vec < _ > = resmoke_cmd. split ( ' ' ) . collect ( ) ;
64
70
let cmd = cmd_parts[ 0 ] ;
@@ -68,10 +74,46 @@ impl ResmokeProxy {
68
74
resmoke_script : script,
69
75
skip_covered_tests,
70
76
include_fully_disabled_feature_tests,
77
+ bazel_suite_configs,
71
78
}
72
79
}
73
80
}
74
81
82
+ #[ derive( Debug , Clone , Default ) ]
83
+ pub struct BazelConfigs {
84
+ /// Map of bazel resmoke config targets to their generated suite config YAMLs.
85
+ configs : HashMap < String , String > ,
86
+ }
87
+
88
+ impl BazelConfigs {
89
+ pub fn from_yaml_file ( path : & Path ) -> Result < Self > {
90
+ let contents = std:: fs:: read_to_string ( path) ?;
91
+ let configs: Result < HashMap < String , String > , serde_yaml:: Error > =
92
+ serde_yaml:: from_str ( & contents) ;
93
+ if configs. is_err ( ) {
94
+ error ! (
95
+ file = path. display( ) . to_string( ) ,
96
+ contents = & contents,
97
+ "Failed to parse bazel configs from yaml file" ,
98
+ ) ;
99
+ }
100
+ Ok ( Self { configs : configs? } )
101
+ }
102
+
103
+ /// Get the generated suite config for a bazel resmoke target.
104
+ ///
105
+ /// # Arguments
106
+ ///
107
+ /// * `target` - Bazel resmoke test target, like "//buildscripts/resmoke:core".
108
+ ///
109
+ /// # Returns
110
+ ///
111
+ /// The path the the generated suite config YAML, like "bazel-out/buildscripts/resmoke/core_config.yml".
112
+ pub fn get ( & self , target : & str ) -> & str {
113
+ self . configs . get ( & format ! ( "{}_config" , target) ) . unwrap ( )
114
+ }
115
+ }
116
+
75
117
/// Details about tests comprising a test suite.
76
118
#[ derive( Debug , Deserialize ) ]
77
119
#[ allow( dead_code) ]
@@ -94,9 +136,15 @@ impl TestDiscovery for ResmokeProxy {
94
136
///
95
137
/// A list of tests belonging to given suite.
96
138
fn discover_tests ( & self , suite_name : & str ) -> Result < Vec < String > > {
139
+ let suite_config = if is_bazel_suite ( suite_name) {
140
+ self . bazel_suite_configs . get ( suite_name)
141
+ } else {
142
+ suite_name
143
+ } ;
144
+
97
145
let mut cmd = vec ! [ & * self . resmoke_cmd] ;
98
146
cmd. append ( & mut self . resmoke_script . iter ( ) . map ( |s| s. as_str ( ) ) . collect ( ) ) ;
99
- cmd. append ( & mut vec ! [ "test-discovery" , "--suite" , suite_name ] ) ;
147
+ cmd. append ( & mut vec ! [ "test-discovery" , "--suite" , suite_config ] ) ;
100
148
101
149
// When running in a patch build, we use the --skipTestsCoveredByMoreComplexSuites
102
150
// flag to tell Resmoke to exclude any tests in the given suite that will
@@ -114,7 +162,7 @@ impl TestDiscovery for ResmokeProxy {
114
162
115
163
event ! (
116
164
Level :: INFO ,
117
- suite_name ,
165
+ suite_config ,
118
166
duration_ms = start. elapsed( ) . as_millis( ) as u64 ,
119
167
"Resmoke test discovery finished"
120
168
) ;
@@ -146,9 +194,15 @@ impl TestDiscovery for ResmokeProxy {
146
194
///
147
195
/// Resmoke configuration for the given suite.
148
196
fn get_suite_config ( & self , suite_name : & str ) -> Result < ResmokeSuiteConfig > {
197
+ let suite_config = if is_bazel_suite ( suite_name) {
198
+ self . bazel_suite_configs . get ( suite_name)
199
+ } else {
200
+ suite_name
201
+ } ;
202
+
149
203
let mut cmd = vec ! [ & * self . resmoke_cmd] ;
150
204
cmd. append ( & mut self . resmoke_script . iter ( ) . map ( |s| s. as_str ( ) ) . collect ( ) ) ;
151
- cmd. append ( & mut vec ! [ "suiteconfig" , "--suite" , suite_name ] ) ;
205
+ cmd. append ( & mut vec ! [ "suiteconfig" , "--suite" , suite_config ] ) ;
152
206
let cmd_output = run_command ( & cmd) . unwrap ( ) ;
153
207
154
208
Ok ( ResmokeSuiteConfig :: from_str ( & cmd_output) ?)
0 commit comments