Skip to content

Commit

Permalink
chore: adapt tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Unitech committed Sep 21, 2018
1 parent e2aa872 commit 4dc68d4
Show file tree
Hide file tree
Showing 8 changed files with 50 additions and 47 deletions.
4 changes: 3 additions & 1 deletion lib/API/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -195,10 +195,12 @@
"docDefault": 16,
"docDescription": "Number of times a script is restarted when it exits in less than min_uptime"
},
"execute_command": {
"type": "boolean"
},
"exec_mode": {
"type": "string",
"regex": "^(cluster|fork)(_mode)?$",
"alias": "executeCommand",
"desc": "it should be \"cluster\"(\"cluster_mode\") or \"fork\"(\"fork_mode\") only",
"docDefault": "fork",
"docDescription": "Set the execution mode, possible values: fork|cluster"
Expand Down
8 changes: 6 additions & 2 deletions lib/Common.js
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ Common.sink.determineExecMode = function(app) {
};

var resolveNodeInterpreter = function(app) {
if (app.exec_mode.indexOf('cluster') > -1) {
if (app.exec_mode && app.exec_mode.indexOf('cluster') > -1) {
Common.printError(cst.PREFIX_MSG_WARNING + chalk.bold.yellow('Choosing the Node.js version in cluster mode is not supported'));
return false;
}
Expand All @@ -355,7 +355,6 @@ var resolveNodeInterpreter = function(app) {
? '/versions/node/v' + node_version + '/bin/node'
: '/v' + node_version + '/bin/node';
var nvm_node_path = path.join(nvm_path, path_to_node);

try {
fs.accessSync(nvm_node_path);
} catch(e) {
Expand Down Expand Up @@ -606,6 +605,11 @@ Common.verifyConfs = function(appConfs){
delete app.command
}

if (app.execute_command == true) {
app.exec_mode = 'fork'
delete app.execute_command
}

app.username = Common.getCurrentUsername();

// If command is like pm2 start "python xx.py --ok"
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@
"chalk": "^2.4.1",
"chokidar": "^2.0.4",
"cli-table-redemption": "^1.0.0",
"coffee-script": "^1.12.7",
"commander": "2.15.1",
"cron": "^1.3",
"debug": "^3.1",
Expand Down
15 changes: 7 additions & 8 deletions test/e2e/logs/log-reload.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,18 @@ cd $file_path

echo -e "\033[1mRunning tests:\033[0m"

>out-rel.log
# >out-rel.log

$pm2 start echo.js -o out-rel.log --merge-logs -i 1
# $pm2 start echo.js -o out-rel.log --merge-logs -i 1

$pm2 reloadLogs

sleep 1
# $pm2 reloadLogs

grep "Reloading log..." out-rel.log
# sleep 2

spec "Should have started the reloading action"
# grep "Reloading log..." ~/.pm2/pm2.log
# spec "Should have started the reloading action"

rm out-rel.log
# rm out-rel.log

## FORK MODE

Expand Down
50 changes: 14 additions & 36 deletions test/fixtures/ecosystem.config.js
Original file line number Diff line number Diff line change
@@ -1,33 +1,22 @@
module.exports = {
/**
* Application configuration section
* http://pm2.keymetrics.io/docs/usage/application-declaration/
*/
apps : [
apps : [{
name: 'API',
script: 'app.js',

// First application
{
name : 'API',
script : 'app.js',
env: {
COMMON_VARIABLE: 'true'
},
env_production : {
NODE_ENV: 'production'
}
// Options reference: https://pm2.io/doc/en/runtime/reference/ecosystem-file/
args: 'one two',
instances: 1,
autorestart: true,
watch: false,
max_memory_restart: '1G',
env: {
NODE_ENV: 'development'
},

// Second application
{
name : 'WEB',
script : 'web.js'
env_production: {
NODE_ENV: 'production'
}
],
}],

/**
* Deployment section
* http://pm2.keymetrics.io/docs/usage/deployment/
*/
deploy : {
production : {
user : 'node',
Expand All @@ -36,17 +25,6 @@ module.exports = {
repo : 'git@github.com:repo.git',
path : '/var/www/production',
'post-deploy' : 'npm install && pm2 reload ecosystem.config.js --env production'
},
dev : {
user : 'node',
host : '212.83.163.1',
ref : 'origin/master',
repo : 'git@github.com:repo.git',
path : '/var/www/development',
'post-deploy' : 'npm install && pm2 reload ecosystem.config.js --env dev',
env : {
NODE_ENV: 'dev'
}
}
}
};
Binary file modified test/fixtures/git/index
Binary file not shown.
9 changes: 9 additions & 0 deletions test/fixtures/nvm-node-version/app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@

var http = require('http');

var server = http.createServer(function(req, res) {
res.writeHead(200);
res.end('hey');
}).listen(process.env.PORT || 8000, function() {
console.log('App listening on port %d', server.address().port);
});
10 changes: 10 additions & 0 deletions test/fixtures/nvm-node-version/web.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@


var http = require('http');

var server = http.createServer(function(req, res) {
res.writeHead(200);
res.end('hey');
}).listen(8002, function() {
console.log('App listening on port %d', server.address().port);
});

0 comments on commit 4dc68d4

Please sign in to comment.