-
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.
Merge pull request #3822 from imarakho/flush_parameter
added parameter to flush command(added tests)
- Loading branch information
Showing
3 changed files
with
110 additions
and
8 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
process.env.NODE_ENV = 'test'; | ||
|
||
var PM2 = require('../..'); | ||
var should = require('should'); | ||
var fs = require('fs'); | ||
var path = require('path'); | ||
|
||
describe('Programmatic flush feature test', function() { | ||
var proc1 = null; | ||
var procs = []; | ||
|
||
var pm2 = new PM2.custom({ | ||
cwd : __dirname + '/../fixtures' | ||
}); | ||
|
||
before(function(done) { | ||
pm2.delete('all', function() { | ||
done(); | ||
}); | ||
}); | ||
|
||
after(function(done) { | ||
pm2.disconnect(done); | ||
}); | ||
|
||
afterEach(function(done) { | ||
pm2.delete('all', done); | ||
}); | ||
|
||
describe('Flush test', function() { | ||
it('flush all logs', function(done) { | ||
pm2.start({ | ||
script: './echo.js', | ||
error_file : 'error-echo.log', | ||
out_file : 'out-echo.log', | ||
merge_logs: false | ||
}, function(err, procs) { | ||
should(err).be.null(); | ||
|
||
var out_file = procs[0].pm2_env.pm_out_log_path; | ||
var err_file = procs[0].pm2_env.pm_err_log_path; | ||
out_file.should.containEql('out-echo-0.log'); | ||
err_file.should.containEql('error-echo-0.log'); | ||
pm2.flush(undefined, function(){ | ||
fs.readFileSync(out_file, "utf8").should.be.empty(); | ||
fs.readFileSync(err_file, "utf8").should.be.empty(); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
it('flush only echo logs', function(done) { | ||
pm2.start({ | ||
script: './echo.js', | ||
error_file : 'error-echo.log', | ||
out_file : 'out-echo.log', | ||
merge_logs: false | ||
}, function(err, procs) { | ||
should(err).be.null(); | ||
var out_file = procs[0].pm2_env.pm_out_log_path; | ||
var err_file = procs[0].pm2_env.pm_err_log_path; | ||
pm2.start({ | ||
script: './001-test.js', | ||
error_file : 'error-001-test.log', | ||
out_file : 'out-001-test.log', | ||
merge_logs: false | ||
}, function(err, procs, $out_file, $err_file) { | ||
should(err).be.null(); | ||
var out_file1 = procs[0].pm2_env.pm_out_log_path; | ||
var err_file1 = procs[0].pm2_env.pm_err_log_path; | ||
pm2.flush('echo', function(){ | ||
fs.readFileSync(out_file, "utf8").toString().should.be.empty(); | ||
fs.readFileSync(err_file, "utf8").toString().should.be.empty(); | ||
fs.readFileSync(out_file1, "utf8").toString().should.not.be.empty(); | ||
fs.readFileSync(err_file1, "utf8").toString().should.not.be.empty(); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); |