@@ -370,21 +370,22 @@ mod tests {
370
370
use crate :: bors:: handlers:: trybuild:: {
371
371
TRY_BRANCH_NAME , TRY_BUILD_CHECK_RUN_NAME , TRY_MERGE_BRANCH_NAME ,
372
372
} ;
373
+ use crate :: database:: WorkflowStatus ;
373
374
use crate :: database:: operations:: get_all_workflows;
374
375
use crate :: github:: CommitSha ;
376
+ use crate :: tests:: BorsTester ;
375
377
use crate :: tests:: mocks:: {
376
- BorsBuilder , Comment , GitHubState , User , Workflow , WorkflowEvent , default_pr_number,
378
+ BorsBuilder , Comment , GitHubState , User , WorkflowEvent , WorkflowRunData , default_pr_number,
377
379
default_repo_name, run_test,
378
380
} ;
379
381
use octocrab:: params:: checks:: { CheckRunConclusion , CheckRunStatus } ;
380
382
381
383
#[ sqlx:: test]
382
384
async fn try_success ( pool : sqlx:: PgPool ) {
383
- run_test ( pool, async |tester| {
384
- tester. create_branch ( TRY_BRANCH_NAME ) . expect_suites ( 1 ) ;
385
+ run_test ( pool. clone ( ) , async |tester| {
385
386
tester. post_comment ( "@bors try" ) . await ?;
386
387
tester. expect_comments ( 1 ) . await ;
387
- tester. workflow_success ( tester. try_branch ( ) ) . await ?;
388
+ tester. workflow_full_success ( tester. try_branch ( ) ) . await ?;
388
389
insta:: assert_snapshot!(
389
390
tester. get_comment( ) . await ?,
390
391
@r#"
@@ -402,10 +403,9 @@ mod tests {
402
403
#[ sqlx:: test]
403
404
async fn try_failure ( pool : sqlx:: PgPool ) {
404
405
run_test ( pool, async |tester| {
405
- tester. create_branch ( TRY_BRANCH_NAME ) . expect_suites ( 1 ) ;
406
406
tester. post_comment ( "@bors try" ) . await ?;
407
407
tester. expect_comments ( 1 ) . await ;
408
- tester. workflow_failure ( tester. try_branch ( ) ) . await ?;
408
+ tester. workflow_full_failure ( tester. try_branch ( ) ) . await ?;
409
409
insta:: assert_snapshot!(
410
410
tester. get_comment( ) . await ?,
411
411
@r###"
@@ -516,7 +516,7 @@ mod tests {
516
516
. post_comment ( "@bors try parent=ea9c1b050cc8b420c2c211d2177811e564a4dc60" )
517
517
. await ?;
518
518
tester. expect_comments ( 1 ) . await ;
519
- tester. workflow_success ( tester. try_branch ( ) ) . await ?;
519
+ tester. workflow_full_success ( tester. try_branch ( ) ) . await ?;
520
520
tester. expect_comments ( 1 ) . await ;
521
521
tester. post_comment ( "@bors try parent=last" ) . await ?;
522
522
insta:: assert_snapshot!( tester. get_comment( ) . await ?, @r"
@@ -660,7 +660,7 @@ mod tests {
660
660
tester. post_comment ( "@bors try" ) . await ?;
661
661
tester. expect_comments ( 1 ) . await ;
662
662
tester
663
- . start_workflow ( Workflow :: from ( tester. try_branch ( ) ) . with_run_id ( 123 ) )
663
+ . workflow_start ( WorkflowRunData :: from ( tester. try_branch ( ) ) . with_run_id ( 123 ) )
664
664
. await ?;
665
665
666
666
tester. post_comment ( "@bors try" ) . await ?;
@@ -683,19 +683,18 @@ mod tests {
683
683
tester. post_comment ( "@bors try" ) . await ?;
684
684
tester. expect_comments ( 1 ) . await ;
685
685
tester
686
- . workflow_success ( Workflow :: from ( tester. try_branch ( ) ) . with_run_id ( 1 ) )
686
+ . workflow_full_success ( WorkflowRunData :: from ( tester. try_branch ( ) ) . with_run_id ( 1 ) )
687
687
. await ?;
688
688
tester. expect_comments ( 1 ) . await ;
689
689
690
- tester. get_branch_mut ( TRY_BRANCH_NAME ) . reset_suites ( ) ;
691
690
tester. post_comment ( "@bors try" ) . await ?;
692
691
insta:: assert_snapshot!( tester. get_comment( ) . await ?, @r"
693
692
:hourglass: Trying commit pr-1-sha with merge merge-main-sha1-pr-1-sha-1…
694
693
695
694
To cancel the try build, run the command `@bors try cancel`.
696
695
" ) ;
697
696
tester
698
- . workflow_success ( Workflow :: from ( tester. try_branch ( ) ) . with_run_id ( 2 ) )
697
+ . workflow_full_success ( WorkflowRunData :: from ( tester. try_branch ( ) ) . with_run_id ( 2 ) . with_check_suite_id ( 2 ) )
699
698
. await ?;
700
699
insta:: assert_snapshot!( tester. get_comment( ) . await ?, @r#"
701
700
:sunny: Try build successful ([Workflow1](https://github.com/workflows/Workflow1/2))
@@ -727,12 +726,12 @@ mod tests {
727
726
let branch = tester. try_branch ( ) ;
728
727
tester
729
728
. workflow_event ( WorkflowEvent :: started (
730
- Workflow :: from ( branch. clone ( ) ) . with_run_id ( 123 ) ,
729
+ WorkflowRunData :: from ( branch. clone ( ) ) . with_run_id ( 123 ) ,
731
730
) )
732
731
. await ?;
733
732
tester
734
733
. workflow_event ( WorkflowEvent :: started (
735
- Workflow :: from ( branch. clone ( ) ) . with_run_id ( 124 ) ,
734
+ WorkflowRunData :: from ( branch. clone ( ) ) . with_run_id ( 124 ) ,
736
735
) )
737
736
. await ?;
738
737
tester. post_comment ( "@bors try cancel" ) . await ?;
@@ -780,45 +779,33 @@ mod tests {
780
779
781
780
#[ sqlx:: test]
782
781
async fn try_cancel_ignore_finished_workflows ( pool : sqlx:: PgPool ) {
783
- let gh = run_test ( pool, async |tester| {
784
- tester. create_branch ( TRY_BRANCH_NAME ) . expect_suites ( 3 ) ;
782
+ let gh = run_test ( pool, async |tester : & mut BorsTester | {
785
783
tester. post_comment ( "@bors try" ) . await ?;
786
784
tester. expect_comments ( 1 ) . await ;
787
-
788
785
let branch = tester. try_branch ( ) ;
789
- tester
790
- . workflow_success ( Workflow :: from ( branch. clone ( ) ) . with_run_id ( 1 ) )
791
- . await ?;
792
- tester
793
- . workflow_failure ( Workflow :: from ( branch. clone ( ) ) . with_run_id ( 2 ) )
794
- . await ?;
795
- tester
796
- . workflow_event ( WorkflowEvent :: started (
797
- Workflow :: from ( branch) . with_run_id ( 3 ) ,
798
- ) )
799
- . await ?;
800
- tester. post_comment ( "@bors try cancel" ) . await ?;
801
- tester. expect_comments ( 1 ) . await ;
802
- Ok ( ( ) )
803
- } )
804
- . await ;
805
- gh. check_cancelled_workflows ( default_repo_name ( ) , & [ 3 ] ) ;
806
- }
807
786
808
- #[ sqlx:: test]
809
- async fn try_cancel_ignore_external_workflows ( pool : sqlx:: PgPool ) {
810
- let gh = run_test ( pool, async |tester| {
811
- tester. post_comment ( "@bors try" ) . await ?;
812
- tester. expect_comments ( 1 ) . await ;
813
- tester
814
- . workflow_success ( Workflow :: from ( tester. try_branch ( ) ) . make_external ( ) )
815
- . await ?;
787
+ let w1 = WorkflowRunData :: from ( branch. clone ( ) ) . with_run_id ( 1 ) ;
788
+ let w2 = WorkflowRunData :: from ( branch. clone ( ) ) . with_run_id ( 2 ) ;
789
+ let w3 = WorkflowRunData :: from ( branch) . with_run_id ( 3 ) ;
790
+ for workflow in [ & w1, & w2, & w3] {
791
+ tester
792
+ . default_repo ( )
793
+ . lock ( )
794
+ . update_workflow_run ( workflow. clone ( ) , WorkflowStatus :: Pending ) ;
795
+ }
796
+
797
+ tester. workflow_full_success ( w1) . await ?;
798
+ tester. workflow_full_success ( w2) . await ?;
799
+ tester. workflow_start ( w3) . await ?;
816
800
tester. post_comment ( "@bors try cancel" ) . await ?;
817
- tester. expect_comments ( 1 ) . await ;
801
+ insta:: assert_snapshot!( tester. get_comment( ) . await ?, @r"
802
+ Try build cancelled. Cancelled workflows:
803
+ - https://github.com/rust-lang/borstest/actions/runs/3
804
+ " ) ;
818
805
Ok ( ( ) )
819
806
} )
820
807
. await ;
821
- gh. check_cancelled_workflows ( default_repo_name ( ) , & [ ] ) ;
808
+ gh. check_cancelled_workflows ( default_repo_name ( ) , & [ 3 ] ) ;
822
809
}
823
810
824
811
#[ sqlx:: test]
@@ -883,7 +870,7 @@ try_succeed = ["+foo", "+bar", "-baz"]
883
870
repo. lock ( )
884
871
. get_pr ( default_pr_number ( ) )
885
872
. check_added_labels ( & [ ] ) ;
886
- tester. workflow_success ( tester. try_branch ( ) ) . await ?;
873
+ tester. workflow_full_success ( tester. try_branch ( ) ) . await ?;
887
874
tester. expect_comments ( 1 ) . await ;
888
875
let pr = repo. lock ( ) . get_pr ( default_pr_number ( ) ) . clone ( ) ;
889
876
pr. check_added_labels ( & [ "foo" , "bar" ] ) ;
@@ -903,7 +890,6 @@ try_failed = ["+foo", "+bar", "-baz"]
903
890
"# ,
904
891
) )
905
892
. run_test ( async |tester| {
906
- tester. create_branch ( TRY_BRANCH_NAME ) . expect_suites ( 1 ) ;
907
893
tester. post_comment ( "@bors try" ) . await ?;
908
894
insta:: assert_snapshot!( tester. get_comment( ) . await ?, @r"
909
895
:hourglass: Trying commit pr-1-sha with merge merge-main-sha1-pr-1-sha-0…
@@ -914,7 +900,7 @@ try_failed = ["+foo", "+bar", "-baz"]
914
900
repo. lock ( )
915
901
. get_pr ( default_pr_number ( ) )
916
902
. check_added_labels ( & [ ] ) ;
917
- tester. workflow_failure ( tester. try_branch ( ) ) . await ?;
903
+ tester. workflow_full_failure ( tester. try_branch ( ) ) . await ?;
918
904
tester. expect_comments ( 1 ) . await ;
919
905
let pr = repo. lock ( ) . get_pr ( default_pr_number ( ) ) . clone ( ) ;
920
906
pr. check_added_labels ( & [ "foo" , "bar" ] ) ;
@@ -927,7 +913,6 @@ try_failed = ["+foo", "+bar", "-baz"]
927
913
#[ sqlx:: test]
928
914
async fn try_build_creates_check_run ( pool : sqlx:: PgPool ) {
929
915
run_test ( pool, async |tester| {
930
- tester. create_branch ( TRY_BRANCH_NAME ) . expect_suites ( 1 ) ;
931
916
tester. post_comment ( "@bors try" ) . await ?;
932
917
tester. expect_comments ( 1 ) . await ;
933
918
@@ -947,11 +932,10 @@ try_failed = ["+foo", "+bar", "-baz"]
947
932
#[ sqlx:: test]
948
933
async fn try_build_updates_check_run_on_success ( pool : sqlx:: PgPool ) {
949
934
run_test ( pool, async |tester| {
950
- tester. create_branch ( TRY_BRANCH_NAME ) . expect_suites ( 1 ) ;
951
935
tester. post_comment ( "@bors try" ) . await ?;
952
936
tester. expect_comments ( 1 ) . await ;
953
937
954
- tester. workflow_success ( tester. try_branch ( ) ) . await ?;
938
+ tester. workflow_full_success ( tester. try_branch ( ) ) . await ?;
955
939
tester. expect_comments ( 1 ) . await ;
956
940
957
941
tester. expect_check_run (
@@ -970,11 +954,10 @@ try_failed = ["+foo", "+bar", "-baz"]
970
954
#[ sqlx:: test]
971
955
async fn try_build_updates_check_run_on_failure ( pool : sqlx:: PgPool ) {
972
956
run_test ( pool, async |tester| {
973
- tester. create_branch ( TRY_BRANCH_NAME ) . expect_suites ( 1 ) ;
974
957
tester. post_comment ( "@bors try" ) . await ?;
975
958
tester. expect_comments ( 1 ) . await ;
976
959
977
- tester. workflow_failure ( tester. try_branch ( ) ) . await ?;
960
+ tester. workflow_full_failure ( tester. try_branch ( ) ) . await ?;
978
961
tester. expect_comments ( 1 ) . await ;
979
962
980
963
tester. expect_check_run (
@@ -993,7 +976,6 @@ try_failed = ["+foo", "+bar", "-baz"]
993
976
#[ sqlx:: test]
994
977
async fn try_cancel_updates_check_run_to_cancelled ( pool : sqlx:: PgPool ) {
995
978
run_test ( pool, async |tester| {
996
- tester. create_branch ( TRY_BRANCH_NAME ) . expect_suites ( 1 ) ;
997
979
tester. post_comment ( "@bors try" ) . await ?;
998
980
tester. expect_comments ( 1 ) . await ;
999
981
@@ -1016,7 +998,6 @@ try_failed = ["+foo", "+bar", "-baz"]
1016
998
#[ sqlx:: test]
1017
999
async fn new_try_build_cancels_previous_and_updates_check_run ( pool : sqlx:: PgPool ) {
1018
1000
run_test ( pool, async |tester| {
1019
- tester. create_branch ( TRY_BRANCH_NAME ) . expect_suites ( 1 ) ;
1020
1001
tester. post_comment ( "@bors try" ) . await ?;
1021
1002
tester. expect_comments ( 1 ) . await ;
1022
1003
0 commit comments