Skip to content

Commit

Permalink
Merge pull request #123 from mindwm/feat/test_ping_pong_full_flow
Browse files Browse the repository at this point in the history
Feat/test ping pong full flow
  • Loading branch information
metacoma authored Sep 23, 2024
2 parents 2910451 + bc56b07 commit c87ce4c
Show file tree
Hide file tree
Showing 4 changed files with 141 additions and 51 deletions.
89 changes: 64 additions & 25 deletions tests/mindwm_bdd/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import nats_reader
from queue import Empty
from neo4j import GraphDatabase
import uuid

@pytest.fixture
def ctx():
Expand All @@ -40,6 +41,10 @@ def cloudevent():
@pytest.fixture
def trace_data():
return {}
@pytest.fixture()
def http_response():
return {}


@scenario('lifecycle.feature','Validate Mindwm custom resource definitions')
def test_scenario():
Expand Down Expand Up @@ -368,15 +373,6 @@ def nats_stream_exists(kube, nats_stream_name, namespace):
pass
assert(is_ready == 'True')

@when("God creates a new cloudevent")
def cloudevent_new(cloudevent):
cloudevent = {}

@when("sets cloudevent \"{key}\" to \"{value}\"")
def cloudevent_header_set(cloudevent, key, value):
cloudevent[key] = value


@when("sends cloudevent to \"{broker_name}\" in \"{namespace}\" namespace")
def event_send_ping(kube, step, cloudevent, broker_name, namespace):
payload = json.loads(step.doc_string.content)
Expand All @@ -385,21 +381,12 @@ def event_send_ping(kube, step, cloudevent, broker_name, namespace):
url = f"http://{ingress_host}/{namespace}/{broker_name}"

headers = {
"Host": "broker-ingress.knative-eventing.svc.cluster.local",
"Content-Type": "application/json",
"traceparent": cloudevent['traceparent'],
"Ce-specversion": "1.0",
"Ce-id": cloudevent['ce-id'],
"ce-source": cloudevent['ce-source'],
"ce-subject": cloudevent['ce-subject'],
"ce-type": cloudevent['ce-type']
**{
"Content-Type": "application/json",
"Ce-specversion": "1.0",
},
**cloudevent['headers']
}
# payload = {
# "input": cloudevent["ce-source"],
# "output": "",
# "ps1": "❯",
# "type": cloudevent['ce-type']
# }
response = requests.post(url, headers=headers, data=json.dumps(payload))
assert response.status_code == 202, f"Unexpected status code: {response.status_code}"

Expand All @@ -413,7 +400,7 @@ def tracesql_get_trace(kube, traceparent, trace_data):
headers = {
"Host": "tempo.mindwm.local"
}
time.sleep(5)
time.sleep(10)
response = requests.get(url, headers = headers)
assert response.status_code == 200, f"Response code {response.status_code} != 200"
tempo_reply = json.loads(response.text)
Expand Down Expand Up @@ -483,7 +470,7 @@ def graph_check_node(kube, node_type, prop, value, cloudevent, context_name):
uri = f"bolt://{ingress_host}:{bolt_port}"
auth = ("neo4j", "password")

traceparent_id = utils.extract_trace_id(cloudevent['traceparent'])
traceparent_id = utils.extract_trace_id(cloudevent['headers']['traceparent'])

with GraphDatabase.driver(uri, auth=auth) as driver:
driver.verify_connectivity()
Expand All @@ -502,6 +489,58 @@ def graph_check_node(kube, node_type, prop, value, cloudevent, context_name):
with allure.step(f"Node '{node_type}' has property {prop} == {value} in {context_name}"):
pass

@when("God creates a new cloudevent")
def cloudevent_create_cloudevent(step, cloudevent):
cloudevent['headers'] = {}
cloudevent['data'] = ""
@when("sets cloudevent header \"{header_name}\" to \"{value}\"")
def cloudevent_header_set(cloudevent, header_name, value):
cloudevent['headers'][header_name] = value

@when("sends cloudevent to knative service \"{knative_service_name}\" in \"{namespace}\" namespace")
def cloudevent_send_to_ksvc(step, http_response, kube, cloudevent, knative_service_name, namespace):
cloudevent['data'] = json.loads(step.doc_string.content)
ksvc = utils.ksvc_url(kube, namespace, knative_service_name)
url = ksvc['status']['url']

