1
- use crate :: actions:: experiments:: ExperimentError ;
2
- use crate :: config:: Config ;
3
- use crate :: db:: { Database , QueryUtils } ;
1
+ use crate :: actions:: { experiments:: ExperimentError , Action , ActionsCtx } ;
2
+ use crate :: db:: QueryUtils ;
4
3
use crate :: experiments:: { CapLints , CrateSelect , Experiment , GitHubIssue , Mode , Status } ;
5
4
use crate :: prelude:: * ;
6
5
use crate :: toolchain:: Toolchain ;
@@ -33,21 +32,23 @@ impl CreateExperiment {
33
32
ignore_blacklist : false ,
34
33
}
35
34
}
35
+ }
36
36
37
- pub fn apply ( self , db : & Database , config : & Config ) -> Fallible < ( ) > {
37
+ impl Action for CreateExperiment {
38
+ fn apply ( self , ctx : & ActionsCtx ) -> Fallible < ( ) > {
38
39
// Ensure no duplicate experiments are created
39
- if Experiment :: exists ( db, & self . name ) ? {
40
- return Err ( ExperimentError :: AlreadyExists ( self . name ) . into ( ) ) ;
40
+ if Experiment :: exists ( & ctx . db , & self . name ) ? {
41
+ return Err ( ExperimentError :: AlreadyExists ( self . name . clone ( ) ) . into ( ) ) ;
41
42
}
42
43
43
44
// Ensure no experiment with duplicate toolchains is created
44
45
if self . toolchains [ 0 ] == self . toolchains [ 1 ] {
45
46
return Err ( ExperimentError :: DuplicateToolchains . into ( ) ) ;
46
47
}
47
48
48
- let crates = crate :: crates:: lists:: get_crates ( self . crates , db, config) ?;
49
+ let crates = crate :: crates:: lists:: get_crates ( self . crates , & ctx . db , & ctx . config ) ?;
49
50
50
- db. transaction ( |transaction| {
51
+ ctx . db . transaction ( |transaction| {
51
52
transaction. execute (
52
53
"INSERT INTO experiments \
53
54
(name, mode, cap_lints, toolchain_start, toolchain_end, priority, created_at, \
@@ -70,7 +71,7 @@ impl CreateExperiment {
70
71
) ?;
71
72
72
73
for krate in & crates {
73
- let skipped = !self . ignore_blacklist && config. should_skip ( krate) ;
74
+ let skipped = !self . ignore_blacklist && ctx . config . should_skip ( krate) ;
74
75
transaction. execute (
75
76
"INSERT INTO experiment_crates (experiment, crate, skipped) VALUES (?1, ?2, ?3);" ,
76
77
& [ & self . name , & :: serde_json:: to_string ( & krate) ?, & skipped] ,
@@ -87,7 +88,7 @@ impl CreateExperiment {
87
88
#[ cfg( test) ]
88
89
mod tests {
89
90
use super :: CreateExperiment ;
90
- use crate :: actions:: ExperimentError ;
91
+ use crate :: actions:: { Action , ActionsCtx , ExperimentError } ;
91
92
use crate :: config:: { Config , CrateConfig } ;
92
93
use crate :: crates:: Crate ;
93
94
use crate :: db:: { Database , QueryUtils } ;
@@ -98,6 +99,7 @@ mod tests {
98
99
fn test_creation ( ) {
99
100
let db = Database :: temp ( ) . unwrap ( ) ;
100
101
let config = Config :: default ( ) ;
102
+ let ctx = ActionsCtx :: new ( & db, & config) ;
101
103
102
104
crate :: crates:: lists:: setup_test_lists ( & db, & config) . unwrap ( ) ;
103
105
@@ -118,7 +120,7 @@ mod tests {
118
120
} ) ,
119
121
ignore_blacklist : true ,
120
122
}
121
- . apply ( & db , & config )
123
+ . apply ( & ctx )
122
124
. unwrap ( ) ;
123
125
124
126
let ex = Experiment :: get ( & db, "foo" ) . unwrap ( ) . unwrap ( ) ;
@@ -182,22 +184,23 @@ mod tests {
182
184
broken : false ,
183
185
} ,
184
186
) ;
187
+ let ctx = ActionsCtx :: new ( & db, & config) ;
185
188
186
189
crate :: crates:: lists:: setup_test_lists ( & db, & config) . unwrap ( ) ;
187
190
188
191
CreateExperiment {
189
192
ignore_blacklist : false ,
190
193
..CreateExperiment :: dummy ( "foo" )
191
194
}
192
- . apply ( & db , & config )
195
+ . apply ( & ctx )
193
196
. unwrap ( ) ;
194
197
assert ! ( is_skipped( & db, "foo" , "build-pass" ) ) ;
195
198
196
199
CreateExperiment {
197
200
ignore_blacklist : true ,
198
201
..CreateExperiment :: dummy ( "bar" )
199
202
}
200
- . apply ( & db , & config )
203
+ . apply ( & ctx )
201
204
. unwrap ( ) ;
202
205
assert ! ( !is_skipped( & db, "bar" , "build-pass" ) ) ;
203
206
}
@@ -206,6 +209,7 @@ mod tests {
206
209
fn test_duplicate_toolchains ( ) {
207
210
let db = Database :: temp ( ) . unwrap ( ) ;
208
211
let config = Config :: default ( ) ;
212
+ let ctx = ActionsCtx :: new ( & db, & config) ;
209
213
210
214
crate :: crates:: lists:: setup_test_lists ( & db, & config) . unwrap ( ) ;
211
215
@@ -220,7 +224,7 @@ mod tests {
220
224
github_issue : None ,
221
225
ignore_blacklist : false ,
222
226
}
223
- . apply ( & db , & config )
227
+ . apply ( & ctx )
224
228
. unwrap_err ( ) ;
225
229
226
230
assert_eq ! (
@@ -233,6 +237,7 @@ mod tests {
233
237
fn test_duplicate_name ( ) {
234
238
let db = Database :: temp ( ) . unwrap ( ) ;
235
239
let config = Config :: default ( ) ;
240
+ let ctx = ActionsCtx :: new ( & db, & config) ;
236
241
237
242
crate :: crates:: lists:: setup_test_lists ( & db, & config) . unwrap ( ) ;
238
243
@@ -247,7 +252,7 @@ mod tests {
247
252
github_issue : None ,
248
253
ignore_blacklist : false ,
249
254
}
250
- . apply ( & db , & config )
255
+ . apply ( & ctx )
251
256
. unwrap ( ) ;
252
257
253
258
// While the second one fails
@@ -261,7 +266,7 @@ mod tests {
261
266
github_issue : None ,
262
267
ignore_blacklist : false ,
263
268
}
264
- . apply ( & db , & config )
269
+ . apply ( & ctx )
265
270
. unwrap_err ( ) ;
266
271
267
272
assert_eq ! (
0 commit comments