@samitouri / QOSami-HFS / commits / c3b670d6

test: "upload.too much" now more reliable

Massimo Melina committed Aug 26, 2025 at 11:16 UTC c3b670d617fd30494f4f7335f52943720d20e445
1 file changed +10 -2
tests/test.ts
+10 -2
@@ -240,7 +240,15 @@ describe('after-login', () => {
240 test('reupload', reqUpload(UPLOAD_DEST, 200))
241 test('delete.method', req(UPLOAD_DEST, 200, { method: 'DELETE' }))
242 test('delete.miss deleted', req(UPLOAD_DEST, 404, { method: 'delete' }))
243 - test('upload.too much', reqUpload(UPLOAD_ROOT + 'temp/tooMuch', 400, BIG_CONTENT, BIG_CONTENT.length / 2)) // 400 is caused by nodejs itself, intercepting the mismatch
243 + const declaredSize = BIG_CONTENT.length / 2
244 + test('upload.too much', reqUpload(UPLOAD_DEST, (x,res)=> {
245 + if (res.statusCode === 400) return // status 400 is caused by nodejs itself, intercepting the mismatch, but it's probably an unreliable race condition
246 + if (res.statusCode !== 200) // it happened sometimes that node didn't block (can't replicate). In such case we should get a 200 with a file the size of declaredSize.
247 + throw `expected 200, got ${res.statusCode}`
248 + const size = try_(() => statSync(resolve(__dirname, UPLOAD_RELATIVE)).size)
249 + if (size !== declaredSize)
250 + throw `expected ${declaredSize}, got ${size}`
251 + }, BIG_CONTENT, declaredSize))
252 test('upload.free space', async () => {
253 const res = statfsSync(ROOT)
254 const free = res.bavail * res.bsize
@@ -306,7 +314,7 @@ async function testMaxDl(uri: string, good: number, bad: number) {
314 }, { throttle })() )) // slow down to ensure the attempted downloads are all concurrent
315 }
316
309 -type TesterFunction = ((data: any, fullResponse: any) => boolean | void)
317 +type TesterFunction = ((data: any, fullResponse: any) => boolean | void) // true or void for ok, false or throw for error
318 type Tester = number
319 | TesterFunction
320 | RegExp