cli: add testworker

Signed-off-by: Yonle <yonle@lecturify.net>
This commit is contained in:
Yonle 2024-05-12 10:10:56 +07:00
parent 5375f98241
commit 9cba4108ba
2 changed files with 44 additions and 5 deletions

View File

@ -12,11 +12,12 @@ function showHelp() {
console.log(
"Usage: bostr [command] (argv)\n" +
"Available command:\n" +
" makeconf [conffile] - Make config file\n" +
" checkconf [conffile] - Check config file\n" +
" start [conffile] - Run bostr with specified config\n" +
" hexconverter [nip19] - Convert NIP-19 string to hex\n" +
" help - Show this help text\n\n" +
" makeconf [conffile] - Make config file\n" +
" checkconf [conffile] - Check config file\n" +
" start [conffile] - Run bostr with specified config\n" +
" hexconverter [nip19] - Convert NIP-19 string to hex\n" +
" testworker [conffile] - Test worker with specified bostr config\n" +
" help - Show this help text\n\n" +
"Software is licensed under BSD-3-Clause\n" +
"https://github.com/Yonle/bostr"
);
@ -71,6 +72,19 @@ switch (argv[0]) {
process.env.BOSTR_CONFIG_PATH = readPath(argv[1]);
require("./index.js");
break;
case "testworker":
if (!argv[1]) return console.log("Usage: bostr testworker [conffile]");
if (!fs.existsSync(argv[1])) {
console.error("Config not exists.");
return process.exit(254);
}
process.env.BOSTR_CONFIG_PATH = readPath(argv[1]);
console.log("Press CTRL + C to stop the test.");
console.log("Using config:", process.env.BOSTR_CONFIG_PATH);
require("./testworker.js");
break;
case "hexconverter":
if (!argv[1]) return console.log("Usage: bostr hexconverter [npub|nsec|....] ....");
for (const i of argv.slice(1)) {

25
testworker.js Normal file
View File

@ -0,0 +1,25 @@
const { Worker } = require("worker_threads");
const worker = new Worker(__dirname + "/worker_bouncer.js", { name: "Bostr (worker)" });
let id = null;
worker.on('message', msg => {
console.log(msg);
if (!id && msg.id) {
id = msg.id;
worker.postMessage({
type: "req",
id,
sid: "testing",
filters: [{ kinds: [1] }]
});
}
});
worker.on("online", _ => {
worker.postMessage({
type: "getsess",
data: { ip: "[TestWorker]", ident: "TestWorker" }
})
});