@@ -742,6 +742,7 @@ impl<'a, I: engine::ScanIterator> Iterator for VersionIterator<'a, I> {
742742 }
743743}
744744
745+ /// Most storage tests are Goldenscripts under src/storage/testscripts.
745746#[ cfg( test) ]
746747pub mod tests {
747748 use super :: * ;
@@ -826,6 +827,8 @@ pub mod tests {
826827 impl goldenscript:: Runner for MVCCRunner {
827828 fn run ( & mut self , command : & goldenscript:: Command ) -> Result < String , Box < dyn Error > > {
828829 let mut output = String :: new ( ) ;
830+ let mut tags = command. tags . clone ( ) ;
831+
829832 match command. name . as_str ( ) {
830833 // txn: begin [readonly] [as_of=VERSION]
831834 "begin" => {
@@ -961,7 +964,7 @@ pub mod tests {
961964 parse_key_range ( args. next_pos ( ) . map ( |a| a. value . as_str ( ) ) . unwrap_or ( ".." ) ) ?;
962965 args. reject_rest ( ) ?;
963966
964- let kvs: Vec < _ > = txn. scan ( range) . collect :: < crate :: error :: Result < _ > > ( ) ?;
967+ let kvs: Vec < _ > = txn. scan ( range) . try_collect ( ) ?;
965968 for ( key, value) in kvs {
966969 writeln ! ( output, "{}" , format:: Raw :: key_value( & key, & value) ) ?;
967970 }
@@ -974,8 +977,7 @@ pub mod tests {
974977 let prefix = decode_binary ( & args. next_pos ( ) . ok_or ( "prefix not given" ) ?. value ) ;
975978 args. reject_rest ( ) ?;
976979
977- let kvs: Vec < _ > =
978- txn. scan_prefix ( & prefix) . collect :: < crate :: error:: Result < _ > > ( ) ?;
980+ let kvs: Vec < _ > = txn. scan_prefix ( & prefix) . try_collect ( ) ?;
979981 for ( key, value) in kvs {
980982 writeln ! ( output, "{}" , format:: Raw :: key_value( & key, & value) ) ?;
981983 }
@@ -1020,49 +1022,41 @@ pub mod tests {
10201022 }
10211023
10221024 // status
1023- "status" => {
1024- let status = self . mvcc . status ( ) ?;
1025- writeln ! ( output, "{status:#?}" ) ?;
1026- }
1025+ "status" => writeln ! ( output, "{:#?}" , self . mvcc. status( ) ?) ?,
10271026
10281027 name => return Err ( format ! ( "invalid command {name}" ) . into ( ) ) ,
10291028 }
1030- Ok ( output)
1031- }
10321029
1033- /// If requested via [ops] tag, output engine operations for the command.
1034- fn end_command (
1035- & mut self ,
1036- command : & goldenscript:: Command ,
1037- ) -> Result < String , Box < dyn Error > > {
1038- // Parse tags.
1039- let mut show_ops = false ;
1040- for tag in & command. tags {
1041- match tag. as_str ( ) {
1042- "ops" => show_ops = true ,
1043- tag => return Err ( format ! ( "invalid tag {tag}" ) . into ( ) ) ,
1030+ // If requested, output engine operations.
1031+ if tags. remove ( "ops" ) {
1032+ while let Ok ( op) = self . op_rx . try_recv ( ) {
1033+ match op {
1034+ Operation :: Delete { key } => {
1035+ let fmtkey = format:: MVCC :: < format:: Raw > :: key ( & key) ;
1036+ let rawkey = format:: Raw :: key ( & key) ;
1037+ writeln ! ( output, "engine delete {fmtkey} [{rawkey}]" ) ?
1038+ }
1039+ Operation :: Flush => writeln ! ( output, "engine flush" ) ?,
1040+ Operation :: Set { key, value } => {
1041+ let fmtkv = format:: MVCC :: < format:: Raw > :: key_value ( & key, & value) ;
1042+ let rawkv = format:: Raw :: key_value ( & key, & value) ;
1043+ writeln ! ( output, "engine set {fmtkv} [{rawkv}]" ) ?
1044+ }
1045+ }
10441046 }
10451047 }
10461048
1047- // Process engine operations, either output or drain.
1048- let mut output = String :: new ( ) ;
1049- while let Ok ( op) = self . op_rx . try_recv ( ) {
1050- match op {
1051- _ if !show_ops => { }
1052- Operation :: Delete { key } => {
1053- let fmtkey = format:: MVCC :: < format:: Raw > :: key ( & key) ;
1054- let rawkey = format:: Raw :: key ( & key) ;
1055- writeln ! ( output, "engine delete {fmtkey} [{rawkey}]" ) ?
1056- }
1057- Operation :: Flush => writeln ! ( output, "engine flush" ) ?,
1058- Operation :: Set { key, value } => {
1059- let fmtkv = format:: MVCC :: < format:: Raw > :: key_value ( & key, & value) ;
1060- let rawkv = format:: Raw :: key_value ( & key, & value) ;
1061- writeln ! ( output, "engine set {fmtkv} [{rawkv}]" ) ?
1062- }
1063- }
1049+ if let Some ( tag) = tags. iter ( ) . next ( ) {
1050+ return Err ( format ! ( "unknown tag {tag}" ) . into ( ) ) ;
10641051 }
1052+
10651053 Ok ( output)
10661054 }
1055+
1056+ // Drain unhandled engine operations.
1057+ fn end_command ( & mut self , _: & goldenscript:: Command ) -> Result < String , Box < dyn Error > > {
1058+ while self . op_rx . try_recv ( ) . is_ok ( ) { }
1059+ Ok ( String :: new ( ) )
1060+ }
10671061 }
10681062}
0 commit comments