Skip to content

Commit 31532bf

Browse files
authored
add test for consistentRead (#834)
1 parent 02ca5df commit 31532bf

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

packages/edge-config/src/index.node.test.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -545,6 +545,31 @@ describe('createClient', () => {
545545
});
546546
});
547547

548+
describe('get(key, { consistentRead: true })', () => {
549+
it('should handle multiple concurrent requests correctly', async () => {
550+
const edgeConfig = createClient(process.env.EDGE_CONFIG);
551+
552+
let i = 0;
553+
// Create a more realistic response with a proper body stream
554+
// @ts-expect-error - aaa
555+
fetchMock.mockImplementation(() => {
556+
return new Response(JSON.stringify(`bar${i++}`), {
557+
headers: { 'content-type': 'application/json' },
558+
});
559+
});
560+
561+
// Make multiple concurrent requests
562+
const a = edgeConfig.get('foo', { consistentRead: true });
563+
const b = edgeConfig.get('foo', { consistentRead: true });
564+
565+
await a;
566+
await b;
567+
await expect(a).resolves.toEqual('bar0');
568+
await expect(b).resolves.toEqual('bar1');
569+
expect(fetchMock).toHaveBeenCalledTimes(2);
570+
});
571+
});
572+
548573
describe('has(key)', () => {
549574
describe('when item exists', () => {
550575
it('should return true', async () => {

0 commit comments

Comments
 (0)