-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: add unique id for each process
- Loading branch information
Showing
4 changed files
with
114 additions
and
0 deletions.
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
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,94 @@ | ||
|
||
process.chdir(__dirname); | ||
|
||
var PM2 = require('../..'); | ||
var should = require('should'); | ||
var assert = require('assert') | ||
|
||
describe('Unique ID verification', function() { | ||
describe('when starting', function() { | ||
var _id = null | ||
|
||
before(function(done) { | ||
PM2.kill(done); | ||
}); | ||
|
||
before(function(done) { | ||
PM2.delete('all', function() { done() }); | ||
}); | ||
|
||
it('should connect to PM2', function(done) { | ||
PM2.connect(done); | ||
}); | ||
|
||
it('should start a script', function(done) { | ||
PM2.start('../fixtures/child.js', function(err) { | ||
should(err).be.null(); | ||
PM2.list(function(err, list) { | ||
should(err).be.null(); | ||
assert(list.length > 0) | ||
assert(typeof list[0].pm2_env.unique_id === 'string') | ||
_id = list[0].pm2_env.unique_id | ||
done(); | ||
}); | ||
}); | ||
}); | ||
|
||
it('should stop app by id', function(done) { | ||
PM2.stop(0, done); | ||
}); | ||
|
||
it('should restart and not changed unique id', function(done) { | ||
PM2.restart(0, (err) => { | ||
should(err).be.null(); | ||
PM2.list(function(err, list) { | ||
should(err).be.null(); | ||
assert(list.length > 0) | ||
assert(typeof list[0].pm2_env.unique_id === 'string') | ||
assert( list[0].pm2_env.unique_id === _id) | ||
done(); | ||
}); | ||
}); | ||
}); | ||
|
||
|
||
it('should generate another unique id for new process', function(done) { | ||
PM2.start('./../fixtures/child.js', { name: 'toto' }, function(err) { | ||
assert(!err); | ||
PM2.list(function(err, list) { | ||
should(err).be.null(); | ||
assert(list.length === 2) | ||
assert(typeof list[0].pm2_env.unique_id === 'string') | ||
assert(typeof list[1].pm2_env.unique_id === 'string') | ||
assert(list[0].pm2_env.unique_id !== typeof list[1].pm2_env.unique_id) | ||
done(); | ||
}); | ||
}); | ||
}); | ||
|
||
it('should duplicate a process and have a new id', function(done) { | ||
PM2.scale('child', 2, function(err) { | ||
assert(!err); | ||
PM2.list(function(err, list) { | ||
should(err).be.null(); | ||
should(list.length).eql(3); | ||
assert(typeof list[0].pm2_env.unique_id === 'string') | ||
assert(typeof list[1].pm2_env.unique_id === 'string') | ||
assert(typeof list[2].pm2_env.unique_id === 'string') | ||
assert(list[0].pm2_env.unique_id !== typeof list[1].pm2_env.unique_id) | ||
assert(list[1].pm2_env.unique_id !== typeof list[2].pm2_env.unique_id) | ||
assert(list[0].pm2_env.unique_id !== typeof list[2].pm2_env.unique_id) | ||
done(); | ||
}); | ||
}); | ||
}); | ||
|
||
after(function(done) { | ||
PM2.delete('all', done); | ||
}); | ||
|
||
after(function(done) { | ||
PM2.kill(done); | ||
}); | ||
}); | ||
}); |