-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtests.js
77 lines (66 loc) · 2.6 KB
/
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
import { Mongo } from 'meteor/mongo';
import { Analyze } from 'meteor/qualia:analyze-observes';
let SampleCollection = new Mongo.Collection('sample_collection'),
buildCollection = () => {
SampleCollection.remove({});
for (let i=0; i < 20; i++) {
SampleCollection.insert({ i });
}
},
withObserve = ({ selector={}, fields, sort, limit, skip, disableOplog=false, callbacks={} }, callback) => {
let cursor = SampleCollection.find(selector, { fields, sort, limit, skip, disableOplog }),
observe = cursor.observe(callbacks)
;
callback();
observe.stop();
}
;
buildCollection();
Tinytest.add('analyze-observes - ordered observe', test => {
withObserve({ callbacks: { addedAt(){} } }, key => {
let result = Object.values(Analyze.go())[0];
test.isTrue(_.size(result.oplogBlockers) === 1 && result.oplogBlockers.ordered);
});
});
Tinytest.add('analyze-observes - disable oplog', test => {
withObserve({ disableOplog: true }, key => {
let result = Object.values(Analyze.go())[0];
test.isTrue(_.size(result.oplogBlockers) === 1 && result.oplogBlockers.oplogDisabled);
});
});
Tinytest.add('analyze-observes - has skip', test => {
withObserve({ skip: 10 }, key => {
let result = Object.values(Analyze.go())[0];
test.isTrue(_.size(result.oplogBlockers) === 1 && result.oplogBlockers.hasSkip);
});
});
Tinytest.add('analyze-observes - limit without sort', test => {
withObserve({ limit: 10 }, key => {
let result = Object.values(Analyze.go())[0];
test.isTrue(_.size(result.oplogBlockers) === 1 && result.oplogBlockers.unsortedLimit);
});
});
Tinytest.add('analyze-observes - limit with sort', test => {
withObserve({ limit: 10, sort: {i: 1} }, key => {
let result = Object.values(Analyze.go())[0];
test.isTrue(_.size(result.oplogBlockers) === 0);
});
});
Tinytest.add('analyze-observes - bad projection', test => {
withObserve({ fields: { a: { $slice: 10 } } }, key => {
let result = Object.values(Analyze.go())[0];
test.isTrue(_.size(result.oplogBlockers) === 1 && result.oplogBlockers.badProjection);
});
});
Tinytest.add('analyze-observes - has $where', test => {
withObserve({ selector: { $where: 'true' } }, key => {
let result = Object.values(Analyze.go())[0];
test.isTrue(_.size(result.oplogBlockers) === 1 && result.oplogBlockers.fancySelector);
});
});
Tinytest.add('analyze-observes - bad sort', test => {
withObserve({ sort: { $natural: 1} }, key => {
let result = Object.values(Analyze.go())[0];
test.isTrue(_.size(result.oplogBlockers) === 1 && result.oplogBlockers.badSort);
});
});