-
-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6917cbd
commit 61fc6c7
Showing
5 changed files
with
64 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 10 additions & 5 deletions
15
packages/dev-server/load-testing/graphql/shop/add-to-order.graphql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,18 @@ | ||
mutation ($id: ID! $qty: Int!) { | ||
addItemToOrder(productVariantId: $id quantity: $qty) { | ||
id | ||
code | ||
lines { | ||
...on Order { | ||
id | ||
quantity | ||
productVariant { | ||
code | ||
lines { | ||
id | ||
quantity | ||
productVariant { | ||
id | ||
} | ||
} | ||
} | ||
...on ErrorResult { | ||
errorCode | ||
} | ||
} | ||
} |
14 changes: 10 additions & 4 deletions
14
packages/dev-server/load-testing/graphql/shop/complete-order.graphql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,21 @@ | ||
mutation SetShippingMethod($id: ID!) { | ||
setOrderShippingMethod(shippingMethodId: $id) { | ||
code | ||
...on Order { | ||
code | ||
} | ||
} | ||
transitionOrderToState(state: "ArrangingPayment") { | ||
code | ||
...on Order { | ||
code | ||
} | ||
} | ||
addPaymentToOrder(input: { | ||
method: "example-payment-provider", | ||
metadata: {} | ||
}) { | ||
code | ||
state | ||
...on Order { | ||
code | ||
state | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
packages/dev-server/load-testing/scripts/very-large-order2.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
// @ts-check | ||
import { check } from 'k6'; | ||
import { ShopApiRequest } from '../utils/api-request.js'; | ||
|
||
const searchQuery = new ShopApiRequest('shop/search.graphql'); | ||
const addItemToOrderMutation = new ShopApiRequest('shop/add-to-order.graphql'); | ||
|
||
export let options = { | ||
stages: [{ duration: '1m', target: 1 }], | ||
}; | ||
|
||
export function setup() { | ||
const searchResult = searchQuery.post(); | ||
const items = searchResult.data.search.items; | ||
return items; | ||
} | ||
|
||
/** | ||
* Continuously adds random items to a single order for the duration of the test. | ||
* Just like very-large-order.js but adds hundreds of items each time, and runs for only 1 minute | ||
*/ | ||
export default function (products) { | ||
for (let i = 0; i < 10000; i++) { | ||
addToCart(randomItem(products).productVariantId); | ||
} | ||
} | ||
|
||
function addToCart(variantId) { | ||
const qty = Math.ceil(Math.random() * 500); | ||
const result = addItemToOrderMutation.post({ id: variantId, qty }); | ||
check(result.data, { | ||
'Product added to cart': r => | ||
!!r.addItemToOrder.lines.find(l => l.productVariant.id === variantId && l.quantity >= qty), | ||
}); | ||
} | ||
|
||
function randomItem(items) { | ||
return items[Math.floor(Math.random() * items.length)]; | ||
} |