test: add retries to account change notification test

This commit is contained in:
Michael Vines 2018-11-02 17:59:51 -07:00
parent cbcb774c82
commit 4c18dabd62
1 changed files with 15 additions and 1 deletions

View File

@ -442,8 +442,22 @@ test('account change notification', async () => {
await connection.removeAccountChangeListener(subscriptionId);
// mockCallback should be called twice
expect(mockCallback.mock.calls).toHaveLength(2);
//
// retry a couple times if needed
let i = 0;
for (;;) {
if (mockCallback.mock.calls.length === 2) {
break;
}
if (++i === 5) {
console.log(JSON.stringify(mockCallback.mock.calls));
throw new Error('mockCallback should be called twice');
}
await sleep(500);
}
// First mockCallback call is due to SystemProgram.createAccount()
expect(mockCallback.mock.calls[0][0].tokens).toBe(42);