@@ -8,8 +8,10 @@ const argv = require('yargs')
8
8
. usage ( 'Usage: $0 [options] <connection string>' )
9
9
. demandCommand ( 1 )
10
10
. help ( 'h' )
11
+ . describe ( 'workload' , 'Simulate a read workload' )
11
12
. describe ( 'legacy' , 'Use the legacy topology types' )
12
13
. alias ( 'l' , 'legacy' )
14
+ . alias ( 'w' , 'workload' )
13
15
. alias ( 'h' , 'help' ) . argv ;
14
16
15
17
function print ( msg ) {
@@ -22,6 +24,7 @@ const client = new MongoClient(uri, {
22
24
useUnifiedTopology : ! argv . legacy
23
25
} ) ;
24
26
27
+ let workloadInterrupt = false ;
25
28
async function run ( ) {
26
29
print (
27
30
`connecting to: ${ chalk . bold ( uri ) } using ${ chalk . bold (
@@ -85,8 +88,33 @@ async function run() {
85
88
} ) ;
86
89
87
90
await client . connect ( ) ;
91
+
92
+ if ( argv . workload ) {
93
+ for ( ; ; ) {
94
+ if ( workloadInterrupt ) {
95
+ return ;
96
+ }
97
+
98
+ await wait ( 2000 ) ;
99
+
100
+ try {
101
+ print ( 'issuing find...' ) ;
102
+ const result = await client
103
+ . db ( 'test' )
104
+ . collection ( 'test' )
105
+ . find ( { } )
106
+ . limit ( 1 )
107
+ . toArray ( ) ;
108
+ print ( ` > find completed: ${ JSON . stringify ( result ) } ` ) ;
109
+ } catch ( e ) {
110
+ print ( ` > find failed: ${ e . message } ` ) ;
111
+ }
112
+ }
113
+ }
88
114
}
89
115
116
+ const wait = ms => new Promise ( resolve => setTimeout ( resolve , ms ) ) ;
117
+
90
118
function diff ( lhs , rhs , fields , comparator ) {
91
119
return fields . reduce ( ( diff , field ) => {
92
120
if ( lhs [ field ] == null || rhs [ field ] == null ) {
@@ -141,5 +169,6 @@ function topologyDescriptionDiff(lhs, rhs) {
141
169
142
170
run ( ) . catch ( error => console . log ( 'Caught' , error ) ) ;
143
171
process . on ( 'SIGINT' , async function ( ) {
172
+ workloadInterrupt = true ;
144
173
await client . close ( ) ;
145
174
} ) ;
0 commit comments