@@ -14,6 +14,8 @@ use std::fs;
14
14
use std:: io:: Read ;
15
15
use std:: path:: { Path , PathBuf } ;
16
16
17
+ const MAX_CONCURRENT_UPLOADS : usize = 1000 ;
18
+
17
19
#[ derive( Clone , Debug , PartialEq , Eq , Hash ) ]
18
20
pub ( crate ) struct Blob {
19
21
pub ( crate ) path : String ,
@@ -96,8 +98,6 @@ impl<'a> Storage<'a> {
96
98
prefix : & str ,
97
99
root_dir : & Path ,
98
100
) -> Result < HashMap < PathBuf , String > , Error > {
99
- const MAX_CONCURRENT_UPLOADS : usize = 1000 ;
100
-
101
101
let trans = conn. transaction ( ) ?;
102
102
let mut file_paths_and_mimes = HashMap :: new ( ) ;
103
103
@@ -191,6 +191,40 @@ mod test {
191
191
use crate :: test:: wrapper;
192
192
use std:: env;
193
193
194
+ pub ( crate ) fn assert_blob_eq ( blob : & Blob , actual : & Blob ) {
195
+ assert_eq ! ( blob. path, actual. path) ;
196
+ assert_eq ! ( blob. content, actual. content) ;
197
+ assert_eq ! ( blob. mime, actual. mime) ;
198
+ // NOTE: this does _not_ compare the upload time since min.io doesn't allow this to be configured
199
+ }
200
+
201
+ pub ( crate ) fn test_roundtrip ( blobs : & [ Blob ] ) {
202
+ let dir = tempdir:: TempDir :: new ( "docs.rs-upload-test" ) . unwrap ( ) ;
203
+ for blob in blobs {
204
+ let path = dir. path ( ) . join ( & blob. path ) ;
205
+ if let Some ( parent) = path. parent ( ) {
206
+ fs:: create_dir_all ( parent) . unwrap ( ) ;
207
+ }
208
+ fs:: write ( path, & blob. content ) . expect ( "failed to write to file" ) ;
209
+ }
210
+ wrapper ( |env| {
211
+ let db = env. db ( ) ;
212
+ let conn = db. conn ( ) ;
213
+ let mut backend = Storage :: Database ( DatabaseBackend :: new ( & conn) ) ;
214
+ let stored_files = backend. store_all ( & conn, "" , dir. path ( ) ) . unwrap ( ) ;
215
+ assert_eq ! ( stored_files. len( ) , blobs. len( ) ) ;
216
+ for blob in blobs {
217
+ let name = Path :: new ( & blob. path ) ;
218
+ assert ! ( stored_files. contains_key( name) ) ;
219
+
220
+ let actual = backend. get ( & blob. path ) . unwrap ( ) ;
221
+ assert_blob_eq ( blob, & actual) ;
222
+ }
223
+
224
+ Ok ( ( ) )
225
+ } ) ;
226
+ }
227
+
194
228
#[ test]
195
229
fn test_uploads ( ) {
196
230
use std:: fs;
@@ -235,6 +269,19 @@ mod test {
235
269
} )
236
270
}
237
271
272
+ #[ test]
273
+ fn test_batched_uploads ( ) {
274
+ let uploads: Vec < _ > = ( 0 ..=MAX_CONCURRENT_UPLOADS + 1 )
275
+ . map ( |i| Blob {
276
+ mime : "text/rust" . into ( ) ,
277
+ content : "fn main() {}" . into ( ) ,
278
+ path : format ! ( "{}.rs" , i) ,
279
+ date_updated : Timespec :: new ( 42 , 0 ) ,
280
+ } )
281
+ . collect ( ) ;
282
+ test_roundtrip ( & uploads) ;
283
+ }
284
+
238
285
#[ test]
239
286
fn test_get_file_list ( ) {
240
287
let _ = env_logger:: try_init ( ) ;
0 commit comments