@@ -104,6 +104,42 @@ describe('S3DataStore', function () {
104104 }
105105 } )
106106
107+ it ( 'upload as multipart upload when incomplete part grows beyond minimal part size' , async function ( ) {
108+ const store = this . datastore
109+ const size = 10 * 1024 * 1024 // 10MB
110+ const incompleteSize = 2 * 1024 * 1024 // 2MB
111+ const getIncompletePart = sinon . spy ( store , 'getIncompletePart' )
112+ const uploadIncompletePart = sinon . spy ( store , 'uploadIncompletePart' )
113+ const uploadPart = sinon . spy ( store , 'uploadPart' )
114+ const upload = new Upload ( {
115+ id : 'incomplete-part-test-' + Uid . rand ( ) ,
116+ size : size + incompleteSize ,
117+ offset : 0 ,
118+ } )
119+
120+ let offset = upload . offset
121+
122+ await store . create ( upload )
123+ offset = await store . write (
124+ Readable . from ( Buffer . alloc ( incompleteSize ) ) ,
125+ upload . id ,
126+ offset
127+ )
128+ offset = await store . write (
129+ Readable . from ( Buffer . alloc ( incompleteSize ) ) ,
130+ upload . id ,
131+ offset
132+ )
133+
134+ assert . equal ( getIncompletePart . called , true )
135+ assert . equal ( uploadIncompletePart . called , true )
136+ assert . equal ( uploadPart . called , false )
137+
138+ await store . write ( Readable . from ( Buffer . alloc ( incompleteSize ) ) , upload . id , offset )
139+
140+ assert . equal ( uploadPart . called , true )
141+ } )
142+
107143 it ( 'should process chunk size of exactly the min size' , async function ( ) {
108144 this . datastore . minPartSize = 1024 * 1024 * 5
109145 const store = this . datastore
0 commit comments