From c2bdc0b8a5f09285c52faf82fbe00765e466551c Mon Sep 17 00:00:00 2001 From: Diamond Lewis Date: Fri, 17 Feb 2023 14:17:58 -0600 Subject: [PATCH 1/9] fix: `Parse.File.cancel` retry attempts --- gulpfile.js | 29 +++++++------ integration/test/ParseDistTest.js | 72 ++++++++++++++++++++++++++++++- src/ParseFile.js | 1 + src/RESTController.js | 3 +- 4 files changed, 89 insertions(+), 16 deletions(-) diff --git a/gulpfile.js b/gulpfile.js index f282f4d83..3cdf4daa9 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -65,8 +65,8 @@ const FULL_HEADER = ( ' */\n' ); -gulp.task('compile', function() { - return gulp.src('src/*.js') +function compileTask(stream) { + return stream .pipe(babel({ presets: PRESETS[BUILD], plugins: PLUGINS[BUILD], @@ -76,6 +76,10 @@ gulp.task('compile', function() { plugins: ['minify-dead-code-elimination'], })) .pipe(gulp.dest(path.join('lib', BUILD))); +} + +gulp.task('compile', function() { + return compileTask(gulp.src('src/*.js')); }); gulp.task('browserify', function(cb) { @@ -132,14 +136,15 @@ gulp.task('minify-weapp', function() { }); gulp.task('watch', function() { - return watch('src/*.js', { ignoreInitial: false, verbose: true }) - .pipe(babel({ - presets: PRESETS[BUILD], - plugins: PLUGINS[BUILD], - })) - // Second pass to kill BUILD-switched code - .pipe(babel({ - plugins: ['minify-dead-code-elimination'], - })) - .pipe(gulp.dest(path.join('lib', BUILD))); + if (BUILD === 'browser') { + const watcher = gulp.watch('src/*.js', { ignoreInitial: false }, gulp.series('compile', 'browserify', 'minify')); + watcher.on('add', function(path) { + console.log(`File ${path} was added`); + }); + watcher.on('change', function(path) { + console.log(`File ${path} was changed`); + }); + return watcher; + } + return compileTask(watch('src/*.js', { ignoreInitial: false, verbose: true })); }); diff --git a/integration/test/ParseDistTest.js b/integration/test/ParseDistTest.js index d3fa39db5..23692b6c0 100644 --- a/integration/test/ParseDistTest.js +++ b/integration/test/ParseDistTest.js @@ -1,11 +1,17 @@ const puppeteer = require('puppeteer'); +const { resolvingPromise } = require('../../lib/node/promiseUtils'); + let browser = null; let page = null; for (const fileName of ['parse.js', 'parse.min.js']) { describe(`Parse Dist Test ${fileName}`, () => { beforeEach(async () => { - browser = await puppeteer.launch(); - page = await browser.newPage(); + // Uncomment to test, setting a timeout with `done` to keep the browser open + // browser = await puppeteer.launch({ args: ['--disable-web-security'], headless:false, devtools: true, userDataDir: path.resolve(__dirname, './myUserDataDir') }); + browser = await puppeteer.launch({ args: ['--disable-web-security'] }); + const context = await browser.createIncognitoBrowserContext(); + page = await context.newPage(); + await page.setCacheEnabled(false); await page.goto(`http://localhost:1337/${fileName}`); }); @@ -35,5 +41,67 @@ for (const fileName of ['parse.js', 'parse.min.js']) { expect(obj).toBeDefined(); expect(obj.id).toEqual(response); }); + + it('can cancel save file with uri', async () => { + let requestsCount = 0; + let abortedCount = 0; + const promise = resolvingPromise(); + await page.setRequestInterception(true); + page.on('request', request => { + if (!request.url().includes('favicon.ico')) { + requestsCount += 1; + } + request.continue(); + }); + page.on('requestfailed', request => { + if (request.failure().errorText === 'net::ERR_ABORTED' && !request.url().includes('favicon.ico')) { + abortedCount += 1; + promise.resolve(); + } + }); + await page.evaluate(async () => { + const parseLogo = + 'https://raw.githubusercontent.com/parse-community/parse-server/master/.github/parse-server-logo.png'; + const file = new Parse.File('parse-server-logo', { uri: parseLogo }); + file.save().then(() => {}); + file.cancel(); + }); + await promise; + expect(requestsCount).toBe(1); + expect(abortedCount).toBe(1); + }); + + it('can cancel save file with base64', async () => { + let requestsCount = 0; + let abortedCount = 0; + const promise = resolvingPromise(); + await page.setRequestInterception(true); + page.on('request', request => { + if (!request.url().includes('favicon.ico')) { + requestsCount += 1; + } + request.continue(); + }); + page.on('requestfailed', request => { + if (request.failure().errorText === 'net::ERR_ABORTED' && !request.url().includes('favicon.ico')) { + abortedCount += 1; + promise.resolve(); + } + }); + await page.evaluate(async () => { + const file = new Parse.File('parse-base64.txt', { base64: 'ParseA==' }); + file.save().then(() => {}); + + const intervalId = setInterval(() => { + if (file._requestTask && typeof file._requestTask.abort === 'function') { + file.cancel(); + clearInterval(intervalId); + } + }, 1); + }); + await promise; + expect(requestsCount).toBe(1); + expect(abortedCount).toBe(1); + }); }); } diff --git a/src/ParseFile.js b/src/ParseFile.js index 7660e9b3b..1d7ff6945 100644 --- a/src/ParseFile.js +++ b/src/ParseFile.js @@ -296,6 +296,7 @@ class ParseFile { */ cancel() { if (this._requestTask && typeof this._requestTask.abort === 'function') { + this._requestTask._aborted = true; this._requestTask.abort(); } this._requestTask = null; diff --git a/src/RESTController.js b/src/RESTController.js index 5e0c42d0f..91ff57531 100644 --- a/src/RESTController.js +++ b/src/RESTController.js @@ -194,11 +194,10 @@ const RESTController = { xhr, }); }; - xhr.send(data); - if (options && typeof options.requestTask === 'function') { options.requestTask(xhr); } + xhr.send(data); }; dispatch(); From bba60256c3742a4e978ba07d561257de1f7a873f Mon Sep 17 00:00:00 2001 From: Diamond Lewis Date: Fri, 17 Feb 2023 14:20:10 -0600 Subject: [PATCH 2/9] remove helper --- integration/test/ParseDistTest.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/integration/test/ParseDistTest.js b/integration/test/ParseDistTest.js index 23692b6c0..9b146236d 100644 --- a/integration/test/ParseDistTest.js +++ b/integration/test/ParseDistTest.js @@ -6,8 +6,6 @@ let page = null; for (const fileName of ['parse.js', 'parse.min.js']) { describe(`Parse Dist Test ${fileName}`, () => { beforeEach(async () => { - // Uncomment to test, setting a timeout with `done` to keep the browser open - // browser = await puppeteer.launch({ args: ['--disable-web-security'], headless:false, devtools: true, userDataDir: path.resolve(__dirname, './myUserDataDir') }); browser = await puppeteer.launch({ args: ['--disable-web-security'] }); const context = await browser.createIncognitoBrowserContext(); page = await context.newPage(); From 0b8400c7ff55743682bcf3d44ee52fb2371499e7 Mon Sep 17 00:00:00 2001 From: Diamond Lewis Date: Fri, 17 Feb 2023 14:31:06 -0600 Subject: [PATCH 3/9] set task after sending data --- src/RESTController.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/RESTController.js b/src/RESTController.js index 91ff57531..5e0c42d0f 100644 --- a/src/RESTController.js +++ b/src/RESTController.js @@ -194,10 +194,11 @@ const RESTController = { xhr, }); }; + xhr.send(data); + if (options && typeof options.requestTask === 'function') { options.requestTask(xhr); } - xhr.send(data); }; dispatch(); From 86b512cc745584b620a746140de9cb091899132d Mon Sep 17 00:00:00 2001 From: Diamond Lewis Date: Fri, 17 Feb 2023 14:37:26 -0600 Subject: [PATCH 4/9] fix flaky test --- integration/test/ParseDistTest.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/integration/test/ParseDistTest.js b/integration/test/ParseDistTest.js index 9b146236d..03f4b151f 100644 --- a/integration/test/ParseDistTest.js +++ b/integration/test/ParseDistTest.js @@ -87,7 +87,13 @@ for (const fileName of ['parse.js', 'parse.min.js']) { } }); await page.evaluate(async () => { - const file = new Parse.File('parse-base64.txt', { base64: 'ParseA==' }); + const parseLogo = + 'https://raw.githubusercontent.com/parse-community/parse-server/master/.github/parse-server-logo.png'; + const logo = new Parse.File('parse-server-logo', { uri: parseLogo }); + await logo.save(); + const base64 = await logo.getData(); + + const file = new Parse.File('parse-base64.txt', { base64 }); file.save().then(() => {}); const intervalId = setInterval(() => { @@ -98,7 +104,7 @@ for (const fileName of ['parse.js', 'parse.min.js']) { }, 1); }); await promise; - expect(requestsCount).toBe(1); + expect(requestsCount).toBe(3); expect(abortedCount).toBe(1); }); }); From cc728c566cad42696648f6bffe2702da013e8e94 Mon Sep 17 00:00:00 2001 From: Diamond Lewis Date: Fri, 17 Feb 2023 14:52:15 -0600 Subject: [PATCH 5/9] flaky test abort immediately --- integration/test/ParseDistTest.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/integration/test/ParseDistTest.js b/integration/test/ParseDistTest.js index 03f4b151f..c88f3fd2b 100644 --- a/integration/test/ParseDistTest.js +++ b/integration/test/ParseDistTest.js @@ -81,6 +81,9 @@ for (const fileName of ['parse.js', 'parse.min.js']) { request.continue(); }); page.on('requestfailed', request => { + console.log(request); + console.log(request.failure()); + console.log(request.url()); if (request.failure().errorText === 'net::ERR_ABORTED' && !request.url().includes('favicon.ico')) { abortedCount += 1; promise.resolve(); @@ -94,14 +97,13 @@ for (const fileName of ['parse.js', 'parse.min.js']) { const base64 = await logo.getData(); const file = new Parse.File('parse-base64.txt', { base64 }); - file.save().then(() => {}); - const intervalId = setInterval(() => { if (file._requestTask && typeof file._requestTask.abort === 'function') { file.cancel(); clearInterval(intervalId); } }, 1); + file.save().then(() => {}); }); await promise; expect(requestsCount).toBe(3); From f1263a0206601314049a591e52dd06ce5285164f Mon Sep 17 00:00:00 2001 From: Diamond Lewis Date: Fri, 17 Feb 2023 15:15:48 -0600 Subject: [PATCH 6/9] improve tests --- integration/test/ParseDistTest.js | 30 +++++++++++++++++++++++------- 1 file changed, 23 insertions(+), 7 deletions(-) diff --git a/integration/test/ParseDistTest.js b/integration/test/ParseDistTest.js index c88f3fd2b..2943b6ac6 100644 --- a/integration/test/ParseDistTest.js +++ b/integration/test/ParseDistTest.js @@ -62,7 +62,16 @@ for (const fileName of ['parse.js', 'parse.min.js']) { 'https://raw.githubusercontent.com/parse-community/parse-server/master/.github/parse-server-logo.png'; const file = new Parse.File('parse-server-logo', { uri: parseLogo }); file.save().then(() => {}); - file.cancel(); + + return new Promise((resolve) => { + const intervalId = setInterval(() => { + if (file._requestTask && typeof file._requestTask.abort === 'function') { + file.cancel(); + clearInterval(intervalId); + resolve(); + } + }, 1); + }); }); await promise; expect(requestsCount).toBe(1); @@ -89,6 +98,7 @@ for (const fileName of ['parse.js', 'parse.min.js']) { promise.resolve(); } }); + console.log('beforeEvaluation'); await page.evaluate(async () => { const parseLogo = 'https://raw.githubusercontent.com/parse-community/parse-server/master/.github/parse-server-logo.png'; @@ -97,15 +107,21 @@ for (const fileName of ['parse.js', 'parse.min.js']) { const base64 = await logo.getData(); const file = new Parse.File('parse-base64.txt', { base64 }); - const intervalId = setInterval(() => { - if (file._requestTask && typeof file._requestTask.abort === 'function') { - file.cancel(); - clearInterval(intervalId); - } - }, 1); file.save().then(() => {}); + + return new Promise((resolve) => { + const intervalId = setInterval(() => { + if (file._requestTask && typeof file._requestTask.abort === 'function') { + file.cancel(); + clearInterval(intervalId); + resolve(); + } + }, 1); + }); }); + console.log('beforePromise'); await promise; + console.log('afterPromise'); expect(requestsCount).toBe(3); expect(abortedCount).toBe(1); }); From 2cf567fe37ac1cde1861ef2a79bce86c3e45a4f0 Mon Sep 17 00:00:00 2001 From: Diamond Lewis Date: Fri, 17 Feb 2023 16:07:43 -0600 Subject: [PATCH 7/9] debugging --- integration/test/ParseDistTest.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/integration/test/ParseDistTest.js b/integration/test/ParseDistTest.js index 2943b6ac6..4cea1afbc 100644 --- a/integration/test/ParseDistTest.js +++ b/integration/test/ParseDistTest.js @@ -99,7 +99,7 @@ for (const fileName of ['parse.js', 'parse.min.js']) { } }); console.log('beforeEvaluation'); - await page.evaluate(async () => { + const result = await page.evaluate(async () => { const parseLogo = 'https://raw.githubusercontent.com/parse-community/parse-server/master/.github/parse-server-logo.png'; const logo = new Parse.File('parse-server-logo', { uri: parseLogo }); @@ -114,11 +114,12 @@ for (const fileName of ['parse.js', 'parse.min.js']) { if (file._requestTask && typeof file._requestTask.abort === 'function') { file.cancel(); clearInterval(intervalId); - resolve(); + resolve('cancelled called'); } }, 1); }); }); + console.log('eval', result); console.log('beforePromise'); await promise; console.log('afterPromise'); From e17483a2f29acd0ba09233c260486dff586d6c3d Mon Sep 17 00:00:00 2001 From: Diamond Lewis Date: Fri, 17 Feb 2023 16:34:39 -0600 Subject: [PATCH 8/9] last try --- integration/test/ParseDistTest.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/integration/test/ParseDistTest.js b/integration/test/ParseDistTest.js index 4cea1afbc..c4134b23c 100644 --- a/integration/test/ParseDistTest.js +++ b/integration/test/ParseDistTest.js @@ -84,13 +84,15 @@ for (const fileName of ['parse.js', 'parse.min.js']) { const promise = resolvingPromise(); await page.setRequestInterception(true); page.on('request', request => { + console.log('request', request); + console.log(request.url()); if (!request.url().includes('favicon.ico')) { requestsCount += 1; } request.continue(); }); page.on('requestfailed', request => { - console.log(request); + console.log('requestfailed', request); console.log(request.failure()); console.log(request.url()); if (request.failure().errorText === 'net::ERR_ABORTED' && !request.url().includes('favicon.ico')) { @@ -98,6 +100,10 @@ for (const fileName of ['parse.js', 'parse.min.js']) { promise.resolve(); } }); + page.on('requestfinished', request => { + console.log('requestfinished', request); + console.log(request.url()); + }); console.log('beforeEvaluation'); const result = await page.evaluate(async () => { const parseLogo = From ff0242e72a4cb40e813aaa9a08953fda5d56785b Mon Sep 17 00:00:00 2001 From: Diamond Lewis Date: Tue, 28 Feb 2023 15:23:29 -0600 Subject: [PATCH 9/9] remove flaky test --- integration/test/ParseDistTest.js | 55 ------------------------------- 1 file changed, 55 deletions(-) diff --git a/integration/test/ParseDistTest.js b/integration/test/ParseDistTest.js index c4134b23c..fa2090d76 100644 --- a/integration/test/ParseDistTest.js +++ b/integration/test/ParseDistTest.js @@ -77,60 +77,5 @@ for (const fileName of ['parse.js', 'parse.min.js']) { expect(requestsCount).toBe(1); expect(abortedCount).toBe(1); }); - - it('can cancel save file with base64', async () => { - let requestsCount = 0; - let abortedCount = 0; - const promise = resolvingPromise(); - await page.setRequestInterception(true); - page.on('request', request => { - console.log('request', request); - console.log(request.url()); - if (!request.url().includes('favicon.ico')) { - requestsCount += 1; - } - request.continue(); - }); - page.on('requestfailed', request => { - console.log('requestfailed', request); - console.log(request.failure()); - console.log(request.url()); - if (request.failure().errorText === 'net::ERR_ABORTED' && !request.url().includes('favicon.ico')) { - abortedCount += 1; - promise.resolve(); - } - }); - page.on('requestfinished', request => { - console.log('requestfinished', request); - console.log(request.url()); - }); - console.log('beforeEvaluation'); - const result = await page.evaluate(async () => { - const parseLogo = - 'https://raw.githubusercontent.com/parse-community/parse-server/master/.github/parse-server-logo.png'; - const logo = new Parse.File('parse-server-logo', { uri: parseLogo }); - await logo.save(); - const base64 = await logo.getData(); - - const file = new Parse.File('parse-base64.txt', { base64 }); - file.save().then(() => {}); - - return new Promise((resolve) => { - const intervalId = setInterval(() => { - if (file._requestTask && typeof file._requestTask.abort === 'function') { - file.cancel(); - clearInterval(intervalId); - resolve('cancelled called'); - } - }, 1); - }); - }); - console.log('eval', result); - console.log('beforePromise'); - await promise; - console.log('afterPromise'); - expect(requestsCount).toBe(3); - expect(abortedCount).toBe(1); - }); }); }