Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

88
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!