-
Notifications
You must be signed in to change notification settings - Fork 122
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
1 parent
a7042ea
commit 6945d21
Showing
3 changed files
with
27 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
// worker.js | ||
const vm = require('vm'); | ||
|
||
module.exports = ({ payload, context }) => { | ||
const script = new vm.Script(payload); | ||
script.runInNewContext(context); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import Piscina from '..'; | ||
import { test } from 'tap'; | ||
import { resolve } from 'path'; | ||
|
||
test('pool will maintain run and wait time histograms', async ({ | ||
equal, | ||
fail | ||
}) => { | ||
const pool = new Piscina({ | ||
filename: resolve(__dirname, 'fixtures/vm.js') | ||
}); | ||
|
||
try { | ||
await pool.run({ payload: 'throw new Error("foo")' }); | ||
fail('Expected an error'); | ||
} catch (error) { | ||
equal(error.message, 'foo'); | ||
} | ||
}); |