Skip to content

Commit

Permalink
Test no rotation when error after cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
brandonpayton committed Jul 19, 2024
1 parent 571b6a0 commit 2948e57
Showing 1 changed file with 27 additions and 3 deletions.
30 changes: 27 additions & 3 deletions packages/php-wasm/node/src/test/rotate-php-runtime.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,28 @@ describe('rotatePHPRuntime()', () => {
expect(recreateRuntimeSpy).toHaveBeenCalledTimes(2);
}, 30_000);

it('Should not rotate after the cleanup handler is called, even if max requests is reached', async () => {
const recreateRuntimeSpy = vitest.fn(recreateRuntime);
const php = new PHP(await recreateRuntimeSpy());
const cleanup = rotatePHPRuntime({
php,
cwd: '/test-root',
recreateRuntime: recreateRuntimeSpy,
maxRequests: 1,
});
// Rotate the PHP runtime
await php.run({ code: `` });
expect(recreateRuntimeSpy).toHaveBeenCalledTimes(2);

cleanup();

// No further rotation should happen
await php.run({ code: `` });
await php.run({ code: `` });

expect(recreateRuntimeSpy).toHaveBeenCalledTimes(2);
}, 30_000);

it('Should recreate the PHP runtime after PHP crash', async () => {
const recreateRuntimeSpy = vitest.fn(recreateRuntime);
const php = new PHP(await recreateRuntimeSpy());
Expand All @@ -83,7 +105,7 @@ describe('rotatePHPRuntime()', () => {
expect(recreateRuntimeSpy).toHaveBeenCalledTimes(2);
}, 30_000);

it('Should stop rotating after the cleanup handler is called', async () => {
it('Should not rotate after the cleanup handler is called, even if there is a PHP runtime error', async () => {
const recreateRuntimeSpy = vitest.fn(recreateRuntime);
const php = new PHP(await recreateRuntimeSpy());
const cleanup = rotatePHPRuntime({
Expand All @@ -99,8 +121,10 @@ describe('rotatePHPRuntime()', () => {
cleanup();

// No further rotation should happen
await php.run({ code: `` });
await php.run({ code: `` });
php.dispatchEvent({
type: 'request.error',
error: new Error('mock error'),
});

expect(recreateRuntimeSpy).toHaveBeenCalledTimes(2);
}, 30_000);
Expand Down

0 comments on commit 2948e57

Please sign in to comment.