Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

283
Vistas
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 la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda