1
1
'use strict' ;
2
- var test = require ( './shared' ) . assert ;
3
2
var setupDatabase = require ( './shared' ) . setupDatabase ;
4
- // var f = require('util').format;
5
3
var expect = require ( 'chai' ) . expect ;
6
4
7
5
// ./node_modules/.bin/mongodb-test-runner -l -e replicaset test/functional/operation_changestream_example_tests.js
8
- // ./node_modules/.bin/mongodb-test-runner -l -e -s replicaset test/functional/operation_changestream_example_tests.js
9
6
10
7
describe ( 'Changestream Examples' , function ( ) {
11
8
before ( function ( ) {
12
9
return setupDatabase ( this . configuration ) ;
13
10
} ) ;
14
11
15
- it ( 'has next' , {
12
+ it . only ( 'has next' , {
16
13
metadata : {
17
14
requires : {
18
15
topology : [ 'replicaset' ]
@@ -29,26 +26,27 @@ describe('Changestream Examples', function() {
29
26
30
27
// Start Changestream Example 1
31
28
changeStream . next ( function ( err , next ) {
32
- if ( err ) console . log ( err ) ;
29
+ if ( err ) return console . log ( err ) ;
33
30
expect ( err ) . to . equal ( null ) ;
34
31
expect ( next ) . to . exist ;
35
- client . close ( function ( ) {
36
- done ( ) ;
37
- } ) ;
32
+ client . close ( ) ;
33
+ done ( ) ;
38
34
} ) ;
39
35
// End Changestream Example 1
40
36
41
37
// Insert something
42
- collection . insertOne ( { a : 1 } , function ( err , result ) {
43
- if ( err ) return console . log ( err ) ;
44
- expect ( err ) . to . equal ( null ) ;
45
- expect ( result ) . to . exist ;
38
+ setTimeout ( function ( ) {
39
+ collection . insertOne ( { a : 1 } , function ( err , result ) {
40
+ if ( err ) return console . log ( err ) ;
41
+ expect ( err ) . to . equal ( null ) ;
42
+ expect ( result ) . to . exist ;
43
+ } ) ;
46
44
} ) ;
47
45
} ) ;
48
46
}
49
47
} ) ;
50
48
51
- it ( ' event emitter api', {
49
+ it . only ( 'uses an event emitter api', {
52
50
metadata : {
53
51
requires : {
54
52
topology : [ 'replicaset' ]
@@ -64,27 +62,26 @@ describe('Changestream Examples', function() {
64
62
const collection = db . collection ( 'changeStreamExample1b' ) ;
65
63
const changeStream = collection . watch ( ) ;
66
64
67
- // Use event emitter API
65
+ // Using event emitter API
68
66
changeStream . on ( 'change' , function ( change ) {
69
- console . log ( 'change' , change )
70
67
expect ( change ) . to . exist ;
71
- client . close ( function ( ) {
72
- done ( ) ;
73
- } ) ;
68
+ client . close ( ) ;
69
+ done ( ) ;
74
70
} ) ;
75
71
76
72
// Insert something
77
- collection . insertOne ( { a : 1 } , function ( err , result ) {
78
- console . log ( 'inserting' ) ;
79
- if ( err ) return console . log ( err ) ;
80
- expect ( err ) . to . equal ( null ) ;
81
- expect ( result ) . to . exist ;
73
+ setTimeout ( function ( ) {
74
+ collection . insertOne ( { a : 1 } , function ( err , result ) {
75
+ if ( err ) return console . log ( err ) ;
76
+ expect ( err ) . to . equal ( null ) ;
77
+ expect ( result ) . to . exist ;
78
+ } ) ;
82
79
} ) ;
83
80
} ) ;
84
81
}
85
82
} ) ;
86
83
87
- it . only ( 'streams changestream' , {
84
+ it . only ( 'streams a changestream' , {
88
85
metadata : {
89
86
requires : {
90
87
topology : [ 'replicaset' ]
@@ -105,16 +102,18 @@ describe('Changestream Examples', function() {
105
102
} ) ;
106
103
107
104
// Insert something
108
- collection . insertOne ( { a : 1 } , function ( err , result ) {
109
- if ( err ) return console . log ( err ) ;
110
- expect ( err ) . to . equal ( null ) ;
111
- expect ( result ) . to . exist ;
105
+ setTimeout ( function ( ) {
106
+ collection . insertOne ( { a : 1 } , function ( err , result ) {
107
+ if ( err ) return console . log ( err ) ;
108
+ expect ( err ) . to . equal ( null ) ;
109
+ expect ( result ) . to . exist ;
110
+ } ) ;
112
111
} ) ;
113
112
} ) ;
114
113
}
115
114
} ) ;
116
115
117
- it ( ' full document update', {
116
+ it . only ( 'specifies a full document update', {
118
117
metadata : {
119
118
requires : {
120
119
topology : [ 'replicaset' ]
@@ -125,31 +124,32 @@ describe('Changestream Examples', function() {
125
124
test : function ( done ) {
126
125
const configuration = this . configuration ;
127
126
const client = configuration . newClient ( configuration . writeConcernMax ( ) , { poolSize : 1 } ) ;
128
- // Start Changestream Example 2
129
127
client . connect ( function ( err , client ) {
130
128
const db = client . db ( configuration . db ) ;
131
129
const collection = db . collection ( 'changeStreamExample1b' ) ;
132
130
const changeStream = collection . watch ( { fullDocument : 'updateLookup' } ) ;
133
131
132
+ // Start Changestream Example 2
134
133
changeStream . on ( 'change' , function ( change ) {
135
- console . log ( change ) ;
136
134
expect ( change ) . to . exist ;
137
135
client . close ( ) ;
138
136
done ( ) ;
139
137
} ) ;
140
138
// End Changestream Eample 2
141
139
142
140
// Insert something
143
- collection . insertOne ( { a : 1 } , function ( err , result ) {
144
- if ( err ) return console . log ( err ) ;
145
- expect ( err ) . to . equal ( null ) ;
146
- expect ( result ) . to . exist ;
141
+ setTimeout ( function ( ) {
142
+ collection . insertOne ( { a : 1 } , function ( err , result ) {
143
+ if ( err ) return console . log ( err ) ;
144
+ expect ( err ) . to . equal ( null ) ;
145
+ expect ( result ) . to . exist ;
146
+ } ) ;
147
147
} ) ;
148
148
} ) ;
149
149
}
150
150
} ) ;
151
151
152
- it ( 'creates and uses a resume token' , {
152
+ it . only ( 'creates and uses a resume token' , {
153
153
metadata : {
154
154
requires : {
155
155
topology : [ 'replicaset' ]
@@ -159,11 +159,11 @@ describe('Changestream Examples', function() {
159
159
test : function ( done ) {
160
160
const configuration = this . configuration ;
161
161
const client = configuration . newClient ( configuration . writeConcernMax ( ) , { poolSize : 1 } ) ;
162
- // Start Changestream Example 3
163
162
client . connect ( function ( err , client ) {
164
163
const db = client . db ( configuration . db ) ;
165
164
const collection = db . collection ( 'changeStreamExample3' ) ;
166
165
const changeStream = collection . watch ( ) ;
166
+ // Start Changestream Example 3
167
167
let resumeToken ;
168
168
169
169
changeStream . hasNext ( function ( err , change ) {
@@ -196,15 +196,17 @@ describe('Changestream Examples', function() {
196
196
} ) ;
197
197
} ) ;
198
198
// Insert something
199
- collection . insertOne ( { a : 1 } , function ( err , result ) {
200
- if ( err ) return console . log ( err ) ;
201
- expect ( err ) . to . equal ( null ) ;
202
- expect ( result ) . to . exist ;
203
- // Insert something else
204
- collection . insertOne ( { a : 2 } , function ( err , result ) {
199
+ setTimeout ( function ( ) {
200
+ collection . insertOne ( { a : 1 } , function ( err , result ) {
205
201
if ( err ) return console . log ( err ) ;
206
202
expect ( err ) . to . equal ( null ) ;
207
203
expect ( result ) . to . exist ;
204
+ // Insert something else
205
+ collection . insertOne ( { a : 2 } , function ( err , result ) {
206
+ if ( err ) return console . log ( err ) ;
207
+ expect ( err ) . to . equal ( null ) ;
208
+ expect ( result ) . to . exist ;
209
+ } ) ;
208
210
} ) ;
209
211
} ) ;
210
212
} ) ;
0 commit comments