Skip to content

Commit

Permalink
expand tests and fix loss of stack
Browse files Browse the repository at this point in the history
  • Loading branch information
splitice committed Nov 30, 2022
1 parent 3a86b90 commit 764a969
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 4 deletions.
8 changes: 4 additions & 4 deletions lib/ThroatQueueFunction.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,16 +52,16 @@ function ThroatQueueFunction(n = 5){
}
running.push(rr)
try {
await r
} finally {
r.then(d.resolve, d.reject)
d.resolve(await r)
} catch(ex) {
d.reject(ex)
}

while(running.length >= n){
await race(cancellationState, running)
}

return d.promise
return await d.promise
}

ret = Q.canceller(ret)
Expand Down
60 changes: 60 additions & 0 deletions test/throat_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,9 @@ describe('ThroatQueueFunction', function(){
deferred.resolve(true)

await tf(null)

await Q.delay(10)

expect(count).to.be.eql(5)

})
Expand Down Expand Up @@ -193,4 +196,61 @@ describe('ThroatQueueFunction', function(){
expect(e.stack).to.contain('testFn')
}
})


it('should capture stack trace (2)', async() => {
async function testFn(){
const errors = []
const tf = ThroatQueueFunction(5)

for(let i = 0; i < 10; i++){
try {
await tf(async ()=>{
await Q.delay(1)
throw new Error('test')
})
} catch(ex) {
errors.push(ex)
}
}

return errors
}

const errors = await testFn()
expect(errors.length).to.be.eql(10)
for(const e of errors){
expect(e.stack).to.be.a('string')
expect(e.stack).to.contain('testFn')
}
})
it('should capture stack trace (3)', async() => {
async function testFn(){
const errors = []
const tf = ThroatQueueFunction(5)

for(let i = 0; i < 10; i++){
const p = tf(async ()=>{
await Q.delay(1)
throw new Error('test')
})
errors.push(p.catch(ex=>ex))
}

const ret = []
for(let e of errors){
e = await e
ret.push(e)
}

return ret
}

const errors = await testFn()
expect(errors.length).to.be.eql(10)
for(let e of errors){
expect(e.stack).to.be.a('string')
expect(e.stack).to.contain('testFn')
}
})
})

0 comments on commit 764a969

Please sign in to comment.