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

89
Vistas
How do I test race conditions and concurrency using fast-check?

💬 Question and Help

I am developing a booking app and I want to use the fast-check library to simulate race conditions in my API. Basically, I want to simulate the use case where many users would call the same API to book the same table at the same time :

Suppose this is my API : POST /book with a request body like :


{
   "table": 1,
   "time": "20:00"
}

My koa API looks something like this:


router
    .post('/book', (ctx) => {
        const { table, time } = ctx.request.body;
        const { isBooked } = await checkIfAvailable(table,time).body; // calls MongoDB
        if(!isBooked){
            ctx.body = {
                table,
                time,
                booked: true
            };  
        } else {
            ctx.throw("This table is already booked", 404)
        }
        
    })


My test looks like this :


mockedCheckIfAvailable.mockImplementation(
    s.scheduleFunction(async (table,time) => {
        return  booking;
    }),
);

const  res  =  await  request
    .post('/book')
    .set('Content-Type', 'application/json')
    .set('Accept', 'application/json')
    .send(booking);
expect(res).toBe(true);

I read the Race Conditions docs but I can't get around how to apply it.

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