Skip to content

Commit 38d5ed8

Browse files
committed
test: add support for a simulated read workload to sdam_viz
1 parent be0d36e commit 38d5ed8

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

test/tools/sdam_viz

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,10 @@ const argv = require('yargs')
88
.usage('Usage: $0 [options] <connection string>')
99
.demandCommand(1)
1010
.help('h')
11+
.describe('workload', 'Simulate a read workload')
1112
.describe('legacy', 'Use the legacy topology types')
1213
.alias('l', 'legacy')
14+
.alias('w', 'workload')
1315
.alias('h', 'help').argv;
1416

1517
function print(msg) {
@@ -22,6 +24,7 @@ const client = new MongoClient(uri, {
2224
useUnifiedTopology: !argv.legacy
2325
});
2426

27+
let workloadInterrupt = false;
2528
async function run() {
2629
print(
2730
`connecting to: ${chalk.bold(uri)} using ${chalk.bold(
@@ -85,8 +88,33 @@ async function run() {
8588
});
8689

8790
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+
}
88114
}
89115

116+
const wait = ms => new Promise(resolve => setTimeout(resolve, ms));
117+
90118
function diff(lhs, rhs, fields, comparator) {
91119
return fields.reduce((diff, field) => {
92120
if (lhs[field] == null || rhs[field] == null) {
@@ -141,5 +169,6 @@ function topologyDescriptionDiff(lhs, rhs) {
141169

142170
run().catch(error => console.log('Caught', error));
143171
process.on('SIGINT', async function() {
172+
workloadInterrupt = true;
144173
await client.close();
145174
});

0 commit comments

Comments
 (0)