Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

284
Visualizações
socket.setInterval no se repite en la prueba websocket k6

Estoy tratando de probar un websocket en k6 y socket.setInterval no se repite. Observe cómo imprimo "principal" en cada bucle. El servidor que estoy usando ha sido probado y no tiene ningún problema. El hecho de que Socket.setInterval simplemente deje de hacer un bucle es lo que está causando el problema.

 import http from 'k6/http'; import { randomString, randomIntBetween } from 'https://jslib.k6.io/k6-utils/1.1.0/index.js'; import { sleep } from 'k6'; import ws from 'k6/ws'; function getRandomInt(max) { return Math.floor(Math.random() * max); } export default function () { const res = ws.connect('ws://localhost:8000/ws', null, function (socket) { socket.on('open', function open() { console.log("connected"); socket.setInterval(function timeout() { console.log("principal") var rand_msg = getRandomInt(100); // 5 percent change of subscribing to a new channel if (0 <= rand_msg && rand_msg <= 4 ) { console.log("sub") let rand_channel = getRandomInt(10000) socket.send("#b "+ rand_channel.toString()) } //95 percent change of writing a new message else if ( 5 <= rand_msg && rand_msg <= 99) { console.log("msg") let rand_channel = getRandomInt(10000) let rand_msg_lenght = getRandomInt(100) //20 percent change of a large message betweem 5 Mb and 500Mb if (0 <= rand_msg_lenght && rand_msg_lenght <= 19) { let msg_lenght = randomIntBetween(1024*1000*5, 1024*1000*500) socket.send("s "+rand_channel.toString()+" "+randomString(msg_lenght)) } //80 percent change of a message between 20b and 200b else if (20 <= rand_msg_lenght && rand_msg_lenght <= 99) { let msg_lenght = randomIntBetween(20, 200) socket.send("s "+rand_channel.toString()+" "+randomString(msg_lenght)) } } }, randomIntBetween(200, 1000)); socket.on('message', function (message) { console.log("new message: \n"+ message) }); socket.on('close', function () { console.log("disconnected"); }); socket.setTimeout(function () { console.log(`Closing the socket`); socket.close(); }, 1000*600); }); }) }

Esta es mi terminal.

ingrese la descripción de la imagen aquí

Imprimió algunos mensajes y luego se detuvo.

about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda