From 4c18dabd62fcbd73770945ef494988d2ac25e1fb Mon Sep 17 00:00:00 2001 From: Michael Vines Date: Fri, 2 Nov 2018 17:59:51 -0700 Subject: [PATCH] test: add retries to account change notification test --- web3.js/test/connection.test.js | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/web3.js/test/connection.test.js b/web3.js/test/connection.test.js index 49baa8c3fb..866b744960 100644 --- a/web3.js/test/connection.test.js +++ b/web3.js/test/connection.test.js @@ -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);