Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(e2e): add kafka tests for on our internal tracetesting/dogfood tests #3089

Merged
merged 2 commits into from
Aug 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions testing/server-tracetesting/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ results/
config.yml
.env
tracetesting-env.yaml
tracetesting-vars.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
type: Test
spec:
id: dvsf860sdv
name: Create Kafka Test
description: Test step of 'Kafka Test Feature - Test Suite'
trigger:
type: http
httpRequest:
url: ${var:TARGET_URL}/api/tests
method: POST
headers:
- key: Content-Type
value: application/json
body: |
{
"type": "Test",
"spec": {
"name": "Import a Pokemon reading a Stream",
"trigger": {
"type": "kafka",
"kafka": {
"brokerUrls": ["${var:DEMO_APP_KAFKA_BROKER}"],
"topic": "pokemon",
"headers": [],
"messageKey": "snorlax-key",
"messageValue": "{\"id\": 143}"
}
},
"specs": [
{
"selector":"span[tracetest.span.type=\"messaging\" name=\"pokemon process\" messaging.system=\"kafka\" messaging.destination=\"pokemon\" messaging.destination_kind=\"topic\" messaging.operation=\"process\"]",
"assertions": ["attr:messaging.system = \"kafka\""],
"name": "A message was received from Kafka stream"
},
{
"selector":"span[tracetest.span.type=\"general\" name=\"import pokemon\"]",
"assertions": ["attr:name = \"import pokemon\""],
"name": "Import Pokemon use case was triggered"
}
]
}
}
specs:
- name: Tracetest API returned a valid HTTP code for test creation
selector: span[name = "Tracetest trigger"]
assertions:
- attr:tracetest.selected_spans.count = 1
- attr:tracetest.response.status = 201
- name: Tracetest API endpoint 'POST /api/tests' was called once
selector: span[name="POST /api/tests" tracetest.span.type="http"]
assertions:
- attr:tracetest.selected_spans.count = 1
- name: Just one test was added into the database
selector: span[name = "exec INSERT"]
assertions:
- attr:tracetest.selected_spans.count = 1
- name: The test was added on the correct database table
selector: span[name = "exec INSERT"]:first
assertions:
- attr:sql.query contains "INSERT INTO tests"
outputs:
- name: KAFKA_TEST_ID
selector: span[name = "Tracetest trigger"]
value: attr:tracetest.response.body | json_path '$.spec.id'
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
type: Test
spec:
id: jkbd86ads
name: List Kafka Test
description: Test step of 'Kafka Test Feature - Test Suite'
trigger:
type: http
httpRequest:
url: ${var:TARGET_URL}/api/tests
method: GET
headers:
- key: Content-Type
value: application/json
specs:
- name: Tracetest API listed the test last test created
selector: span[name = "Tracetest trigger"]
assertions:
- attr:tracetest.selected_spans.count = 1
- attr:tracetest.response.status = 200
- attr:tracetest.response.body | json_path '$.items[*].spec.id' contains var:KAFKA_TEST_ID # check if the test is listed
- name: Tracetest API endpoint 'GET /api/tests' was called once
selector: span[name="GET /api/tests" tracetest.span.type="http"]
assertions:
- attr:tracetest.selected_spans.count = 1
- name: Two queries were executed on the database, one for counting and another for listing
selector: span[name = "query SELECT"]
assertions:
- attr:tracetest.selected_spans.count = 2
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
type: Test
spec:
id: as8d7da8s6
name: Run Kafka Test
description: Test step of 'Kafka Test Feature - Test Suite'
trigger:
type: http
httpRequest:
url: ${var:TARGET_URL}/api/tests/${var:KAFKA_TEST_ID}/run
method: POST
headers:
- key: Content-Type
value: application/json
body: '{}'
specs:
- name: Tracetest API started to run the test correctly
selector: span[name = "Tracetest trigger"]
assertions:
- attr:tracetest.selected_spans.count = 1
- attr:tracetest.response.status = 200
- name: Tracetest API endpoint 'POST /api/tests/{testId}/run' was called once
selector: span[name = "POST /api/tests/{testId}/run" tracetest.span.type = "http"]
assertions:
- attr:tracetest.selected_spans.count = 1
- name: The test trigger was executed correctly
selector: span[name = "Trigger test"]
assertions:
- attr:tracetest.selected_spans.count = 1
- attr:tracetest.run.trigger.test_id = "${var:KAFKA_TEST_ID}"
- attr:tracetest.run.trigger.type = "kafka"
- name: The trace poller was started
selector: span[name = "Fetch trace"]
assertions:
- attr:tracetest.selected_spans.count > 0
- attr:tracetest.run.trace_poller.test_id = "${var:KAFKA_TEST_ID}"
- name: The trace poller finished with success
selector: span[name = "Fetch trace"]:last
assertions:
- attr:tracetest.run.trace_poller.succesful = "true"
- name: All assertions were validated and passed
selector: span[name = "Execute assertions"]
assertions:
- attr:tracetest.selected_spans.count = 1
- attr:tracetest.run.assertion_runner.all_assertions_passed = "true"
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
---
type: Test
spec:
id: asd978dfg
name: Delete Kafka Test
description: Test step of 'Kafka Test Feature - Test Suite'
trigger:
type: http
httpRequest:
url: ${var:TARGET_URL}/api/tests/${var:KAFKA_TEST_ID}
method: DELETE
headers:
- key: Content-Type
value: application/json
specs:
- name: Tracetest API deleted the test last test created
selector: span[name = "Tracetest trigger"]
assertions:
- attr:tracetest.selected_spans.count = 1
- attr:tracetest.response.status = 204
- name: Tracetest API endpoint 'DELETE /api/tests/{id}' was called once
selector: span[name="DELETE /api/tests/{id}" tracetest.span.type="http"]
assertions:
- attr:tracetest.selected_spans.count = 1
- name: All test entities were deleted
selector: span[name = "exec DELETE"]
assertions:
# must delete test and runs. That's why we need 2 deletes
- attr:tracetest.selected_spans.count = 4
14 changes: 14 additions & 0 deletions testing/server-tracetesting/features/kafka_test/_test_suite.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
type: TestSuite
spec:
id: kajwb6asd
name: Kafka Test Feature
description: Sequence of tests to validate if our Kafka Test feature is working as expected
steps:
# create a Kafka Test
- ./01_create_kafka_test.yml
# check if this test is listed on API
- ./02_list_kafka_test.yml
# run test
- ./03_run_kafka_test.yml
# delete test
- ./04_delete_kafka_test.yml
30 changes: 17 additions & 13 deletions testing/server-tracetesting/run.bash
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ fi
export TRACETEST_ENDPOINT=${TRACETEST_ENDPOINT:-"localhost:11633"}
export DEMO_APP_URL=${DEMO_APP_URL-"http://demo-pokemon-api.demo"}
export DEMO_APP_GRPC_URL=${DEMO_APP_GRPC_URL-"demo-pokemon-api.demo:8082"}
export DEMO_APP_KAFKA_BROKER=${DEMO_APP_KAFKA_BROKER-"stream:9092"}

