| 168 | let workloadCounter = 0; |
| 169 | let workloadInterrupt = false; |
| 170 | async function scheduleWorkload(client) { |
| 171 | if (!workloadInterrupt) { |
| 172 | // immediately reschedule work |
| 173 | workloadTimer = setTimeout(() => scheduleWorkload(client), 7000); |
| 174 | } |
| 175 | |
| 176 | const currentWorkload = workloadCounter++; |
| 177 | |
| 178 | try { |
| 179 | print(`${chalk.yellow(`workload#${currentWorkload}`)} issuing find...`); |
| 180 | const result = await client |
| 181 | .db('test') |
| 182 | .collection('test') |
| 183 | .find({}, { socketTimeoutMS: 2000 }) |
| 184 | .limit(1) |
| 185 | .toArray(); |
| 186 | |
| 187 | print( |
| 188 | `${chalk.yellow(`workload#${currentWorkload}`)} find completed: ${JSON.stringify(result)}` |
| 189 | ); |
| 190 | } catch (e) { |
| 191 | print(`${chalk.yellow(`workload#${currentWorkload}`)} find failed: ${e.message}`); |
| 192 | } |
| 193 | } |
| 194 | |
| 195 | let writeWorkloadTimer; |
| 196 | let writeWorkloadCounter = 0; |