-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathagent.test.js
59 lines (53 loc) · 1.69 KB
/
agent.test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
'use strict';
const assert = require('assert');
const fs = require('fs');
const path = require('path');
const execSync = require('child_process').execSync;
const mm = require('egg-mock');
const utils = require('../utils');
describe('test/lib/agent.test.js', () => {
afterEach(mm.restore);
describe('agent throw', () => {
const baseDir = utils.getFilepath('apps/agent-throw');
let app;
before(() => {
app = utils.cluster('apps/agent-throw');
return app.ready();
});
after(() => app.close());
it('should catch exeption', done => {
app.httpRequest()
.get('/agent-throw')
.expect(200, err => {
assert(!err);
setTimeout(() => {
const body = fs.readFileSync(path.join(baseDir, 'logs/agent-throw/common-error.log'), 'utf8');
assert(body.includes('nodejs.unhandledExceptionError: agent error'));
app.notExpect(/nodejs.AgentWorkerDiedError/);
done();
}, 1000);
});
});
it('should catch uncaughtException string error', done => {
app.httpRequest()
.get('/agent-throw-string')
.expect(200, err => {
assert(!err);
setTimeout(() => {
const body = fs.readFileSync(path.join(baseDir, 'logs/agent-throw/common-error.log'), 'utf8');
assert(body.includes('nodejs.unhandledExceptionError: agent error string'));
done();
}, 1000);
});
});
});
if (process.platform !== 'win32') {
describe('require agent', () => {
it('should exit normal', () => {
execSync(`${process.execPath} -e "require('./lib/agent')"`, {
timeout: 3000,
});
});
});
}
});