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

Make the library asynchronous and compatible with the async/await syntax #41

Closed
8 tasks done
oleiade opened this issue Apr 25, 2023 · 3 comments
Closed
8 tasks done
Assignees
Labels
enhancement New feature or request epic

Comments

@oleiade
Copy link
Member

oleiade commented Apr 25, 2023

Recently, k6 has received support for the async/await syntax. Considering that this javascript library is currently blocking and offers functionalities to users which would benefit from being asynchronous, we should consider making its APIs asynchronous indeed.

This would benefit the users as it would allow to avoid blocking the execution of their scripts over heavy operations such as downloading a file from S3. It would also benefit the overall performance of the scripts relying on AWS operations as it would allow the runtime to offload certain costly operations such as cryptographic signature.

The target API should lead to the following kind of code:

export default async function () {
    // List the buckets the AWS authentication configuration
    // gives us access to.
    const buckets = await s3.listBuckets()

    // If our test bucket does not exist, abort the execution.
    if (buckets.filter((b) => b.name === testBucketName).length == 0) {
        exec.test.abort()
    }

    // Let's upload our test file to the bucket
    await s3.putObject(testBucketName, testFileKey, testFile)

    // Let's list the test bucket objects
    const objects = await s3.listObjects(testBucketName)

    // And verify it does contain our test object
    if (objects.filter((o) => o.key === testFileKey).length == 0) {
        exec.test.abort()
    }

    // Let's redownload it verify it's correct, and delete it
    const obj = await s3.getObject(testBucketName, testFileKey)
    s3.deleteObject(testBucketName, testFileKey)
}

Tasks

@oleiade
Copy link
Member Author

oleiade commented May 8, 2023

After running some experiments, it turns out that making the library itself async would be relatively trivial. However, the k6chaijs library doesn't seem to support the expect.to.eventually subset of features. We therefore have a dependency on it, and can't reliably implement support async/await until we get this feature set in k6chaijs.

@mstoykov
Copy link
Contributor

mstoykov commented May 9, 2023

It might be better to just not use k6chaijs for tests if expect.to.eventually turns out to be too complicated to implement.

@oleiade
Copy link
Member Author

oleiade commented May 9, 2023

That's fair 👍🏻

I think I'll probably timebox a session trying to integrate the expect.to.eventually syntax to k6chaijs one of these days, and if I don't make enough progress will indeed "just" test the async behaviors without it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request epic
Projects
None yet
Development

No branches or pull requests

2 participants