egg/test/lib/plugins/schedule.test.js
2016-07-18 21:16:35 +08:00

35 lines
944 B
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

'use strict';
const path = require('path');
const fs = require('fs');
const utils = require('../../utils');
describe.skip('test/lib/plugins/schedule.test.js', () => {
it('should schedule work', function* () {
const app = utils.cluster('apps/schedule', {
workers: 4,
});
yield app.ready();
yield sleep(5000);
app.close();
const log = getLogContent('schedule');
// 由于 app.ready() 在 agent.ready 之后ci 可能要耗太多时间导致多执行一次
contains(log, 'cron').should.within(1, 2);
});
});
function sleep(time) {
return new Promise(resolve => {
setTimeout(resolve, time);
});
}
function getLogContent(name) {
const logPath = path.join(__dirname, '../../fixtures/apps', name, 'logs', name, `${name}-web.log`);
return fs.readFileSync(logPath, 'utf8');
}
function contains(content, match) {
return content.split('\n').filter(line => line.indexOf(match) >= 0).length;
}