@@ -26,6 +26,19 @@ describe('preload', () => {
26
26
after ( ( ) => cleanup ( ) )
27
27
afterEach ( ( ) => MockPreloadNode . clearPreloadCids ( ) )
28
28
29
+ it ( 'should not preload content multiple times' , async function ( ) {
30
+ this . timeout ( 50 * 1000 )
31
+ const { cid } = await ipfs . add ( uint8ArrayFromString ( nanoid ( ) ) , { preload : false } )
32
+
33
+ await all ( ipfs . cat ( cid ) )
34
+ await MockPreloadNode . waitForCids ( cid )
35
+
36
+ // should not preload the second time
37
+ await MockPreloadNode . clearPreloadCids ( )
38
+ await all ( ipfs . cat ( cid ) )
39
+ await expect ( MockPreloadNode . waitForCids ( cid ) ) . to . eventually . be . rejectedWith ( 'Timed out waiting for CIDs to be preloaded' )
40
+ } )
41
+
29
42
it ( 'should preload content added with add' , async function ( ) {
30
43
this . timeout ( 50 * 1000 )
31
44
const res = await ipfs . add ( uint8ArrayFromString ( nanoid ( ) ) )
@@ -112,7 +125,7 @@ describe('preload', () => {
112
125
} , {
113
126
path : 'dir0/file2' ,
114
127
content : uint8ArrayFromString ( nanoid ( ) )
115
- } ] , { wrapWithDirectory : true } ) )
128
+ } ] , { wrapWithDirectory : true , preload : false } ) )
116
129
117
130
const wrappingDir = res . find ( file => file . path === '' )
118
131
expect ( wrappingDir ) . to . exist ( )
@@ -147,12 +160,12 @@ describe('preload', () => {
147
160
148
161
const [ parent , link ] = await Promise . all ( [ createNode ( ) , createNode ( ) ] )
149
162
163
+ await MockPreloadNode . clearPreloadCids ( )
150
164
const cid = await ipfs . object . patch . addLink ( parent . cid , {
151
165
Name : 'link' ,
152
166
Hash : link . cid ,
153
167
Tsize : link . node . size
154
168
} )
155
-
156
169
await MockPreloadNode . waitForCids ( cid )
157
170
} )
158
171
@@ -171,27 +184,31 @@ describe('preload', () => {
171
184
} ]
172
185
} )
173
186
187
+ await MockPreloadNode . clearPreloadCids ( )
174
188
const cid = await ipfs . object . patch . rmLink ( parentCid , { name : 'link' } )
175
189
await MockPreloadNode . waitForCids ( cid )
176
190
} )
177
191
178
192
it ( 'should preload content added with object.patch.setData' , async function ( ) {
179
193
this . timeout ( 50 * 1000 )
180
194
const originalCid = await ipfs . object . put ( { Data : uint8ArrayFromString ( nanoid ( ) ) , Links : [ ] } )
195
+ await MockPreloadNode . clearPreloadCids ( )
181
196
const patchedCid = await ipfs . object . patch . setData ( originalCid , uint8ArrayFromString ( nanoid ( ) ) )
182
197
await MockPreloadNode . waitForCids ( patchedCid )
183
198
} )
184
199
185
200
it ( 'should preload content added with object.patch.appendData' , async function ( ) {
186
201
this . timeout ( 50 * 1000 )
187
202
const originalCid = await ipfs . object . put ( { Data : uint8ArrayFromString ( nanoid ( ) ) , Links : [ ] } )
203
+ await MockPreloadNode . clearPreloadCids ( )
188
204
const patchedCid = await ipfs . object . patch . appendData ( originalCid , uint8ArrayFromString ( nanoid ( ) ) )
189
205
await MockPreloadNode . waitForCids ( patchedCid )
190
206
} )
191
207
192
208
it ( 'should preload content retrieved with object.get' , async function ( ) {
193
209
this . timeout ( 50 * 1000 )
194
- const cid = await ipfs . object . new ( { preload : false } )
210
+ const cid = await ipfs . object . put ( { Data : uint8ArrayFromString ( nanoid ( ) ) , Links : [ ] } , { preload : false } )
211
+ await MockPreloadNode . clearPreloadCids ( )
195
212
await ipfs . object . get ( cid )
196
213
await MockPreloadNode . waitForCids ( cid )
197
214
} )
@@ -205,13 +222,15 @@ describe('preload', () => {
205
222
it ( 'should preload content retrieved with block.get' , async function ( ) {
206
223
this . timeout ( 50 * 1000 )
207
224
const block = await ipfs . block . put ( uint8ArrayFromString ( nanoid ( ) ) , { preload : false } )
225
+ await MockPreloadNode . clearPreloadCids ( )
208
226
await ipfs . block . get ( block . cid )
209
227
await MockPreloadNode . waitForCids ( block . cid )
210
228
} )
211
229
212
230
it ( 'should preload content retrieved with block.stat' , async function ( ) {
213
231
this . timeout ( 50 * 1000 )
214
232
const block = await ipfs . block . put ( uint8ArrayFromString ( nanoid ( ) ) , { preload : false } )
233
+ await MockPreloadNode . clearPreloadCids ( )
215
234
await ipfs . block . stat ( block . cid )
216
235
await MockPreloadNode . waitForCids ( block . cid )
217
236
} )
@@ -228,39 +247,35 @@ describe('preload', () => {
228
247
const obj = { test : nanoid ( ) }
229
248
const opts = { format : 'dag-cbor' , hashAlg : 'sha2-256' , preload : false }
230
249
const cid = await ipfs . dag . put ( obj , opts )
250
+ await MockPreloadNode . clearPreloadCids ( )
231
251
await ipfs . dag . get ( cid )
232
252
await MockPreloadNode . waitForCids ( cid )
233
253
} )
234
254
235
255
it ( 'should preload content retrieved with files.ls' , async ( ) => {
236
- const res = await ipfs . add ( { path : `/t/${ nanoid ( ) } ` , content : uint8ArrayFromString ( nanoid ( ) ) } )
256
+ const res = await ipfs . add ( { path : `/t/${ nanoid ( ) } ` , content : uint8ArrayFromString ( nanoid ( ) ) } , { preload : false } )
237
257
const dirCid = res . cid
238
- await MockPreloadNode . waitForCids ( dirCid )
239
258
await MockPreloadNode . clearPreloadCids ( )
240
259
await all ( ipfs . files . ls ( `/ipfs/${ dirCid } ` ) )
241
260
await MockPreloadNode . waitForCids ( `/ipfs/${ dirCid } ` )
242
261
} )
243
262
244
263
it ( 'should preload content retrieved with files.ls by CID' , async ( ) => {
245
- const res = await ipfs . add ( { path : `/t/${ nanoid ( ) } ` , content : uint8ArrayFromString ( nanoid ( ) ) } )
264
+ const res = await ipfs . add ( { path : `/t/${ nanoid ( ) } ` , content : uint8ArrayFromString ( nanoid ( ) ) } , { preload : false } )
246
265
const dirCid = res . cid
247
- await MockPreloadNode . waitForCids ( dirCid )
248
- await MockPreloadNode . clearPreloadCids ( )
249
266
await all ( ipfs . files . ls ( dirCid ) )
250
267
await MockPreloadNode . waitForCids ( dirCid )
251
268
} )
252
269
253
270
it ( 'should preload content retrieved with files.read' , async ( ) => {
254
- const { cid } = await ipfs . add ( uint8ArrayFromString ( nanoid ( ) ) )
255
- await MockPreloadNode . waitForCids ( cid )
271
+ const { cid } = await ipfs . add ( uint8ArrayFromString ( nanoid ( ) ) , { preload : false } )
256
272
await MockPreloadNode . clearPreloadCids ( )
257
273
await ipfs . files . read ( `/ipfs/${ cid } ` )
258
274
await MockPreloadNode . waitForCids ( `/ipfs/${ cid } ` )
259
275
} )
260
276
261
277
it ( 'should preload content retrieved with files.stat' , async ( ) => {
262
- const { cid : fileCid } = await ipfs . add ( uint8ArrayFromString ( nanoid ( ) ) )
263
- await MockPreloadNode . waitForCids ( fileCid )
278
+ const { cid : fileCid } = await ipfs . add ( uint8ArrayFromString ( nanoid ( ) ) , { preload : false } )
264
279
await MockPreloadNode . clearPreloadCids ( )
265
280
await ipfs . files . stat ( `/ipfs/${ fileCid } ` )
266
281
await MockPreloadNode . waitForCids ( `/ipfs/${ fileCid } ` )
0 commit comments