Skip to content

Commit

Permalink
Updates README and adds an example for volumeClaim testing usage (#151)
Browse files Browse the repository at this point in the history
* Feat: Add more information on how to use volumeClaim testing in the readme along with an example in config/samples

Signed-off-by: Sagar Vakkala <sagarwakawaka@gmail.com>

* fix: Review points

Signed-off-by: Sagar Vakkala <sagarwakawaka@gmail.com>

Signed-off-by: Sagar Vakkala <sagarwakawaka@gmail.com>
  • Loading branch information
ionicc authored Aug 31, 2022
1 parent 7799d98 commit 25e028e
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 2 deletions.
44 changes: 42 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,19 +41,59 @@ $ kubectl create configmap my-test --from-file /path/to/my/test.js

#### VolumeClaim

If you have a PVC with the name `stress-test` containing your script and any other supporting file(s), you can pass it to the test like this:
There is a sample avaiable in `config/samples/k6_v1alpha1_k6_with_volumeClaim.yaml` on how to configure to run a test script with a volumeClaim.

If you have a PVC with the name `stress-test-volumeClaim` containing your script and any other supporting file(s), you can pass it to the test like this:

```
spec:
parallelism: 2
script:
volumeClaim:
name: "stress-test"
name: "stress-test-volumeClaim"
file: "test.js"
```

***Note:*** the pods will expect to find script files in `/test/` folder. If `volumeClaim` fails, it's the first place to check: the latest initializer pod does not generate any logs and when it can't find the file, it will terminate with error. So missing file may not be that obvious and it makes sense to check it manually. See #143 for potential improvements.

##### Example directory structure while using volumeClaim

```
├── test
│ ├── requests
│ │ ├── stress-test.js
│ ├── test.js
```
In the above example, `test.js` imports a function from `stress-test.js` and they would look like this:
```js
// stress-test.js
import stress-test from "./requests/stress-test.js";

export let options = {
vus: 50,
duration: '10s'
};

export default function () {
stress-test();
}
```
```js
// stress-test.js
import { sleep, check } from 'k6';
import http from 'k6/http';


export default () => {
const res = http.get('https://test-api.k6.io');
check(res, {
'status is 200': () => res.status === 200,
});
sleep(1);
};

```

#### LocalFile

There is a sample avaiable in `config/samples/k6_v1alpha1_k6_with_localfile.yaml` on how to configure to run a test script inside the docker image.
Expand Down
14 changes: 14 additions & 0 deletions config/samples/k6_v1alpha1_k6_with_volumeClaim.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
apiVersion: k6.io/v1alpha1
kind: K6
metadata:
name: k6-sample
namespace: load-test
spec:
parallelism: 4
script:
volumeClaim:
name: stress-test-volumeClaim
# test.js should exist inside /test/ folder.
# And, All the js files and directories test.js
# is importing from should be inside the same directory as well.
file: test.js

0 comments on commit 25e028e

Please sign in to comment.