Skip to content

Commit

Permalink
blog(testing otel demo): format edits
Browse files Browse the repository at this point in the history
  • Loading branch information
adnanrahic authored and chalin committed Jul 27, 2023
1 parent 57cef74 commit 78cc834
Showing 1 changed file with 55 additions and 51 deletions.
106 changes: 55 additions & 51 deletions content/en/blog/2023/testing-otel-demo/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,8 @@ greater confidence.

Trace-based testing is a type of testing that validates a system's behavior by
triggering an operation against the system and validating its result by checking
the system output with the emitted
[traces](/docs/concepts/signals/traces/) generated by the system during
this call.
the system output with the emitted [traces](/docs/concepts/signals/traces/)
generated by the system during this call.

This term was popularized by Ted Young in the talk
[Trace Driven Development: Unifying Testing and Observability](https://www.youtube.com/watch?v=NU-fTr-udZg)
Expand Down Expand Up @@ -113,8 +112,8 @@ spec:
trigger:
type: grpc
grpc:
protobufFile: {{protobuf file with CurrencyService definition}}
address: {{currency service address}}
protobufFile: {{ protobuf file with CurrencyService definition }}
address: {{ currency service address }}
method: oteldemo.CurrencyService.Convert
request: |-
{
Expand All @@ -126,16 +125,17 @@ spec:
"toCode": "CAD"
}
specs:
- name: It converts from USD to CAD
selector: span[name="CurrencyService/Convert" rpc.system="grpc"
rpc.method="Convert" rpc.service="CurrencyService"]
assertions:
- attr:app.currency.conversion.from = "USD"
- attr:app.currency.conversion.to = "CAD"
- name: It has more nanos than expected
selector: span[name="Test trigger"]
assertions:
- attr:response.body | json_path '$.nanos' >= 599380800
- name: It converts from USD to CAD
selector:
span[name="CurrencyService/Convert" rpc.system="grpc"
rpc.method="Convert" rpc.service="CurrencyService"]
assertions:
- attr:app.currency.conversion.from = "USD"
- attr:app.currency.conversion.to = "CAD"
- name: It has more nanos than expected
selector: span[name="Test trigger"]
assertions:
- attr:response.body | json_path '$.nanos' >= 599380800
```
In the `trigger` section, we define which operation to trigger. In this case, a
Expand All @@ -148,9 +148,9 @@ the trace and the operation result.
We can see two types of assertions:

- The first assertion is against a trace
[span](/docs/concepts/signals/traces/#spans) that the
`CurrencyService` emitted. It checks if the service received a conversion
operation from USD to CAD by checking if the
[span](/docs/concepts/signals/traces/#spans) that the `CurrencyService`
emitted. It checks if the service received a conversion operation from USD to
CAD by checking if the
[span attributes](/docs/concepts/signals/traces/#attributes)
`app.currency.conversion.from` and `app.currency.conversion.to` have correct
values;
Expand All @@ -164,8 +164,8 @@ The end-to-end tests are based on front-end tests using
[Cypress](https://www.cypress.io/). We call the services through the API used by
the front end and check if the service interaction between them is correct. We
also verify if a trace is
[propagated](/docs/concepts/signals/traces/#context-propagation)
correctly through the services.
[propagated](/docs/concepts/signals/traces/#context-propagation) correctly
through the services.

For these tests, we considered a scenario based on the main use case of the
demo: “_a user buying a product_” executed against the
Expand All @@ -191,7 +191,7 @@ type: Transaction
spec:
name: 'Frontend Service'
description: Run all Frontend tests enabled in sequence,
simulating a process of a user purchasing products on the Astronomy store
simulating a process of a user purchasing products on the Astronomy store
steps:
- ./01-see-ads.yaml
- ./02-get-product-recommendation.yaml
Expand Down Expand Up @@ -250,8 +250,8 @@ spec:
url: http://{{frontend address}}/api/checkout
method: POST
headers:
- key: Content-Type
value: application/json
- key: Content-Type
value: application/json
body: |
{
"userId": "2491f868-88f1-4345-8836-d5d8511a9f83",
Expand All @@ -272,34 +272,38 @@ spec:
}
}
specs:
- name: "The frontend has been called with success"
selector: span[name="Test trigger"]
assertions:
- attr:response.status = 200
- selector: span[name="oteldemo.CheckoutService/PlaceOrder" rpc.system="grpc"
rpc.method="PlaceOrder" rpc.service="oteldemo.CheckoutService"]
name: "The order was placed"
assertions:
- attr:app.user.id = "2491f868-88f1-4345-8836-d5d8511a9f83"
- attr:app.order.items.count = 1
- selector: span[name="oteldemo.PaymentService/Charge" rpc.system="grpc"
rpc.method="Charge" rpc.service="oteldemo.PaymentService"]
name: "The user was charged"
assertions:
- attr:rpc.grpc.status_code = 0
- attr:selected_spans.count >= 1
- selector: span[name="oteldemo.ShippingService/ShipOrder" rpc.system="grpc"
rpc.method="ShipOrder" rpc.service="oteldemo.ShippingService"]
name: "The product was shipped"
assertions:
- attr:rpc.grpc.status_code = 0
- attr:selected_spans.count >= 1
- selector: span[name="oteldemo.CartService/EmptyCart" rpc.system="grpc"
rpc.method="EmptyCart" rpc.service="oteldemo.CartService"]
name: "The cart was emptied"
assertions:
- attr:rpc.grpc.status_code = 0
- attr:selected_spans.count >= 1
- name: 'The frontend has been called with success'
selector: span[name="Test trigger"]
assertions:
- attr:response.status = 200
- selector:
span[name="oteldemo.CheckoutService/PlaceOrder" rpc.system="grpc"
rpc.method="PlaceOrder" rpc.service="oteldemo.CheckoutService"]
name: 'The order was placed'
assertions:
- attr:app.user.id = "2491f868-88f1-4345-8836-d5d8511a9f83"
- attr:app.order.items.count = 1
- selector:
span[name="oteldemo.PaymentService/Charge" rpc.system="grpc"
rpc.method="Charge" rpc.service="oteldemo.PaymentService"]
name: 'The user was charged'
assertions:
- attr:rpc.grpc.status_code = 0
- attr:selected_spans.count >= 1
- selector:
span[name="oteldemo.ShippingService/ShipOrder" rpc.system="grpc"
rpc.method="ShipOrder" rpc.service="oteldemo.ShippingService"]
name: 'The product was shipped'
assertions:
- attr:rpc.grpc.status_code = 0
- attr:selected_spans.count >= 1
- selector:
span[name="oteldemo.CartService/EmptyCart" rpc.system="grpc"
rpc.method="EmptyCart" rpc.service="oteldemo.CartService"]
name: 'The cart was emptied'
assertions:
- attr:rpc.grpc.status_code = 0
- attr:selected_spans.count >= 1
```

Finally, when running these tests we have the following report, showing each
Expand Down

0 comments on commit 78cc834

Please sign in to comment.