Skip to content

Commit

Permalink
fix(owl-bot): fix two timing related bugs (#1413)
Browse files Browse the repository at this point in the history
  • Loading branch information
bcoe authored Feb 11, 2021
1 parent 1f7654d commit 8a60f32
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 2 deletions.
2 changes: 1 addition & 1 deletion packages/gcf-utils/src/gcf-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ export class GCFBootstrapper {
this.probot = createProbot({overrides: cfg});
}

this.probot.load(appFn);
await this.probot.load(appFn);

return this.probot;
}
Expand Down
7 changes: 6 additions & 1 deletion packages/owl-bot/src/handlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,12 @@ export async function onPostProcessorPublished(
installation: configs.installationId,
});
// TODO(bcoe): switch updatedAt to date from PubSub payload:
createOnePullRequestForUpdatingLock(configsStore, octokit, repo, lock);
await createOnePullRequestForUpdatingLock(
configsStore,
octokit,
repo,
lock
);
}
}
}
Expand Down
28 changes: 28 additions & 0 deletions packages/owl-bot/test/owl-bot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,4 +119,32 @@ describe('owlBot', () => {
githubMock.done();
});
});
it('loads async app before handling request', async () => {
const probot = createProbot({
overrides: {
githubToken: 'abc123',
Octokit: ProbotOctokit.defaults({
retry: {enabled: false},
throttle: {enabled: false},
}),
},
});
await probot.load(async (app: Probot) => {
await new Promise(resolve => {
setTimeout(() => {
return resolve(undefined);
}, 100);
});
// eslint-disable-next-line @typescript-eslint/no-explicit-any
owlBot('abc123', app, sandbox.stub() as any);
});
const loggerStub = sandbox.stub(logger, 'info');
await probot.receive({
// eslint-disable-next-line @typescript-eslint/no-explicit-any
name: 'pubsub.message' as any,
payload: {},
id: 'abc123',
});
sandbox.assert.calledOnce(loggerStub);
});
});

0 comments on commit 8a60f32

Please sign in to comment.