@@ -12,10 +12,11 @@ use crate::bors::handlers::trybuild::{command_try_build, command_try_cancel, TRY
12
12
use crate :: bors:: handlers:: workflow:: {
13
13
handle_check_suite_completed, handle_workflow_completed, handle_workflow_started,
14
14
} ;
15
- use crate :: bors:: { BorsContext , Comment , RepositoryClient , RepositoryLoader , RepositoryState } ;
16
- use crate :: database:: DbClient ;
17
- use crate :: utils:: logging:: LogError ;
18
- use crate :: TeamApiClient ;
15
+ use crate :: bors:: { BorsContext , Comment , RepositoryLoader , RepositoryState } ;
16
+ use crate :: { PgDbClient , TeamApiClient } ;
17
+
18
+ #[ cfg( test) ]
19
+ use crate :: tests:: util:: TestSyncMarker ;
19
20
20
21
mod help;
21
22
mod labels;
@@ -24,18 +25,21 @@ mod refresh;
24
25
mod trybuild;
25
26
mod workflow;
26
27
28
+ #[ cfg( test) ]
29
+ pub static WAIT_FOR_WORKFLOW_STARTED : TestSyncMarker = TestSyncMarker :: new ( ) ;
30
+
27
31
/// This function executes a single BORS repository event
28
- pub async fn handle_bors_repository_event < Client : RepositoryClient > (
32
+ pub async fn handle_bors_repository_event (
29
33
event : BorsRepositoryEvent ,
30
- ctx : Arc < BorsContext < Client > > ,
34
+ ctx : Arc < BorsContext > ,
31
35
) -> anyhow:: Result < ( ) > {
32
36
let db = Arc :: clone ( & ctx. db ) ;
33
37
let Some ( repo) = ctx
34
38
. repositories
35
39
. read ( )
36
40
. unwrap ( )
37
41
. get ( event. repository ( ) )
38
- . map ( Arc :: clone )
42
+ . cloned ( )
39
43
else {
40
44
return Err ( anyhow:: anyhow!(
41
45
"Repository {} not found in the bot state" ,
@@ -61,7 +65,6 @@ pub async fn handle_bors_repository_event<Client: RepositoryClient>(
61
65
. instrument ( span. clone ( ) )
62
66
. await
63
67
{
64
- span. log_error ( error) ;
65
68
repo. client
66
69
. post_comment (
67
70
pr_number,
@@ -71,6 +74,7 @@ pub async fn handle_bors_repository_event<Client: RepositoryClient>(
71
74
)
72
75
. await
73
76
. context ( "Cannot send comment reacting to an error" ) ?;
77
+ return Err ( error. context ( "Cannot perform command" ) ) ;
74
78
}
75
79
}
76
80
@@ -80,47 +84,44 @@ pub async fn handle_bors_repository_event<Client: RepositoryClient>(
80
84
repo = payload. repository. to_string( ) ,
81
85
id = payload. run_id. into_inner( )
82
86
) ;
83
- if let Err ( error ) = handle_workflow_started ( db, payload)
87
+ handle_workflow_started ( db, payload)
84
88
. instrument ( span. clone ( ) )
85
- . await
86
- {
87
- span . log_error ( error ) ;
88
- }
89
+ . await ? ;
90
+
91
+ # [ cfg ( test ) ]
92
+ WAIT_FOR_WORKFLOW_STARTED . mark ( ) ;
89
93
}
90
94
BorsRepositoryEvent :: WorkflowCompleted ( payload) => {
91
95
let span = tracing:: info_span!(
92
96
"Workflow completed" ,
93
97
repo = payload. repository. to_string( ) ,
94
98
id = payload. run_id. into_inner( )
95
99
) ;
96
- if let Err ( error ) = handle_workflow_completed ( repo, db, payload)
100
+ handle_workflow_completed ( repo, db, payload)
97
101
. instrument ( span. clone ( ) )
98
- . await
99
- {
100
- span. log_error ( error) ;
101
- }
102
+ . await ?;
102
103
}
103
104
BorsRepositoryEvent :: CheckSuiteCompleted ( payload) => {
104
105
let span = tracing:: info_span!(
105
106
"Check suite completed" ,
106
107
repo = payload. repository. to_string( ) ,
107
108
) ;
108
- if let Err ( error ) = handle_check_suite_completed ( repo, db, payload)
109
+ handle_check_suite_completed ( repo, db, payload)
109
110
. instrument ( span. clone ( ) )
110
- . await
111
- {
112
- span. log_error ( error) ;
113
- }
111
+ . await ?;
114
112
}
115
113
}
116
114
Ok ( ( ) )
117
115
}
118
116
117
+ #[ cfg( test) ]
118
+ pub static WAIT_FOR_REFRESH : TestSyncMarker = TestSyncMarker :: new ( ) ;
119
+
119
120
/// This function executes a single BORS global event
120
- pub async fn handle_bors_global_event < Client : RepositoryClient > (
121
+ pub async fn handle_bors_global_event (
121
122
event : BorsGlobalEvent ,
122
- ctx : Arc < BorsContext < Client > > ,
123
- repo_loader : & dyn RepositoryLoader < Client > ,
123
+ ctx : Arc < BorsContext > ,
124
+ repo_loader : & RepositoryLoader ,
124
125
team_api_client : & TeamApiClient ,
125
126
) -> anyhow:: Result < ( ) > {
126
127
let db = Arc :: clone ( & ctx. db ) ;
@@ -133,7 +134,7 @@ pub async fn handle_bors_global_event<Client: RepositoryClient>(
133
134
}
134
135
BorsGlobalEvent :: Refresh => {
135
136
let span = tracing:: info_span!( "Refresh" ) ;
136
- let repos: Vec < Arc < RepositoryState < Client > > > =
137
+ let repos: Vec < Arc < RepositoryState > > =
137
138
ctx. repositories . read ( ) . unwrap ( ) . values ( ) . cloned ( ) . collect ( ) ;
138
139
futures:: future:: join_all ( repos. into_iter ( ) . map ( |repo| {
139
140
let repo = Arc :: clone ( & repo) ;
@@ -146,15 +147,18 @@ pub async fn handle_bors_global_event<Client: RepositoryClient>(
146
147
} ) )
147
148
. instrument ( span)
148
149
. await ;
150
+
151
+ #[ cfg( test) ]
152
+ WAIT_FOR_REFRESH . mark ( ) ;
149
153
}
150
154
}
151
155
Ok ( ( ) )
152
156
}
153
157
154
- async fn handle_comment < Client : RepositoryClient > (
155
- repo : Arc < RepositoryState < Client > > ,
156
- database : Arc < dyn DbClient > ,
157
- ctx : Arc < BorsContext < Client > > ,
158
+ async fn handle_comment (
159
+ repo : Arc < RepositoryState > ,
160
+ database : Arc < PgDbClient > ,
161
+ ctx : Arc < BorsContext > ,
158
162
comment : PullRequestComment ,
159
163
) -> anyhow:: Result < ( ) > {
160
164
let pr_number = comment. pr_number ;
@@ -237,9 +241,9 @@ async fn handle_comment<Client: RepositoryClient>(
237
241
Ok ( ( ) )
238
242
}
239
243
240
- async fn reload_repos < Client : RepositoryClient > (
241
- ctx : Arc < BorsContext < Client > > ,
242
- repo_loader : & dyn RepositoryLoader < Client > ,
244
+ async fn reload_repos (
245
+ ctx : Arc < BorsContext > ,
246
+ repo_loader : & RepositoryLoader ,
243
247
team_api_client : & TeamApiClient ,
244
248
) -> anyhow:: Result < ( ) > {
245
249
let reloaded_repos = repo_loader. load_repositories ( team_api_client) . await ?;
@@ -281,7 +285,7 @@ mod tests {
281
285
run_test ( pool, |mut tester| async {
282
286
tester
283
287
. post_comment ( Comment :: from ( "@bors ping" ) . with_author ( User :: bors_bot ( ) ) )
284
- . await ;
288
+ . await ? ;
285
289
// Returning here will make sure that no comments were received
286
290
Ok ( tester)
287
291
} )
0 commit comments