From 50604a67ed00ab5d79b21c623373894877be33b1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Soko=C5=82owski?= Date: Mon, 22 Jul 2019 16:13:38 -0400 Subject: [PATCH] add missing await, rename update to safeUpdate MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Jakub SokoĊ‚owski --- src/app.js | 4 ++-- src/comments.js | 6 +++--- test/app.js | 4 ++-- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/app.js b/src/app.js index bf721bf..460a404 100644 --- a/src/app.js +++ b/src/app.js @@ -36,7 +36,7 @@ const App = ({ghc, schema}) => { await ghc.db.addBuild({ ...ctx.params, build: ctx.request.body }) - await ghc.update(ctx.params) + await ghc.safeUpdate(ctx.params) ctx.status = 201 ctx.body = {status:'ok'} } @@ -44,7 +44,7 @@ const App = ({ghc, schema}) => { /* just re-render the comment */ router.post('/builds/:repo/:pr/refresh', async (ctx) => { - await ghc.update(ctx.params) + await ghc.safeUpdate(ctx.params) ctx.status = 201 ctx.body = {status:'ok'} }) diff --git a/src/comments.js b/src/comments.js index 0e4b512..d84012c 100644 --- a/src/comments.js +++ b/src/comments.js @@ -59,7 +59,7 @@ class Comments { return rval.data.id } - async _update ({repo, pr}) { + async update ({repo, pr}) { /* check if repo is in a whitelist */ if (!this.repos.includes(repo)) { throw Error(`Repo not whitelisted: ${repo}`) @@ -74,14 +74,14 @@ class Comments { } } - async update ({repo, pr}) { + async safeUpdate ({repo, pr}) { /* we use a lock to avoid creating multiple comments */ let key = repo + pr /* use existing lock for repo+pr or create a new one */ this.locks[key] || ( this.locks[key] = new AwaitLock() ) await this.locks[key].acquireAsync() try { - this._update({repo, pr}) + await this.update({repo, pr}) } finally { this.locks[key].release() } diff --git a/test/app.js b/test/app.js index 89f3a9a..12bb275 100644 --- a/test/app.js +++ b/test/app.js @@ -48,7 +48,7 @@ describe('App', () => { expect(ghc.db.addBuild).calledOnceWith({ repo: 'REPO-1', pr: 'PR-1', build: sample.BUILD, }) - expect(ghc.update).calledOnceWith({ + expect(ghc.safeUpdate).calledOnceWith({ repo: 'REPO-1', pr: 'PR-1' }) }) @@ -65,7 +65,7 @@ describe('App', () => { expect(ghc.db.addBuild).not.calledOnceWith({ repo: 'REPO-1', pr: 'PR-1', build: sample.BUILD }) - expect(ghc.update).calledOnceWith({ + expect(ghc.safeUpdate).calledOnceWith({ repo: 'REPO-1', pr: 'PR-1', }) })