Skip to content

Commit f0e0110

Browse files
kriszypclaude
andcommitted
Verify 500 responses hit source twice via call counter
Adds tables.CacheOfHttp.serverErrorCalls counter (matching the CacheOfResource.sourceGetsPerformed pattern) so the non-cacheable 500 test can assert the source was invoked on both requests rather than relying on server-timing headers. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 8d4067f commit f0e0110

2 files changed

Lines changed: 4 additions & 0 deletions

File tree

unitTests/apiTests/basicREST-test.mjs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -457,6 +457,7 @@ describe('test REST calls', () => {
457457
assert(!response2.headers['server-timing'].includes('miss'));
458458
});
459459
it('does not cache a non-cacheable 500 response', async () => {
460+
const callsBefore = tables.CacheOfHttp.serverErrorCalls;
460461
const response = await axios.get('http://localhost:9926/CacheOfHttp/server-error', {
461462
validateStatus: () => true,
462463
});
@@ -466,6 +467,7 @@ describe('test REST calls', () => {
466467
validateStatus: () => true,
467468
});
468469
assert.equal(response2.status, 500);
470+
assert.equal(tables.CacheOfHttp.serverErrorCalls, callsBefore + 2);
469471
});
470472
it('does not store status in cached record for 200 responses', async () => {
471473
// The CacheOfHttp 'created-response' source returns a 200 with a custom header

unitTests/testApp/resources.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,7 @@ tables.CacheOfResource.sourcedFrom({
169169
});
170170

171171
// test transparent HTTP caching straight through
172+
tables.CacheOfHttp.serverErrorCalls = 0;
172173
tables.CacheOfHttp.sourcedFrom({
173174
async get(target) {
174175
switch (target) {
@@ -197,6 +198,7 @@ tables.CacheOfHttp.sourcedFrom({
197198
case 'not-found':
198199
return new Response('Not Found', { status: 404 });
199200
case 'server-error':
201+
tables.CacheOfHttp.serverErrorCalls++;
200202
return new Response('Internal Server Error', { status: 500 });
201203
}
202204
},

0 commit comments

Comments
 (0)