mirror of
https://github.com/hasura/graphql-engine.git
synced 2024-12-14 17:02:49 +03:00
server: fix flaky test_check_events_statuses
test
PR-URL: https://github.com/hasura/graphql-engine-mono/pull/2467 Co-authored-by: paritosh-08 <85472423+paritosh-08@users.noreply.github.com> GitOrigin-RevId: a6388397dae11e38962321915c06496cc57ffd64
This commit is contained in:
parent
459a7adbfb
commit
631f39cadf
3
server/tests-py/queries/scheduled_triggers/teardown.yaml
Normal file
3
server/tests-py/queries/scheduled_triggers/teardown.yaml
Normal file
@ -0,0 +1,3 @@
|
||||
type: run_sql
|
||||
args:
|
||||
sql : delete from hdb_catalog.hdb_scheduled_events
|
@ -7,6 +7,7 @@ from validate import validate_event_webhook,validate_event_headers
|
||||
from queue import Empty
|
||||
import json
|
||||
import time
|
||||
from utils import until_asserts_pass
|
||||
|
||||
# The create and delete tests should ideally go in setup and teardown YAML files,
|
||||
# We can't use that here because, the payload is dynamic i.e. in case of one-off scheduled events
|
||||
@ -15,10 +16,13 @@ import time
|
||||
|
||||
def stringify_datetime(dt):
|
||||
return dt.strftime("%Y-%m-%dT%H:%M:%S.%fZ")
|
||||
|
||||
@pytest.mark.skip(msg="See https://github.com/hasura/graphql-engine-mono/pull/2467 for the details")
|
||||
@pytest.mark.usefixtures('per_method_tests_db_state')
|
||||
class TestScheduledEvent(object):
|
||||
|
||||
@classmethod
|
||||
def dir(cls):
|
||||
return 'queries/scheduled_triggers'
|
||||
|
||||
webhook_payload = {"foo":"baz"}
|
||||
|
||||
header_conf = [
|
||||
@ -28,68 +32,58 @@ class TestScheduledEvent(object):
|
||||
}
|
||||
]
|
||||
|
||||
url = "/v1/query"
|
||||
|
||||
webhook_domain = "http://127.0.0.1:5594"
|
||||
|
||||
|
||||
# Succeeds
|
||||
def test_create_scheduled_event(self,hge_ctx):
|
||||
def test_scheduled_events(self,hge_ctx,scheduled_triggers_evts_webhook):
|
||||
query = {
|
||||
"type":"create_scheduled_event",
|
||||
"args":{
|
||||
"webhook":'{{SCHEDULED_TRIGGERS_WEBHOOK_DOMAIN}}/test',
|
||||
"schedule_at":stringify_datetime(datetime.utcnow()),
|
||||
"payload":self.webhook_payload,
|
||||
"headers":self.header_conf,
|
||||
"comment":"test scheduled event"
|
||||
}
|
||||
}
|
||||
st, resp = hge_ctx.v1q(query)
|
||||
assert st == 200,resp
|
||||
# ensuring that a valid event_id is returned
|
||||
assert 'event_id' in resp, resp
|
||||
|
||||
# Fails immediately, with 'dead'
|
||||
def test_create_scheduled_event_with_very_old_scheduled_time(self,hge_ctx):
|
||||
query = {
|
||||
"type":"create_scheduled_event",
|
||||
"args":{
|
||||
"webhook":"{{SCHEDULED_TRIGGERS_WEBHOOK_DOMAIN}}/",
|
||||
"schedule_at": "2020-01-01T00:00:00Z",
|
||||
"payload":self.webhook_payload,
|
||||
"headers":self.header_conf
|
||||
}
|
||||
}
|
||||
st, resp = hge_ctx.v1q(query)
|
||||
assert st == 200,resp
|
||||
# ensuring that a valid event_id is returned
|
||||
assert 'event_id' in resp, resp
|
||||
|
||||
# Fails on request, trying twice:
|
||||
def test_create_trigger_with_error_returning_webhook(self,hge_ctx):
|
||||
query = {
|
||||
"type":"create_scheduled_event",
|
||||
"args":{
|
||||
"webhook":self.webhook_domain + '/fail',
|
||||
"schedule_at": stringify_datetime(datetime.utcnow()),
|
||||
"payload":self.webhook_payload,
|
||||
"headers":self.header_conf,
|
||||
"retry_conf":{
|
||||
"num_retries":1,
|
||||
"retry_interval_seconds":1,
|
||||
"timeout_seconds":1,
|
||||
"tolerance_seconds": 21600
|
||||
"type": "bulk",
|
||||
"args": [
|
||||
# Succeeds
|
||||
{
|
||||
"type":"create_scheduled_event",
|
||||
"args":{
|
||||
"webhook":'{{SCHEDULED_TRIGGERS_WEBHOOK_DOMAIN}}/test',
|
||||
"schedule_at":stringify_datetime(datetime.utcnow()),
|
||||
"payload":self.webhook_payload,
|
||||
"headers":self.header_conf,
|
||||
"comment":"test scheduled event"
|
||||
}
|
||||
},
|
||||
# Fails immediately, with 'dead'
|
||||
{
|
||||
"type":"create_scheduled_event",
|
||||
"args":{
|
||||
"webhook":"{{SCHEDULED_TRIGGERS_WEBHOOK_DOMAIN}}/",
|
||||
"schedule_at": "2020-01-01T00:00:00Z",
|
||||
"payload":self.webhook_payload,
|
||||
"headers":self.header_conf
|
||||
}
|
||||
},
|
||||
# Fails on request, trying twice:
|
||||
{
|
||||
"type":"create_scheduled_event",
|
||||
"args":{
|
||||
"webhook":self.webhook_domain + '/fail',
|
||||
"schedule_at": stringify_datetime(datetime.utcnow()),
|
||||
"payload":self.webhook_payload,
|
||||
"headers":self.header_conf,
|
||||
"retry_conf":{
|
||||
"num_retries":1,
|
||||
"retry_interval_seconds":1,
|
||||
"timeout_seconds":1,
|
||||
"tolerance_seconds": 21600
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
st, resp = hge_ctx.v1q(query)
|
||||
assert st == 200, resp
|
||||
# ensuring that a valid event_id is returned
|
||||
assert 'event_id' in resp, resp
|
||||
assert st == 200,resp
|
||||
assert len(resp) == 3, resp
|
||||
# ensuring that valid event_id is returned for all requests
|
||||
assert all(['event_id' in r for r in resp]), resp
|
||||
|
||||
# Here we check the three requests received by the webhook, from above.
|
||||
def test_check_fired_webhook_events(self,hge_ctx,scheduled_triggers_evts_webhook):
|
||||
# Here we check the three requests received by the webhook.
|
||||
# Collect the three generated events (they may arrive out of order):
|
||||
e1 = scheduled_triggers_evts_webhook.get_event(12) # at least 10 sec, see processScheduledTriggers.sleep
|
||||
e2 = scheduled_triggers_evts_webhook.get_event(12)
|
||||
@ -121,36 +115,28 @@ class TestScheduledEvent(object):
|
||||
assert k in payload_keys
|
||||
assert scheduled_triggers_evts_webhook.is_queue_empty()
|
||||
|
||||
def test_check_events_statuses(self,hge_ctx):
|
||||
query = {
|
||||
"type":"run_sql",
|
||||
"args":{
|
||||
"sql":"select status,tries from hdb_catalog.hdb_scheduled_events"
|
||||
}
|
||||
}
|
||||
st, resp = hge_ctx.v1q(query)
|
||||
assert st == 200, resp
|
||||
scheduled_event_statuses = dict(resp['result'])
|
||||
# 3 scheduled events have been created
|
||||
# one should be dead because the timestamp was past the tolerance limit
|
||||
# one should be delivered because all the parameters were reasonable
|
||||
# one should be error because the webhook returns an error state
|
||||
assert scheduled_event_statuses == {
|
||||
'status': 'tries',
|
||||
'dead': '0',
|
||||
'delivered': '1',
|
||||
'error': '2' # num_retries + 1
|
||||
def try_check_events_statuses():
|
||||
query = {
|
||||
"type":"run_sql",
|
||||
"args":{
|
||||
"sql":"select status,tries from hdb_catalog.hdb_scheduled_events order by status desc"
|
||||
}
|
||||
|
||||
def test_teardown_scheduled_events(self,hge_ctx):
|
||||
query = {
|
||||
"type":"run_sql",
|
||||
"args": {
|
||||
"sql":"delete from hdb_catalog.hdb_scheduled_events"
|
||||
}
|
||||
}
|
||||
st, resp = hge_ctx.v1q(query)
|
||||
assert st == 200,resp
|
||||
st, resp = hge_ctx.v1q(query)
|
||||
assert st == 200, resp
|
||||
scheduled_event_statuses = resp['result']
|
||||
# 3 scheduled events have been created
|
||||
# one should be dead because the timestamp was past the tolerance limit
|
||||
# one should be delivered because all the parameters were reasonable
|
||||
# one should be error because the webhook returns an error state
|
||||
assert scheduled_event_statuses == [
|
||||
['status', 'tries'],
|
||||
['error', '2'], # num_retries + 1
|
||||
['delivered', '1'],
|
||||
['dead', '0']
|
||||
], resp
|
||||
|
||||
until_asserts_pass(100,try_check_events_statuses)
|
||||
|
||||
class TestCronTrigger(object):
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user