# TODO: think how to move this id generation to HTTP Test suite
export EXAMPLE_TEST_ID="w2ON-RVVg"
Expand All @@ -24,30 +25,33 @@ echo "Preparing to run tests on API..."
echo ""

echo "Variable set considered on this run:"
echo "TRACETEST_CLI: $TRACETEST_CLI"
echo "TARGET_URL: $TARGET_URL"
echo "TRACETEST_ENDPOINT: $TRACETEST_ENDPOINT"
echo "DEMO_APP_URL: $DEMO_APP_URL"
echo "DEMO_APP_GRPC_URL: $DEMO_APP_GRPC_URL"

cat << EOF > tracetesting-env.yaml
echo "TRACETEST_CLI: $TRACETEST_CLI"
echo "TARGET_URL: $TARGET_URL"
echo "TRACETEST_ENDPOINT: $TRACETEST_ENDPOINT"
echo "DEMO_APP_URL: $DEMO_APP_URL"
echo "DEMO_APP_GRPC_URL: $DEMO_APP_GRPC_URL"
echo "DEMO_APP_KAFKA_BROKER: $DEMO_APP_KAFKA_BROKER"

cat << EOF > tracetesting-vars.yaml
type: VariableSet
spec:
id: tracetesting-env
name: tracetesting-env
id: tracetesting-vars
name: tracetesting-vars
values:
- key: TARGET_URL
value: $TARGET_URL
- key: DEMO_APP_URL
value: $DEMO_APP_URL
- key: DEMO_APP_GRPC_URL
value: $DEMO_APP_GRPC_URL
- key: DEMO_APP_KAFKA_BROKER
value: $DEMO_APP_KAFKA_BROKER
- key: EXAMPLE_TEST_ID
value: $EXAMPLE_TEST_ID
EOF

echo "variables set created:"
cat tracetesting-env.yaml
cat tracetesting-vars.yaml

echo "Setting up tracetest CLI configuration..."
cat << EOF > config.yml
Expand All @@ -65,10 +69,9 @@ mkdir -p results/responses
run_test_suite_for_feature() {
feature=$1

# junit_output='results/'$feature'_test_suite.xml'
definition='./features/'$feature'/_test_suite.yml'

testCMD="$TRACETEST_CLI --config ./config.yml run testsuite --file $definition --vars ./tracetesting-env.yaml"
testCMD="$TRACETEST_CLI --config ./config.yml run testsuite --file $definition --vars ./tracetesting-vars.yaml"
echo $testCMD
$testCMD
return $?
Expand All @@ -84,13 +87,14 @@ EXIT_STATUS=0
# add more test suites here
run_test_suite_for_feature 'http_test' || EXIT_STATUS=$?
run_test_suite_for_feature 'grpc_test' || EXIT_STATUS=$?
run_test_suite_for_feature 'kafka_test' || EXIT_STATUS=$?
run_test_suite_for_feature 'variableset' || EXIT_STATUS=$?
run_test_suite_for_feature 'testsuite' || EXIT_STATUS=$?

echo ""
echo "Tests done! Exit code: $EXIT_STATUS"

rm tracetesting-env.yaml
rm tracetesting-vars.yaml

exit $EXIT_STATUS