This repository has been archived by the owner on Feb 4, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 108
/
apm_tests.js
157 lines (138 loc) · 4.79 KB
/
apm_tests.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
'use strict';
const Pool = require('../../../lib/connection/pool');
const BSON = require('bson');
const apm = require('../../../lib/connection/apm');
const expect = require('chai').expect;
const commands = require('../../../lib/connection/commands');
const Query = commands.Query;
const KillCursor = commands.KillCursor;
const GetMore = commands.GetMore;
const bson = new BSON();
const pool = new Pool({}, { bson });
describe('APM tests', function() {
describe('CommandStartedEvent', function() {
// Only run on single topology since these are unit tests
const metadata = { requires: { topology: ['single'] } };
it('should wrap a basic query option', metadata, function() {
const db = 'test1';
const coll = 'testingQuery';
const query = new Query(
bson,
`${db}.${coll}`,
{
testCmd: 1,
fizz: 'buzz',
star: 'trek'
},
{}
);
const startEvent = new apm.CommandStartedEvent(pool, query);
expect(startEvent).to.have.property('commandName', 'testCmd');
expect(startEvent).to.have.property('databaseName', db);
expect(startEvent).to.have.property('requestId', query.requestId);
expect(startEvent)
.to.have.property('connectionId')
.that.is.a('string');
expect(startEvent)
.to.have.property('command')
.that.deep.equals(query.query);
});
it('should wrap a basic killCursor command', metadata, function() {
const db = 'test2';
const coll = 'testingKillCursors';
const killCursor = new KillCursor(bson, `${db}.${coll}`, [12, 42, 57]);
const startEvent = new apm.CommandStartedEvent(pool, killCursor);
expect(startEvent).to.have.property('commandName', 'killCursors');
expect(startEvent).to.have.property('databaseName', db);
expect(startEvent).to.have.property('requestId', killCursor.requestId);
expect(startEvent)
.to.have.property('connectionId')
.that.is.a('string');
expect(startEvent)
.to.have.property('command')
.that.deep.equals({
killCursors: coll,
cursors: killCursor.cursorIds
});
});
it('should wrap a basic GetMore command', metadata, function() {
const db = 'test3';
const coll = 'testingGetMore';
const numberToReturn = 321;
const getMore = new GetMore(bson, `${db}.${coll}`, 5525, { numberToReturn });
const startEvent = new apm.CommandStartedEvent(pool, getMore);
expect(startEvent).to.have.property('commandName', 'getMore');
expect(startEvent).to.have.property('databaseName', db);
expect(startEvent).to.have.property('requestId', getMore.requestId);
expect(startEvent)
.to.have.property('connectionId')
.that.is.a('string');
expect(startEvent)
.to.have.property('command')
.that.deep.equals({
getMore: getMore.cursorId,
collection: coll,
batchSize: numberToReturn
});
});
it(
'should upconvert a Query wrapping a command into the corresponding command',
metadata,
function() {
const db = 'admin';
const coll = '$cmd';
const query = new Query(
bson,
`${db}.${coll}`,
{
$query: {
testCmd: 1,
fizz: 'buzz',
star: 'trek'
}
},
{}
);
const startEvent = new apm.CommandStartedEvent(pool, query);
expect(startEvent).to.have.property('commandName', 'testCmd');
expect(startEvent).to.have.property('databaseName', db);
expect(startEvent).to.have.property('requestId', query.requestId);
expect(startEvent)
.to.have.property('connectionId')
.that.is.a('string');
expect(startEvent)
.to.have.property('command')
.that.deep.equals(query.query.$query);
}
);
it('should upconvert a Query wrapping a query into a find command', metadata, function() {
const db = 'test5';
const coll = 'testingFindCommand';
const query = new Query(
bson,
`${db}.${coll}`,
{
$query: {
testCmd: 1,
fizz: 'buzz',
star: 'trek'
}
},
{}
);
const startEvent = new apm.CommandStartedEvent(pool, query);
expect(startEvent).to.have.property('commandName', 'find');
expect(startEvent).to.have.property('databaseName', db);
expect(startEvent).to.have.property('requestId', query.requestId);
expect(startEvent)
.to.have.property('connectionId')
.that.is.a('string');
expect(startEvent)
.to.have.property('command')
.that.deep.equals({
find: coll,
filter: query.query.$query
});
});
});
});