Skip to content

Commit 54ff69e

Browse files
committed
test(load): add K6 load test workflow with example test
This commit adds a GitHub Actions workflow (you have to *manually* trigger it) that uses the K6 load testing utillity to run tests on a given environment. I had to add the `K6_API_TOKEN` secret to GitHub to allow running the tests in K6's cloud (VSF has a paid plan). You can also run the test on GitHub's agent though. M2-899 fix: use js, not ts file chore: partially revert #1107 This reverts commit 9b8de85. This change was made because K6 recorded tests are gigantic when customQuery sends the GraphQL AST in the request body. After this change, this the request is sent in string form, but is converted into GraphQL AST on the middleware side (because Apollo GraphQL client expects AST (DocumentNode TS type), not string) test(load): improve gql requests refactor: fix newlines
1 parent 79c87ce commit 54ff69e

File tree

17 files changed

+438
-44
lines changed

17 files changed

+438
-44
lines changed

.eslintrc.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ module.exports = {
3030
'@vue-storefront/eslint-config-vue',
3131
'@vue-storefront/eslint-config-jest',
3232
],
33+
globals: {
34+
"__ENV": "readonly",
35+
},
3336
rules: {
3437
"@typescript-eslint/no-floating-promises": "off",
3538
"jest/expect-expect": [
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
name: Run K6 test file
2+
on:
3+
workflow_dispatch:
4+
inputs:
5+
cloud:
6+
description: True = run in K6 cloud; False = run on the test on GitHub Actions agent
7+
required: true
8+
default: false
9+
type: boolean
10+
11+
filename:
12+
description: The K6 test file to run relative to repository root
13+
required: true
14+
default: packages/theme/tests/load/searchProduct.js
15+
type: string
16+
17+
environment:
18+
description: The full URL of the environment on which load tests will be ran
19+
required: true
20+
default: https://demo-magento2-canary.europe-west1.gcp.storefrontcloud.io
21+
type: choice
22+
options:
23+
- https://demo-magento2-canary.europe-west1.gcp.storefrontcloud.io
24+
- https://demo-magento2-dev.europe-west1.gcp.storefrontcloud.io
25+
- https://demo-magento2.europe-west1.gcp.storefrontcloud.cloud
26+
- https://demo-magento2-enterprise.europe-west1.gcp.storefrontcloud.io
27+
28+
flags:
29+
description: Additional argument and flags to provide to the k6 CLI. See https://k6.io/docs/using-k6/options for details.
30+
required: false
31+
default: ''
32+
type: string
33+
34+
jobs:
35+
build:
36+
name: Run k6 cloud test
37+
runs-on: ubuntu-latest
38+
environment: test
39+
40+
steps:
41+
- name: Checkout
42+
uses: actions/checkout@v3
43+
44+
- name: Run k6 cloud test
45+
uses: grafana/[email protected]
46+
with:
47+
cloud: ${{ inputs.cloud }}
48+
token: ${{ secrets.K6_CLOUD_API_TOKEN }}
49+
filename: ${{ inputs.filename }}
50+
flags: ${{ inputs.flags }}
51+
env:
52+
BASE_URL: ${{ inputs.environment }}

packages/api-client/src/api/customMutation/index.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1+
import gql from 'graphql-tag';
12
import { FetchPolicy, FetchResult } from '@apollo/client/core';
2-
import { DocumentNode } from 'graphql';
33
import { Context } from '../../types/context';
44
import getHeaders from '../getHeaders';
55

@@ -10,12 +10,12 @@ export default async <MUTATION = any, MUTATION_VARIABLES = any>(
1010
mutationVariables,
1111
fetchPolicy,
1212
}: {
13-
mutation: DocumentNode,
13+
mutation: string,
1414
mutationVariables: MUTATION_VARIABLES,
1515
fetchPolicy?: Extract<FetchPolicy, 'network-only' | 'no-cache'>,
1616
},
1717
): Promise<FetchResult<MUTATION>> => context.client.mutate<MUTATION, MUTATION_VARIABLES>({
18-
mutation,
18+
mutation: gql`${mutation}`,
1919
variables: { ...mutationVariables },
2020
fetchPolicy: fetchPolicy || 'no-cache',
2121
context: {

packages/api-client/src/api/customQuery/index.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1+
import gql from 'graphql-tag';
12
import { ApolloQueryResult, FetchPolicy } from '@apollo/client/core';
2-
import { DocumentNode } from 'graphql';
33
import { Context } from '../../types/context';
44
import getHeaders from '../getHeaders';
55

@@ -10,12 +10,12 @@ export default async <QUERY = any, QUERY_VARIABLES = any>(
1010
queryVariables,
1111
fetchPolicy,
1212
}: {
13-
query: DocumentNode,
13+
query: string,
1414
queryVariables?: QUERY_VARIABLES,
1515
fetchPolicy?: FetchPolicy,
1616
},
1717
): Promise<ApolloQueryResult<QUERY>> => context.client.query<QUERY, QUERY_VARIABLES>({
18-
query,
18+
query: gql`${query}`,
1919
variables: { ...queryVariables },
2020
fetchPolicy: fetchPolicy || 'no-cache',
2121
context: {

packages/api-client/src/types/API.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { ApolloQueryResult, FetchPolicy, FetchResult } from '@apollo/client/core';
2-
import { DocumentNode, ExecutionResult } from 'graphql';
2+
import { ExecutionResult } from 'graphql';
33
import { CustomQuery } from '@vue-storefront/core';
44
import {
55
AddConfigurableProductsToCartInput,
@@ -278,13 +278,13 @@ export interface MagentoApiMethods {
278278
): Promise<ApolloQueryResult<CustomerOrdersQuery>>;
279279

280280
customQuery<QUERY, QUERY_VARIABLES = any>(params: {
281-
query: DocumentNode,
281+
query: string,
282282
queryVariables?: QUERY_VARIABLES,
283283
fetchPolicy?: FetchPolicy,
284284
}): Promise<ApolloQueryResult<QUERY>>;
285285

286286
customMutation<MUTATION, MUTATION_VARIABLES = any>(params: {
287-
mutation: DocumentNode,
287+
mutation: string,
288288
mutationVariables: MUTATION_VARIABLES,
289289
fetchPolicy?: Extract<FetchPolicy, 'network-only' | 'no-cache'>,
290290
}): Promise<FetchResult<MUTATION>>;

packages/theme/components/TopBar/checkStoresAndCurrency.gql.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
import gql from 'graphql-tag';
2-
3-
export default gql`
1+
export default `
42
query getStoresAndCurrencies {
53
availableStores {
64
store_code

packages/theme/composables/useApi/index.ts

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { useContext } from '@nuxtjs/composition-api';
2-
import type { DocumentNode } from 'graphql';
32
import { Logger } from '~/helpers/logger';
43

54
export type FetchPolicy = 'cache-first' | 'network-only' | 'cache-only' | 'no-cache' | 'standby';
@@ -19,7 +18,7 @@ export type Error = {
1918
};
2019

2120
export type Request = <DATA, VARIABLES extends Variables = Variables>(
22-
request: DocumentNode,
21+
request: string,
2322
variables?: VARIABLES,
2423
fetchPolicy?: FetchPolicy,
2524
) => Promise<{ data: DATA, errors: Error[] }>;
@@ -75,10 +74,6 @@ export interface UseApiInterface {
7574
mutate: Request;
7675
}
7776

78-
function getGqlString(doc: DocumentNode) {
79-
return doc.loc && doc.loc.source.body;
80-
}
81-
8277
/**
8378
* Allows executing arbitrary GraphQL queries and mutations.
8479
*
@@ -93,7 +88,7 @@ export function useApi(): UseApiInterface {
9388
variables,
9489
) => {
9590
const reqID = `id${Math.random().toString(16).slice(2)}`;
96-
Logger.debug(`customQuery/request/${reqID}`, getGqlString(request));
91+
Logger.debug(`customQuery/request/${reqID}`, request);
9792
const { data, errors } = await context.app.$vsf.$magento.api.customQuery({ query: request, queryVariables: variables });
9893
Logger.debug(`customQuery/result/${reqID}`, { data, errors });
9994

@@ -106,7 +101,7 @@ export function useApi(): UseApiInterface {
106101
variables,
107102
) => {
108103
const reqID = `id${Math.random().toString(16).slice(2)}`;
109-
Logger.debug(`customQuery/request/${reqID}`, getGqlString(request));
104+
Logger.debug(`customQuery/request/${reqID}`, request);
110105
const { data, errors } = await context.app.$vsf.$magento.api.customMutation({ mutation: request, mutationVariables: variables });
111106
Logger.debug(`customQuery/result/${reqID}`, { data, errors });
112107

packages/theme/modules/catalog/category/components/cms/categoryContent.gql.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
import gql from 'graphql-tag';
2-
3-
export default gql`
1+
export default `
42
query getCategoryContentData($filters: CategoryFilterInput) {
53
categoryList(filters: $filters) {
64
uid

packages/theme/modules/catalog/category/components/filters/command/getProductFilterByCategory.gql.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
import gql from 'graphql-tag';
2-
3-
export default gql`
1+
export default `
42
query getProductFiltersByCategory($categoryIdFilter: FilterEqualTypeInput!) {
53
products(filter: { category_uid: $categoryIdFilter }) {
64
aggregations {

packages/theme/modules/catalog/category/composables/useFacet/getFacetData.gql.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
1-
import gql from 'graphql-tag';
2-
31
/**
42
* GraphQL Query that fetches products using received search term and the params
53
* for filter, sort and pagination.
64
*/
7-
export default gql`
5+
export default `
86
query getFacetData($search: String = "", $filter: ProductAttributeFilterInput, $pageSize: Int = 10, $currentPage: Int = 1, $sort: ProductAttributeSortInput) {
97
products(search: $search, filter: $filter, pageSize: $pageSize, currentPage: $currentPage, sort: $sort) {
108
items {

0 commit comments

Comments
 (0)