---
title: "Fault injection"
slug: "fault-injection"
abstract: "How to use the Sitecore.Commerce.Plugin.FaultInjection plugin to test failure in a complex distributed solution."
---
# Fault injection

Fault injection provides the ability to deliberately cause a service to fail, in order to test failure in a complex distributed solution. Sitecore XC has a single fault injection pattern, which covers the concurrency fault in the persistence of a Commerce Entity.

The `Sitecore.Commerce.Plugin.FaultInjection` plugin is included in the sample Commerce Engine project provided in the `Sitecore.Commerce.Engine.SDK` package.

> [!important]
> The `Sitecore.Commerce.Plugin.FaultInjection` plugin included in the sample Commerce Engine project is intended for use only in development or test environments. In the `Sitecore.Commerce.Engine.SDK`, the path to the Commerce Engine project is: `Sitecore.Commerce.Engine.SDK.*.*.**\src\Sitecore.Commerce.Engine\Sitecore.Commerce.Engine.csproj.`
>
> You must remove the sample `Sitecore.Commerce.Plugin.FaultInjection` plugin from your custom solution before deploying to production.

To inject the defined concurrency fault:

1. Ensure that your `Sitecore.Commerce.Engine` project contains a reference to the `Sitecore.Commerce.Plugin.FaultInjection`.
2. In the API request, add a header named `FaultInjection`.
3. Assign the value `ConcurrencyFault` to the header you added in the previous step.
4. Invoke any API methods that persists a Commerce Entity.

At this point, you should have a concurrency fault raised.

The following is a sample result from calling the `AddCartLine` using Postman with the fault injection header inserted:

Headers raw view:

`Content-Type:application/json `

`ShopName:{{ShopName}} `

`ShopperId:{{ShopperId}} `

`Language:{{Language}} `

`Currency:{{Currency}} `

`Environment:{{Environment}} `

`IpAddress:{{IpAddress}} `

`CustomerId:{{CustomerId}} `

`Roles:{{Roles}} `

`FaultInjection:ConcurencyFault`

In Postman, the response body shows the following:

```csharp
"ResponseCode": "Error",
 "Messages": [
 { 
  "MessageDate": "2016-09-01T12:`12:45`.0287079-`05:00`",
  "Code": "Error" 
  "Text": "SQL.UpdateEntity.Fail:Id=Cart01|Try=1|Environment=Entity-CommerceEnvironment-
   AdventureWorks|Message='Concurrency error: The Entity version supplied (1) is lower or equal to the current version
  (1).'|Number=50000|Procedure='sp_CommerceEntitiesUpdate'|Line=22", 
"CommerceTermKey": "EntityPersistException"
 }

```