Big News: Socket raises $60M Series C at a $1B valuation to secure software supply chains for AI-driven development.Announcement
Sign In

phantom-workers

Package Overview
Dependencies
Maintainers
2
Versions
16
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

phantom-workers - npm Package Compare versions

Comparing version
0.4.2
to
0.4.3
+18
test/test-script/recycling.js
var port = require("system").env['PHANTOM_WORKER_PORT'];
var host = require("system").env['PHANTOM_WORKER_HOST'];
var ws = require('webserver').create()
var numberOfRequests = 1
function handler (req, res) {
res.statusCode = 200;
res.write(numberOfRequests++);
res.close();
// always stop listening after the request to replicate ECONNREFUSED errors
setTimeout(function () {
ws.close();
})
}
ws.listen(host + ':' + port, handler);
+18
-4

@@ -87,2 +87,3 @@ var childProcess = require('child_process'),

var childOpts = {
windowsHide: true,
env: objectAssign({}, process.env, self.options.env)

@@ -178,4 +179,9 @@ };

res.on("end", function () {
self.isBusy = false;
cb(null, result ? JSON.parse(result) : null);
self.isBusy = false;
try {
var parsedResult = result ? JSON.parse(result) : null
cb(null, parsedResult)
} catch (e) {
cb(new Error('Unparsable response from the phantomjs ' + result))
}
});

@@ -189,5 +195,13 @@ });

req.on("error", function (e) {
req.on("error", function (e) {
// recycle phantomjs if it cannot accept connections to avoid getting it freezed in the invalid state
if (e.code === 'ECONNREFUSED' || e.code === 'ECONNRESET') {
return self.recycle(function (recycleError) {
self.isBusy = false;
cb(recycleError || e);
});
}
self.isBusy = false;
cb(e);
cb(e);
});

@@ -194,0 +208,0 @@

+2
-2
{
"name": "phantom-workers",
"version": "0.4.2",
"version": "0.4.3",
"author": {

@@ -33,3 +33,3 @@ "name": "Jan Blaha",

"scripts": {
"test": "mocha test/test.js --timeout 4000"
"test": "mocha test/test.js --timeout 8000"
},

@@ -36,0 +36,0 @@ "main": "index.js",

@@ -203,2 +203,42 @@ var should = require("should"),

});
it("should recycle phantom after the web server fails to receive the connection", function (done) {
// request to phantomjs on LINUX with stopped web server timesout which causes the recycle anyway
// this tests only verifies WINDOWS behavior, on which the phantomjs with stopped server drops connections with ECONNREFUSED
if (process.platform !== 'win32') {
return done();
}
phantomManager = new PhantomManager({
pathToPhantomScript: path.join(__dirname, "test-script", "recycling.js"),
numberOfWorkers: 1
});
phantomManager.start(function(err) {
if (err)
return done(err);
// every second request fails to receive connection and should cause recycling
phantomManager.execute({}, function (err, res) {
if (err)
return done(err);
res.should.be.eql(1)
// intentionally fails
phantomManager.execute({}, function (err, res) {
if (!err)
return done(new Error('Every second request should fail'));
phantomManager.execute({}, function (err, res) {
if (err)
return done(err);
// acumulator should get restarted
res.should.be.eql(1)
done();
});
});
});
});
});
});

Sorry, the diff of this file is not supported yet