Spaces:
Sleeping
Sleeping
File size: 2,324 Bytes
61d39e2 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 |
const axios = require('axios');
const YAML = require('yaml');
const https = require('node:https');
const { parseArgs } = require('node:util');
const url = require('node:url');
const path_ = require('path');
const fs = require('fs');
let config;
try {
({ values: {
config,
}, positionals: [id] } = parseArgs({
options: {
config: {
type: 'string',
},
},
allowPositionals: true,
}));
} catch (e) {
if ( args.length < 1 ) {
console.error(
'Usage: readdir_profile [OPTIONS]\n' +
'\n' +
'Options:\n' +
' --config=<path> (required) Path to configuration file\n' +
''
);
process.exit(1);
}
}
const conf = YAML.parse(fs.readFileSync(config).toString());
const dir = `/${conf.username}/readdir_test`
// process.on('SIGINT', async () => {
// process.exit(0);
// });
const httpsAgent = new https.Agent({
rejectUnauthorized: false
})
const getURL = (...path) => {
const apiURL = new url.URL(conf.url);
apiURL.pathname = path_.posix.join(
apiURL.pathname,
...path
);
return apiURL.href;
};
const epoch = Date.now();
const TIME_BEFORE_TEST = 20 * 1000; // 10 seconds
const NOOP = () => {};
let check = () => {
if ( Date.now() - epoch >= TIME_BEFORE_TEST ) {
console.log(
`\x1B[36;1m !!! START THE TEST !!! \x1B[0m`
);
check = NOOP;
}
};
const measure_readdir = async () => {
const ts_start = Date.now();
await axios.request({
httpsAgent,
method: 'post',
url: getURL('readdir'),
data: {
path: dir,
},
headers: {
'Authorization': `Bearer ${conf.token}`,
'Content-Type': 'application/json'
}
})
const ts_end = Date.now();
const diff = ts_end - ts_start;
await fs.promises.appendFile(
`readdir_profile.txt`,
`${Date.now()},${diff}\n`
)
check();
await new Promise(rslv => {
setTimeout(rslv, 5);
});
}
const main = async () => {
while (true) {
await measure_readdir();
}
}
main();
|