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

Experimental/fs read all #3229

Closed
wants to merge 11 commits into from

Conversation

oleiade
Copy link
Member

@oleiade oleiade commented Jul 26, 2023

What?

This Pull Request adds a readAll method to the k6/experimental/fs module's File object, as per #3147.

⚠️ This PR is based on the experimental/fs-read branch.

It enables users to read the whole content of a file in one go, in an asynchronous manner. The method returns a promise which resolves to an ArrayBuffer holding the file data.

import http from "k6/http";
import { open } from "k6/experimental/fs";

export const options = {
	vus: 1,
	iterations: 1,
};

// As k6 does not support asynchronous code in the init context, yet, we need to
// use a top-level async function to be able to use the `await` keyword.
let file;
(async function () {
	file = await open("bonjour.txt");
})();

export default async function () {
	// Obtain information about the file.
	const fileinfo = await file.stat();
	if (fileinfo.name != "bonjour.txt") {
		throw new Error("Unexpected file name");
	}

	let res = http.post(
		"https://httpbin.test.k6.io/post",
		await file.readAll(),
		{
			headers: { "Content-Type": "text/plain" },
		}
	);

	console.log(res.body);
}

Checklist

  • I have performed a self-review of my code.
  • I have added tests for my changes.
  • I have run linter locally (make ci-like-lint) and all checks pass.
  • I have run tests locally (make tests) and all tests pass.
  • I have commented on my code, particularly in hard-to-understand areas.

Related PR(s)/Issue(s)

ref #3219
closes #3147

@oleiade oleiade added this to the v0.47.0 milestone Jul 26, 2023
@oleiade oleiade self-assigned this Jul 26, 2023
@oleiade oleiade marked this pull request as draft July 26, 2023 08:08
@github-actions github-actions bot requested review from codebien and imiric July 26, 2023 08:08
@oleiade oleiade changed the base branch from experimental/fs-read to experimental/fs-readseek August 29, 2023 14:19
@codecov-commenter
Copy link

Codecov Report

❗ No coverage uploaded for pull request base (experimental/fs-readseek@15c8dce). Click here to learn what that means.
The diff coverage is n/a.

❗ Current head a70fd93 differs from pull request most recent head c6975ea. Consider uploading reports for the commit c6975ea to get more accurate results

@@                     Coverage Diff                     @@
##             experimental/fs-readseek    #3229   +/-   ##
===========================================================
  Coverage                            ?   73.14%           
===========================================================
  Files                               ?      261           
  Lines                               ?    20072           
  Branches                            ?        0           
===========================================================
  Hits                                ?    14681           
  Misses                              ?     4451           
  Partials                            ?      940           
Flag Coverage Δ
ubuntu 73.14% <0.00%> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

@oleiade oleiade force-pushed the experimental/fs-readseek branch 4 times, most recently from 6d8dbb3 to 28ee0ef Compare September 27, 2023 09:06
@oleiade oleiade modified the milestones: v0.47.0, v0.48.0 Sep 27, 2023
@oleiade oleiade closed this Sep 28, 2023
@oleiade oleiade deleted the experimental/fs-readAll branch October 26, 2023 11:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants