@@ -1006,6 +1006,93 @@ func TestBatch(t *testing.T) {
1006
1006
})
1007
1007
}
1008
1008
1009
+ func TestSetOrderIndependent (t * testing.T ) {
1010
+ bs := cbor .NewCborStore (newMockBlocks ())
1011
+ ctx := context .Background ()
1012
+ a , err := NewAMT (bs )
1013
+ require .NoError (t , err )
1014
+
1015
+ nKeys := 8 * 8 * 8
1016
+
1017
+ for i := 0 ; i < nKeys ; i ++ {
1018
+ assertSet (t , a , uint64 (i ), "foo" )
1019
+ }
1020
+
1021
+ c , err := a .Flush (ctx )
1022
+ require .NoError (t , err )
1023
+
1024
+ vals := make ([]int , 100 )
1025
+
1026
+ for i := range vals {
1027
+ vals [i ] = rand .Intn (nKeys )
1028
+ }
1029
+
1030
+ res := map [cid.Cid ]struct {}{}
1031
+ for i := 0 ; i < 20 ; i ++ {
1032
+ a , err := LoadAMT (ctx , bs , c )
1033
+ require .NoError (t , err )
1034
+
1035
+ rand .Shuffle (len (vals ), func (i , j int ) {
1036
+ vals [i ], vals [j ] = vals [j ], vals [i ]
1037
+ })
1038
+
1039
+ for _ , k := range vals {
1040
+ assertSet (t , a , uint64 (k ), "foo2" )
1041
+ }
1042
+
1043
+ c , err := a .Flush (ctx )
1044
+ require .NoError (t , err )
1045
+ res [c ] = struct {}{}
1046
+ }
1047
+
1048
+ require .Len (t , res , 1 )
1049
+ }
1050
+
1051
+ func TestDeleteOrderIndependent (t * testing.T ) {
1052
+ bs := cbor .NewCborStore (newMockBlocks ())
1053
+ ctx := context .Background ()
1054
+ a , err := NewAMT (bs )
1055
+ require .NoError (t , err )
1056
+
1057
+ nKeys := 8 * 8 * 8 * 8
1058
+
1059
+ for i := 0 ; i < nKeys ; i ++ {
1060
+ assertSet (t , a , uint64 (i ), "foo" )
1061
+ }
1062
+
1063
+ c , err := a .Flush (ctx )
1064
+ require .NoError (t , err )
1065
+
1066
+ mvals := map [int ]struct {}{}
1067
+ for i := 0 ; i < 100 ; i ++ {
1068
+ mvals [rand .Intn (nKeys )] = struct {}{}
1069
+ }
1070
+ vals := make ([]int , 0 , len (mvals ))
1071
+ for v := range mvals {
1072
+ vals = append (vals , v )
1073
+ }
1074
+
1075
+ res := map [cid.Cid ]struct {}{}
1076
+ for i := 0 ; i < 20 ; i ++ {
1077
+ a , err := LoadAMT (ctx , bs , c )
1078
+ require .NoError (t , err )
1079
+
1080
+ rand .Shuffle (len (vals ), func (i , j int ) {
1081
+ vals [i ], vals [j ] = vals [j ], vals [i ]
1082
+ })
1083
+
1084
+ for _ , k := range vals {
1085
+ assertDelete (t , a , uint64 (k ))
1086
+ }
1087
+
1088
+ c , err := a .Flush (ctx )
1089
+ require .NoError (t , err )
1090
+ res [c ] = struct {}{}
1091
+ }
1092
+
1093
+ require .Len (t , res , 1 )
1094
+ }
1095
+
1009
1096
func assertEquals (ctx context.Context , t testing.TB , a * Root , expected []cbg.CBORMarshaler ) {
1010
1097
// Note: the AMT is not necessarily indexed from zero, so indexes may not align.
1011
1098
expIndex := 0
0 commit comments