-
Notifications
You must be signed in to change notification settings - Fork 352
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(persister): Handle concurrent find requests #88
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
import Persister from '../../src'; | ||
import { timeout } from '@pollyjs/utils'; | ||
|
||
describe('Unit | Persister', function() { | ||
it('should exist', function() { | ||
|
@@ -19,24 +20,37 @@ describe('Unit | Persister', function() { | |
}; | ||
|
||
class CustomPersister extends Persister { | ||
findRecording() { | ||
async findRecording() { | ||
callCounts.find++; | ||
await timeout(1); | ||
|
||
return recording; | ||
} | ||
|
||
saveRecording() { | ||
async saveRecording() { | ||
callCounts.save++; | ||
await timeout(1); | ||
} | ||
|
||
deleteRecording() { | ||
async deleteRecording() { | ||
callCounts.delete++; | ||
await timeout(1); | ||
} | ||
} | ||
|
||
this.persister = new CustomPersister({}); | ||
}); | ||
|
||
it('should handle concurrent find requests', async function() { | ||
await Promise.all([ | ||
this.persister.find('test'), | ||
this.persister.find('test'), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we update the test to assert when adding another recordingId that it will increment? i.e.:
|
||
this.persister.find('test') | ||
]); | ||
|
||
expect(callCounts.find).to.equal(1); | ||
}); | ||
|
||
it('caches', async function() { | ||
await this.persister.find('test'); | ||
await this.persister.find('test'); | ||
|
@@ -49,7 +63,11 @@ describe('Unit | Persister', function() { | |
recording = null; | ||
|
||
await this.persister.find('test'); | ||
await this.persister.find('test'); | ||
await Promise.all([ | ||
this.persister.find('test'), | ||
this.persister.find('test'), | ||
this.persister.find('test') | ||
]); | ||
await this.persister.find('test'); | ||
|
||
expect(callCounts.find).to.equal(3); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Might be worth naming this anonymous fn for a better callstack