3
3
const semver = require ( 'semver' )
4
4
const agent = require ( '../../dd-trace/test/plugins/agent' )
5
5
const { NODE_MAJOR } = require ( '../../../version' )
6
+ const id = require ( '../../dd-trace/src/id' )
6
7
7
8
describe ( 'Plugin' , ( ) => {
8
- let id
9
9
let tracer
10
10
let dbName
11
11
@@ -23,7 +23,8 @@ describe('Plugin', () => {
23
23
function connect ( ) {
24
24
// mongoose.connect('mongodb://username:password@host:port/database?options...');
25
25
// actually the first part of the path is the dbName and not the collection
26
- mongoose . connect ( `mongodb://localhost:27017/${ dbName } ` , {
26
+ return mongoose . connect ( `mongodb://localhost:27017/${ dbName } ` , {
27
+ bufferCommands : false ,
27
28
useNewUrlParser : true ,
28
29
useUnifiedTopology : true
29
30
} )
@@ -33,25 +34,14 @@ describe('Plugin', () => {
33
34
return agent . load ( [ 'mongodb-core' ] )
34
35
} )
35
36
36
- before ( ( ) => {
37
- id = require ( '../../dd-trace/src/id' )
37
+ before ( async ( ) => {
38
38
tracer = require ( '../../dd-trace' )
39
39
40
- dbName = id ( ) . toString ( )
41
-
42
40
mongoose = require ( `../../../versions/mongoose@${ version } ` ) . get ( )
43
41
44
- connect ( )
45
-
46
- withPeerService (
47
- ( ) => tracer ,
48
- 'mongodb-core' ,
49
- ( done ) => {
50
- const PeerCat = mongoose . model ( 'PeerCat' , { name : String } )
51
- new PeerCat ( { name : 'PeerCat' } ) . save ( ) . catch ( done )
52
- done ( )
53
- } ,
54
- 'db' , 'peer.service' )
42
+ dbName = id ( ) . toString ( )
43
+
44
+ await connect ( )
55
45
} )
56
46
57
47
after ( ( ) => {
@@ -62,6 +52,15 @@ describe('Plugin', () => {
62
52
return agent . close ( { ritmReset : false } )
63
53
} )
64
54
55
+ withPeerService (
56
+ ( ) => tracer ,
57
+ 'mongodb-core' ,
58
+ ( done ) => {
59
+ const PeerCat = mongoose . model ( 'PeerCat' , { name : String } )
60
+ new PeerCat ( { name : 'PeerCat' } ) . save ( ) . catch ( done )
61
+ } ,
62
+ ( ) => dbName , 'peer.service' )
63
+
65
64
it ( 'should propagate context with write operations' , ( ) => {
66
65
const Cat = mongoose . model ( 'Cat1' , { name : String } )
67
66
0 commit comments