@@ -725,117 +725,103 @@ async function upload_new_files() {
725
725
console . timeEnd ( 'dataset upload' ) ;
726
726
}
727
727
728
- function run_test ( throw_on_fail ) {
729
- return P . resolve ( )
730
- . then ( ( ) => log_journal_file ( `${ CFG_MARKER } ${ DATASET_NAME } -${ JSON . stringify ( TEST_CFG ) } ` ) )
731
- . then ( ( ) => upload_new_files ( )
732
- // aging
733
- . then ( ( ) => {
734
- if ( argv . no_aging ) {
735
- console . log ( 'skipping aging stage' ) ;
736
- return ;
737
- }
738
- TEST_STATE . aging = true ;
739
- const start = Date . now ( ) ;
740
- if ( TEST_CFG . aging_timeout !== 0 ) {
741
- console . log ( `will run aging for ${ TEST_CFG . aging_timeout } minutes` ) ;
742
- }
743
- return P . pwhile ( ( ) =>
744
- ( TEST_CFG . aging_timeout === 0 || ( ( Date . now ( ) - start ) / ( 60 * 1000 ) ) < TEST_CFG . aging_timeout ) , ( ) => {
745
- console . log ( `Aging... currently uploaded ${ TEST_STATE . current_size } ${ TEST_CFG . size_units } from desired ${
746
- TEST_CFG . dataset_size } ${ TEST_CFG . size_units } `) ;
747
- let action_type ;
748
- if ( TEST_STATE . current_size > TEST_CFG . dataset_size ) {
749
- console . log ( `${ Yellow } the current dataset size is ${
750
- TEST_STATE . current_size } ${ TEST_CFG . size_units } and the requested dataset size is ${
751
- TEST_CFG . dataset_size } ${ TEST_CFG . size_units } , going to delete${ NC } `) ;
752
- action_type = Math . round ( Math . random ( ) ) ? 'DELETE' : 'MULTI_DELETE' ;
753
- } else {
754
- action_type = 'RANDOM' ;
755
- }
756
- return P . resolve ( )
757
- . then ( ( ) => act_and_log ( action_type ) ) ;
758
- } ) ;
759
- } )
760
- . then ( async ( ) => {
761
- await report . report ( ) ;
762
- } )
763
- . then ( ( ) => {
764
- console . log ( `Everything finished with success!` ) ;
765
- if ( ! TEST_CFG . no_exit_on_success ) process . exit ( 0 ) ;
766
- } )
767
- . catch ( async err => {
768
- await report . report ( ) ;
769
- console . error ( `Errors during test` , err ) ;
770
- if ( throw_on_fail ) {
771
- throw new Error ( `dataset failed` ) ;
728
+ async function run_test ( throw_on_fail ) {
729
+ try {
730
+ await log_journal_file ( `${ CFG_MARKER } ${ DATASET_NAME } -${ JSON . stringify ( TEST_CFG ) } ` ) ;
731
+ await upload_new_files ( ) ;
732
+
733
+ // aging
734
+ if ( argv . no_aging ) {
735
+ console . log ( 'skipping aging stage' ) ;
736
+ return ;
737
+ } else {
738
+ TEST_STATE . aging = true ;
739
+ const start = Date . now ( ) ;
740
+ if ( TEST_CFG . aging_timeout !== 0 ) {
741
+ console . log ( `will run aging for ${ TEST_CFG . aging_timeout } minutes` ) ;
742
+ }
743
+ while ( ( TEST_CFG . aging_timeout === 0 || ( ( Date . now ( ) - start ) / ( 60 * 1000 ) ) < TEST_CFG . aging_timeout ) ) {
744
+ console . log ( `Aging... currently uploaded ${ TEST_STATE . current_size } ${ TEST_CFG . size_units } from desired ${
745
+ TEST_CFG . dataset_size } ${ TEST_CFG . size_units } `) ;
746
+ let action_type ;
747
+ if ( TEST_STATE . current_size > TEST_CFG . dataset_size ) {
748
+ console . log ( `${ Yellow } the current dataset size is ${
749
+ TEST_STATE . current_size } ${ TEST_CFG . size_units } and the requested dataset size is ${
750
+ TEST_CFG . dataset_size } ${ TEST_CFG . size_units } , going to delete${ NC } `) ;
751
+ action_type = Math . round ( Math . random ( ) ) ? 'DELETE' : 'MULTI_DELETE' ;
772
752
} else {
773
- process . exit ( 4 ) ;
753
+ action_type = 'RANDOM' ;
774
754
}
775
- } ) ) ;
755
+ await act_and_log ( action_type ) ;
756
+ }
757
+ }
758
+ await report . report ( ) ;
759
+
760
+ console . log ( `Everything finished with success!` ) ;
761
+ if ( ! TEST_CFG . no_exit_on_success ) process . exit ( 0 ) ;
762
+
763
+ } catch ( err ) {
764
+ await report . report ( ) ;
765
+ console . error ( `Errors during test` , err ) ;
766
+ if ( throw_on_fail ) {
767
+ throw new Error ( `dataset failed` ) ;
768
+ } else {
769
+ process . exit ( 4 ) ;
770
+ }
771
+ }
776
772
}
777
773
778
- function run_replay ( ) {
779
- const journal = [ ] ;
780
- const readfile = readline . createInterface ( {
781
- input : fs . createReadStream ( argv . replay ) ,
782
- terminal : false
783
- } ) ;
784
- return new Promise ( ( resolve , reject ) => {
785
- readfile
786
- . on ( 'line' , line => journal . push ( line ) )
787
- . once ( 'error' , reject )
788
- . once ( 'close' , resolve ) ;
789
- } )
790
- . then ( ( ) => {
791
- //first line should contain the TEST_CFG
792
- console . log ( `journal[0] ${ journal [ 0 ] } ` ) ;
793
- if ( ! journal [ 0 ] . startsWith ( `${ CFG_MARKER } ` ) ) {
794
- console . error ( 'Expected CFG as first line of replay' ) ;
795
- process . exit ( 5 ) ;
796
- }
797
- TEST_CFG = JSON . parse ( journal [ 0 ] . slice ( CFG_MARKER . length + DATASET_NAME . length + 1 ) ) ;
798
- let iline = 1 ;
799
- let idx ;
800
- let current_action ;
801
- let current_params ;
802
- return P . pwhile (
803
- ( ) => iline < journal . length ,
804
- ( ) => P . resolve ( )
805
- . then ( ( ) => {
806
- //split action from params
807
- current_params = JSON . parse ( journal [ iline ] . slice ( ACTION_MARKER . length ) ) ;
808
- current_action = current_params . action ;
809
- delete current_params . action ;
810
- console . log ( `Calling ${ current_action } with parameters ${ util . inspect ( current_params ) } ` ) ;
811
- //run single selected activity
812
- idx = _ . findIndex ( ACTION_TYPES , ac => ac . name === current_action ) ;
813
- if ( idx === - 1 ) {
814
- console . error ( `Cannot find action ${ current_action } ` ) ;
815
- process . exit ( 1 ) ;
816
- } else {
817
- return ACTION_TYPES [ idx ] . action ( current_params ) ;
818
- }
819
-
820
- } )
821
- . then ( ( ) => report . success ( current_action ) )
822
- . catch ( err => report . fail ( current_action )
823
- . then ( ( ) => {
824
- console . error ( `Failed replaying action ${ current_action } with ${ err } ` ) ;
825
- throw err ;
826
- } )
827
- )
828
- . finally ( ( ) => {
829
- iline += 1 ;
830
- } )
831
- ) ;
832
- } )
833
- . then ( async ( ) => report . report ( ) )
834
- . catch ( async err => {
835
- await report . report ( ) ;
836
- console . error ( 'Failed replaying journal file ' , err ) ;
837
- process . exit ( 5 ) ;
774
+ async function run_replay ( ) {
775
+ try {
776
+ const journal = [ ] ;
777
+ const readfile = readline . createInterface ( {
778
+ input : fs . createReadStream ( argv . replay ) ,
779
+ terminal : false
838
780
} ) ;
781
+
782
+ for await ( const line of readfile ) {
783
+ journal . push ( line ) ;
784
+ }
785
+
786
+ //first line should contain the TEST_CFG
787
+ console . log ( `journal[0] ${ journal [ 0 ] } ` ) ;
788
+ if ( ! journal [ 0 ] . startsWith ( `${ CFG_MARKER } ` ) ) {
789
+ console . error ( 'Expected CFG as first line of replay' ) ;
790
+ process . exit ( 5 ) ;
791
+ }
792
+
793
+ TEST_CFG = JSON . parse ( journal [ 0 ] . slice ( CFG_MARKER . length + DATASET_NAME . length + 1 ) ) ;
794
+
795
+ for ( let iline = 1 ; iline < journal . length ; iline ++ ) {
796
+ let current_action ;
797
+ try {
798
+ //split action from params
799
+ const current_params = JSON . parse ( journal [ iline ] . slice ( ACTION_MARKER . length ) ) ;
800
+ current_action = current_params . action ;
801
+ delete current_params . action ;
802
+ console . log ( `Calling ${ current_action } with parameters ${ util . inspect ( current_params ) } ` ) ;
803
+ //run single selected activity
804
+ const idx = _ . findIndex ( ACTION_TYPES , ac => ac . name === current_action ) ;
805
+ if ( idx === - 1 ) {
806
+ console . error ( `Cannot find action ${ current_action } ` ) ;
807
+ process . exit ( 1 ) ;
808
+ }
809
+
810
+ await ACTION_TYPES [ idx ] . action ( current_params ) ;
811
+ report . success ( current_action ) ;
812
+ } catch ( err ) {
813
+ console . error ( `Failed action ${ journal [ iline ] } with error ${ err } ` ) ;
814
+ report . fail ( current_action ) ;
815
+ throw err ;
816
+ }
817
+ }
818
+
819
+ await report . report ( ) ;
820
+ } catch ( err ) {
821
+ await report . report ( ) ;
822
+ console . error ( 'Failed replaying journal file ' , err ) ;
823
+ process . exit ( 5 ) ;
824
+ }
839
825
}
840
826
841
827
async function main ( ) {
0 commit comments