telegram-test-api icon indicating copy to clipboard operation
telegram-test-api copied to clipboard

Support for multiple clients needed

Open olifur opened this issue 3 years ago • 0 comments

Hi devs,

I want to stress test my bot which has functionality to store the client's userId in a database. Therefore I try to create multiple clients (each with their own unique userid) in a loop which does not work, all additional (n+1) clients run into timeout errors TimeoutError: did not get new updates in 10000 ms

Is the client implemented as singleton? Also if I manipulate the userId field in the client directly it times out.


const testUsers = [
    {
        userid: 1,
        username: "horst",
    },
    {
        userid: 2,
        username: "charly",
    },
    {
        userid: 3,
        username: "egon",
    },
   [...]
]


for (const entry of testUsers) {
        const newClient = server.getClient(token, { userId: entry.userid , username: entry.username, timeout: 10000 });
        const command = newClient.makeCommand('/start');
        const res = await newClient.sendCommand(command);
        let updates = await newClient.getUpdates();
        [...]

}

also what is producing same negative result (timeout)


let index = 0
for (const entry of testUsers) {
        const newClient = server.getClient(token, { username: entry.username, timeout: 10000 });
        const command = newClient.makeCommand('/start');
        const res = await newClient.sendCommand(command);
        // tweaking userId directly in the command to be sent
        command.from.id = entry.userid
        let updates = await newClient.getUpdates();
        [...]

}

whereas what works but is always the same client (and I need to process different userIds in my bot)


for (const entry of testUsers) {
        const newClient = server.getClient(token, { userId: 1, username: entry.username, timeout: 10000 });
        const command = newClient.makeCommand('/start');
        const res = await newClient.sendCommand(command);
        let updates = await newClient.getUpdates();
        [...]
}

error is


 TimeoutError: did not get new updates in 10000 
      at Timeout._onTimeout (../telegram-test-api/node_modules/p-timeout/index.js:39:64)

Thank you for your help! Oliver

olifur avatar Jan 04 '22 07:01 olifur