headers = {
**{
"Content-Type": "application/json",
"Ce-specversion": "1.0",
},
**cloudevent['headers']
}

http_response['answer'] = requests.post(url, headers=headers, data=json.dumps(cloudevent['data']))

@then("the response http code should be \"{code}\"")
def http_response_code_check(http_response, code):
status_code = str(http_response['answer'].status_code)
assert status_code == code, f"HTTP status code {status_code} != {code}"

@when("sends cloudevent to \"{endpoint}\"")
def cloudevent_send(step, kube, http_response, cloudevent, endpoint):
cloudevent['data'] = json.loads(step.doc_string.content)
(host, path) = endpoint.split("/", 1)
assert host is not None, f"Host in {endpoint} is None"
assert path is not None, f"Path in {endpoint} is None"

ingress_host = utils.get_lb(kube)
url = f"http://{ingress_host}/{path}"

headers = {
**{
"Host": f"{host}.svc.cluster.local",
"Content-Type": "application/json",
"Ce-specversion": "1.0",
"Ce-id": str(uuid.uuid4()),
},
**cloudevent['headers']
}

http_response['answer'] = requests.post(url, headers=headers, data=json.dumps(cloudevent['data']))


@when("God makes graph query in context \"{context_name}\"")
def graph_query(kube, context_name, step):
q = step.doc_string.content
Expand Down
71 changes: 52 additions & 19 deletions tests/mindwm_bdd/features/3_mindwm_ping_pong.feature
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,10 @@ Feature: MindWM Ping-pong EDA test
Given A MindWM environment
Then all nodes in Kubernetes are ready

Scenario: Ping <context>

Scenario: Prepare environment for ping tests
When God creates a MindWM context with the name "<context>"
Then the context should be ready and operable
Then following knative service is in ready state in "context-<context>" namespace
And following knative service is in ready state in "context-<context>" namespace
| Knative service name |
| pong |

Expand All @@ -17,23 +16,56 @@ Feature: MindWM Ping-pong EDA test

When God creates a MindWM host resource with the name "<host>" and connects it to the user "<username>"
Then the host resource should be ready and operable
And NatsJetStreamChannel "<host>-host-broker-kne-trigger" is ready in "user-<username>" namespace


When God starts reading message from NATS topic "user-<username>.<host>-host-broker-kne-trigger._knative"

Examples:
| context | username | host |
| green4 | amanda4 | pi6-host |

Scenario: Send pind to knative ping service
When God creates a new cloudevent
And sets cloudevent "ce-id" to "<cloudevent_id>"
And sets cloudevent "traceparent" to "<traceparent>"
And sets cloudevent "ce-subject" to "#ping"
And sets cloudevent "ce-source" to "org.mindwm.<username>.<host>.L3RtcC90bXV4LTEwMDAvZGVmYXVsdA==.09fb195c-c419-6d62-15e0-51b6ee990922.23.36.iodocument"
And sets cloudevent "ce-type" to "org.mindwm.v1.iodocument"
And sends cloudevent to "context-broker" in "context-<context>" namespace
"""
{
"input": "#ping",
"output": "",
"ps1": "❯",
"type": "org.mindwm.v1.iodocument"
}
"""
And sets cloudevent header "ce-subject" to "#ping"
And sets cloudevent header "ce-type" to "org.mindwm.v1.iodocument"
And sets cloudevent header "ce-source" to "org.mindwm.<username>.<host>.L3RtcC90bXV4LTEwMDAvZGVmYXVsdA==.09fb195c-c419-6d62-15e0-51b6ee990922.23.36.iodocument"
And sends cloudevent to knative service "pong" in "context-<context>" namespace
"""
{
"input": "#ping",
"output": "",
"ps1": "❯",
"type": "org.mindwm.v1.iodocument"
}
"""
Then the response http code should be "200"

Then following deployments is in ready state in "context-<context>" namespace
| Deployment name |
| pong-00001-deployment |

Examples:
| context | username | host |
| green4 | amanda4 | pi6-host |

