Skip to content

Commit

Permalink
tests(oracle): avoid explicit waiting for 1 second
Browse files Browse the repository at this point in the history
  • Loading branch information
davidyuk committed Apr 28, 2021
1 parent dc955e1 commit f81cd3a
Showing 1 changed file with 11 additions and 15 deletions.
26 changes: 11 additions & 15 deletions test/integration/oracle.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,22 +47,18 @@ describe('Oracle', function () {
query.decode(query.query).toString().should.be.equal("{'city': 'Berlin'}")
})

it('Pool for queries', async () => {
let queries = []
const stopPolling = await oracle.pollQueries((q) => {
queries = [...q.map(a => a.id), ...queries]
it('Pool for queries', (done) => {
let count = 0
const stopPolling = oracle.pollQueries((queries) => {
count += queries.length
if (count !== 4) return
stopPolling()
done()
}, { interval: 100 })
await oracle.postQuery("{'city': 'Berlin2'}")
await oracle.postQuery("{'city': 'Berlin3'}")
await oracle.postQuery("{'city': 'Berlin4'}")
await (new Promise((resolve) => {
setTimeout(() => {
stopPolling()
resolve()
}, 1000)
}))
queries.length.should.be.equal(4)
})
oracle.postQuery("{'city': 'Berlin2'}")
.then(() => oracle.postQuery("{'city': 'Berlin3'}"))
.then(() => oracle.postQuery("{'city': 'Berlin4'}"))
}).timeout(10000)

it('Poll for response for query without response', async () => {
return query.pollForResponse({ attempts: 2, interval: 1000 }).should.be.rejectedWith(Error)
Expand Down

0 comments on commit f81cd3a

Please sign in to comment.