@@ -1901,9 +1901,13 @@ pub mod tests {
19011901
19021902 assert_eq ! ( snapshots. len( ) , 2 , "Test fixture should have two snapshots" ) ;
19031903
1904- // First snapshot is the parent of the second
1905- let first_snapshot_id = snapshots[ 0 ] . snapshot_id ( ) ;
1906- let second_snapshot_id = snapshots[ 1 ] . snapshot_id ( ) ;
1904+ // Determine the correct order by snapshot IDs (since validation requires to_snapshot_id > from_snapshot_id)
1905+ // Sort snapshots by snapshot_id to ensure consistent ordering
1906+ let mut snapshot_ids: Vec < i64 > = snapshots. iter ( ) . map ( |s| s. snapshot_id ( ) ) . collect ( ) ;
1907+ snapshot_ids. sort ( ) ;
1908+
1909+ let first_snapshot_id = snapshot_ids[ 0 ] ;
1910+ let second_snapshot_id = snapshot_ids[ 1 ] ;
19071911
19081912 // Create an incremental scan from first to second snapshot
19091913 let table_scan = fixture
@@ -2047,67 +2051,67 @@ pub mod tests {
20472051
20482052 // We need to set up snapshots for the remaining tests
20492053 let snapshots = table. metadata ( ) . snapshots ( ) . collect :: < Vec < _ > > ( ) ;
2050- if snapshots. len ( ) >= 2 {
2051- let first_snapshot_id = snapshots[ 0 ] . snapshot_id ( ) ;
2052- let second_snapshot_id = snapshots[ 1 ] . snapshot_id ( ) ;
2053-
2054- // Test case 3: from_snapshot_id doesn't exist but to_snapshot_id does
2055- let result = table
2056- . scan ( )
2057- . from_snapshot_id ( 999998 ) // Non-existent
2058- . to_snapshot_id ( second_snapshot_id) // Existent
2059- . build ( ) ;
2054+ assert_eq ! ( snapshots. len( ) , 2 , "Test fixture should have two snapshots" ) ;
20602055
2061- assert ! (
2062- result. is_err( ) ,
2063- "Should fail when from_snapshot_id does not exist"
2064- ) ;
2065- assert_eq ! (
2066- result. unwrap_err( ) . to_string( ) ,
2067- "DataInvalid => from_snapshot_id 999998 not found" ,
2068- "Should have correct error message for non-existent from_snapshot_id"
2069- ) ;
2056+ // Sort snapshots by snapshot_id to ensure consistent ordering
2057+ let mut snapshot_ids: Vec < i64 > = snapshots. iter ( ) . map ( |s| s. snapshot_id ( ) ) . collect ( ) ;
2058+ snapshot_ids. sort ( ) ;
20702059
2071- // Determine which snapshot is newer based on snapshot IDs
2072- let ( older_snapshot_id, newer_snapshot_id) = if first_snapshot_id < second_snapshot_id {
2073- ( first_snapshot_id, second_snapshot_id)
2074- } else {
2075- ( second_snapshot_id, first_snapshot_id)
2076- } ;
2060+ let first_snapshot_id = snapshot_ids[ 0 ] ;
2061+ let second_snapshot_id = snapshot_ids[ 1 ] ;
20772062
2078- // Test case 4: Reversed snapshot order ( to_snapshot_id <= from_snapshot_id)
2079- let result = table
2080- . scan ( )
2081- . from_snapshot_id ( newer_snapshot_id ) // Later snapshot
2082- . to_snapshot_id ( older_snapshot_id ) // Earlier snapshot
2083- . build ( ) ;
2063+ // Test case 3: from_snapshot_id doesn't exist but to_snapshot_id does
2064+ let result = table
2065+ . scan ( )
2066+ . from_snapshot_id ( 999998 ) // Non-existent
2067+ . to_snapshot_id ( second_snapshot_id ) // Existent
2068+ . build ( ) ;
20842069
2085- assert ! (
2086- result. is_err( ) ,
2087- "Should fail when to_snapshot_id <= from_snapshot_id "
2088- ) ;
2089- assert_eq ! (
2090- result. unwrap_err( ) . to_string( ) ,
2091- "DataInvalid => to_snapshot_id must be greater than from_snapshot_id " ,
2092- "Should have correct error message for reversed snapshot order "
2093- ) ;
2070+ assert ! (
2071+ result. is_err( ) ,
2072+ "Should fail when from_snapshot_id does not exist "
2073+ ) ;
2074+ assert_eq ! (
2075+ result. unwrap_err( ) . to_string( ) ,
2076+ "DataInvalid => from_snapshot_id 999998 not found " ,
2077+ "Should have correct error message for non-existent from_snapshot_id "
2078+ ) ;
20942079
2095- // Test case 5: Equal snapshot IDs (empty range)
2096- let result = table
2097- . scan ( )
2098- . from_snapshot_id ( older_snapshot_id)
2099- . to_snapshot_id ( older_snapshot_id)
2100- . build ( ) ;
2080+ // Determine which snapshot is newer based on snapshot IDs
2081+ let ( older_snapshot_id, newer_snapshot_id) = ( first_snapshot_id, second_snapshot_id) ;
21012082
2102- assert ! (
2103- result. is_err( ) ,
2104- "Should fail when from_snapshot_id == to_snapshot_id"
2105- ) ;
2106- assert_eq ! (
2107- result. unwrap_err( ) . to_string( ) ,
2108- "DataInvalid => to_snapshot_id must be greater than from_snapshot_id" ,
2109- "Should have correct error message for equal snapshot IDs"
2110- ) ;
2111- }
2083+ // Test case 4: Reversed snapshot order (to_snapshot_id <= from_snapshot_id)
2084+ let result = table
2085+ . scan ( )
2086+ . from_snapshot_id ( newer_snapshot_id) // Later snapshot
2087+ . to_snapshot_id ( older_snapshot_id) // Earlier snapshot
2088+ . build ( ) ;
2089+
2090+ assert ! (
2091+ result. is_err( ) ,
2092+ "Should fail when to_snapshot_id <= from_snapshot_id"
2093+ ) ;
2094+ assert_eq ! (
2095+ result. unwrap_err( ) . to_string( ) ,
2096+ "DataInvalid => to_snapshot_id must be greater than from_snapshot_id" ,
2097+ "Should have correct error message for reversed snapshot order"
2098+ ) ;
2099+
2100+ // Test case 5: Equal snapshot IDs (empty range)
2101+ let result = table
2102+ . scan ( )
2103+ . from_snapshot_id ( older_snapshot_id)
2104+ . to_snapshot_id ( older_snapshot_id)
2105+ . build ( ) ;
2106+
2107+ assert ! (
2108+ result. is_err( ) ,
2109+ "Should fail when from_snapshot_id == to_snapshot_id"
2110+ ) ;
2111+ assert_eq ! (
2112+ result. unwrap_err( ) . to_string( ) ,
2113+ "DataInvalid => to_snapshot_id must be greater than from_snapshot_id" ,
2114+ "Should have correct error message for equal snapshot IDs"
2115+ ) ;
21122116 }
21132117}
0 commit comments