Scenario: Send ping via <endpoint>
When God creates a new cloudevent
And sets cloudevent header "ce-subject" to "#ping"
And sets cloudevent header "ce-type" to "org.mindwm.v1.iodocument"
And sets cloudevent header "traceparent" to "<traceparent>"
And sets cloudevent header "ce-source" to "org.mindwm.<username>.<host>.L3RtcC90bXV4LTEwMDAvZGVmYXVsdA==.09fb195c-c419-6d62-15e0-51b6ee990922.23.36.iodocument"
And sends cloudevent to "<endpoint>"
"""
{
"input": "#ping",
"output": "",
"ps1": "❯",
"type": "org.mindwm.v1.iodocument"
}
"""
Then the response http code should be "202"

Then following deployments is in ready state in "context-<context>" namespace
| Deployment name |
| pong-00001-deployment |
Expand All @@ -46,8 +78,9 @@ Feature: MindWM Ping-pong EDA test
And a cloudevent with type == "org.mindwm.v1.pong" should have been received from the NATS topic

Examples:
| context | username | host | cloudevent_id | traceparent |
| green4 | amanda4 | pi6-host | 442af213-c860-4535-b639-355f13b2d443 | 00-5df92f3577b34da6a3ce929d0e0e4734-00f067aa0ba902b7-00 |
| context | username | host | endpoint | traceparent |
| green4 | amanda4 | pi6-host | broker-ingress.knative-eventing/context-green4/context-broker | 00-5df92f3577b34da6a3ce929d0e0e4734-00f067aa0ba902b7-00 |
| green4 | amanda4 | pi6-host | broker-ingress.knative-eventing/user-amanda4/user-broker | 00-6df93f3577b34da6a3ce929d0e0e4742-00f067aa0ba902b7-00 |


Scenario: Cleanup <username>@<host> in <context>
Expand Down
20 changes: 13 additions & 7 deletions tests/mindwm_bdd/features/4_mindwm_io_context.feature
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,27 @@ Feature: MindWM io context function test

When God creates a MindWM host resource with the name "<host>" and connects it to the user "<username>"
Then the host resource should be ready and operable
# When God makes graph query in context "<context>"
# """
# MATCH (N) DETACH DELETE N;
# """

When God creates a new cloudevent
And sets cloudevent "ce-id" to "<cloudevent_id>"
And sets cloudevent "traceparent" to "<traceparent>"
And sets cloudevent "ce-subject" to "id"
And sets cloudevent "ce-source" to "org.mindwm.<username>.<host>.L3RtcC90bXV4LTEwMDAvZGVmYXVsdA==.09fb195c-c419-6d62-15e0-51b6ee990922.23.36.iodocument"
And sets cloudevent "ce-type" to "org.mindwm.v1.iodocument"
When sends cloudevent to "context-broker" in "context-<context>" namespace
And sets cloudevent header "ce-id" to "<cloudevent_id>"
And sets cloudevent header "traceparent" to "<traceparent>"
And sets cloudevent header "ce-subject" to "id"
And sets cloudevent header "ce-source" to "org.mindwm.<username>.<host>.L3RtcC90bXV4LTEwMDAvZGVmYXVsdA==.09fb195c-c419-6d62-15e0-51b6ee990922.23.36.iodocument"
And sets cloudevent header "ce-type" to "org.mindwm.v1.iodocument"
And sends cloudevent to "broker-ingress.knative-eventing/context-<context>/context-broker"
"""
{
"input": "id",
"output": "uid=1000(pion) gid=1000(pion) groups=1000(pion),4(adm),100(users),112(tmux),988(docker)",
"ps1": "pion@mindwm-stg1:~/work/dev/mindwm-manager$"
"ps1": "pion@mindwm-stg1:~/work/dev/mindwm-manager$",
"type": "org.mindwm.v1.iodocument"
}
"""
Then the response http code should be "202"
Then following deployments is in ready state in "context-<context>" namespace
| Deployment name |
| iocontext-00001-deployment |
Expand Down
12 changes: 12 additions & 0 deletions tests/mindwm_bdd/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -304,3 +304,15 @@ def neo4j_get_bolt_node_port(kube, context_name):
return port.node_port

return None

def ksvc_url(kube, namespace, knative_service_name):
ksvc = custom_object_wait_for(
kube,
namespace,
'serving.knative.dev',
"v1",
"services",
knative_service_name,
60
)
return ksvc

0 comments on commit c87ce4c

Please sign in to comment.