Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sync APIs #7

Closed
ppcano opened this issue Jul 15, 2022 · 1 comment
Closed

Sync APIs #7

ppcano opened this issue Jul 15, 2022 · 1 comment

Comments

@ppcano
Copy link

ppcano commented Jul 15, 2022

#4 brought async support to most of the xk6-redis APIs. Currently, await is not currently supported, so there is no way to interact with Redis synchronously for most APIs.

// await is not supported
const counter = await redisClient.get('my_counter');
if (counter > 10) { 
   // do something in VU code
}

I discussed this briefly with @mstoykov and @sniku. It seems that async APIs does not allow using using Redis for some particular cases.

The main reason is that Promise handlers are always executed after the VU code. Let's show one example:

export default function () {

    CONSOLE.log(`before async ${exec.vu.idInTest}`);
    
    redisClient.incr('my_key').then((total) => { 
          // this will only be executed when the VUs code finalizes
	   CONSOLE.log(`promise callback ${exec.vu.idInTest}`);
    });
    sleep(Math.random() * 5);
    CONSOLE.log(`exit VU code ${exec.vu.idInTest}`);
}

In this case, the execution will always be in this order:

before async 1                             
exit VU code 1                                
promise callback 1         

With async APIs, the result of a promise cannot change the VU execution code (outside the promise handler). Users could not do something like:

let localCounter = 0;
redisClient.get('my_counter').then((counter) => { 
     localCounter = counter;
});

while (localCounter === 0) {
   // VU will be blocked in this loop.
}

This issue requests to provide "sync" support for Redis APIs to not limit the potential of using Redis in k6 tests. For example, to share data across VUs in your load test.

cc @oleiade

@oleiade
Copy link
Member

oleiade commented Jul 19, 2022

Unless I'm mistaken, this is a duplicate of #4. Closing.

Please don't hesitate to reopen if I was wrong 👍🏻

@oleiade oleiade closed this as completed Jul 19, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants