@@ -742,6 +742,7 @@ impl<'a, I: engine::ScanIterator> Iterator for VersionIterator<'a, I> {
742
742
}
743
743
}
744
744
745
+ /// Most storage tests are Goldenscripts under src/storage/testscripts.
745
746
#[ cfg( test) ]
746
747
pub mod tests {
747
748
use super :: * ;
@@ -826,6 +827,8 @@ pub mod tests {
826
827
impl goldenscript:: Runner for MVCCRunner {
827
828
fn run ( & mut self , command : & goldenscript:: Command ) -> Result < String , Box < dyn Error > > {
828
829
let mut output = String :: new ( ) ;
830
+ let mut tags = command. tags . clone ( ) ;
831
+
829
832
match command. name . as_str ( ) {
830
833
// txn: begin [readonly] [as_of=VERSION]
831
834
"begin" => {
@@ -961,7 +964,7 @@ pub mod tests {
961
964
parse_key_range ( args. next_pos ( ) . map ( |a| a. value . as_str ( ) ) . unwrap_or ( ".." ) ) ?;
962
965
args. reject_rest ( ) ?;
963
966
964
- let kvs: Vec < _ > = txn. scan ( range) . collect :: < crate :: error :: Result < _ > > ( ) ?;
967
+ let kvs: Vec < _ > = txn. scan ( range) . try_collect ( ) ?;
965
968
for ( key, value) in kvs {
966
969
writeln ! ( output, "{}" , format:: Raw :: key_value( & key, & value) ) ?;
967
970
}
@@ -974,8 +977,7 @@ pub mod tests {
974
977
let prefix = decode_binary ( & args. next_pos ( ) . ok_or ( "prefix not given" ) ?. value ) ;
975
978
args. reject_rest ( ) ?;
976
979
977
- let kvs: Vec < _ > =
978
- txn. scan_prefix ( & prefix) . collect :: < crate :: error:: Result < _ > > ( ) ?;
980
+ let kvs: Vec < _ > = txn. scan_prefix ( & prefix) . try_collect ( ) ?;
979
981
for ( key, value) in kvs {
980
982
writeln ! ( output, "{}" , format:: Raw :: key_value( & key, & value) ) ?;
981
983
}
@@ -1020,49 +1022,41 @@ pub mod tests {
1020
1022
}
1021
1023
1022
1024
// status
1023
- "status" => {
1024
- let status = self . mvcc . status ( ) ?;
1025
- writeln ! ( output, "{status:#?}" ) ?;
1026
- }
1025
+ "status" => writeln ! ( output, "{:#?}" , self . mvcc. status( ) ?) ?,
1027
1026
1028
1027
name => return Err ( format ! ( "invalid command {name}" ) . into ( ) ) ,
1029
1028
}
1030
- Ok ( output)
1031
- }
1032
1029
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
+ }
1044
1046
}
1045
1047
}
1046
1048
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 ( ) ) ;
1064
1051
}
1052
+
1065
1053
Ok ( output)
1066
1054
}
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
+ }
1067
1061
}
1068
1062
}
0 commit comments