Skip to content

Commit

Permalink
server: fix updating of headers behaviour in the update cron trigger …
Browse files Browse the repository at this point in the history
…API and create future events immediately (hasura#5151)

* server: fix bug to update headers in an existing cron trigger and create future events

Co-authored-by: Tirumarai Selvan <tiru@hasura.io>
  • Loading branch information
codingkarthik and tirumaraiselvan committed Jul 28, 2020
1 parent cd7de01 commit ec1c467
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 11 deletions.
10 changes: 0 additions & 10 deletions server/commit_diff.txt
Original file line number Diff line number Diff line change
Expand Up @@ -197,16 +197,6 @@ Date: Tue Jun 23 20:35:36 2020 -0400
GHC should probably also be doubling the stack buffer at each overflow
or doing something even smarter; the knobs we have aren't so helpful.

commit 6a58c144f540508e3a75c977585577e0b757d550
Author: Karthikeyan Chinnakonda <karthikeyan@hasura.io>
Date: Tue Jun 23 20:51:34 2020 +0530

server: fix updating of headers behaviour in the update cron trigger API and create future events immediately (#5151)

* server: fix bug to update headers in an existing cron trigger and create future events

Co-authored-by: Tirumarai Selvan <tiru@hasura.io>

(Done, but we should re-visit this, if we do query plan caching)
commit 20cbe9cfd3e90b91d3f4faf370b081fc3859cbde
Author: Auke Booij <auke@hasura.io>
Expand Down
70 changes: 69 additions & 1 deletion server/tests-py/test_scheduled_triggers.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from croniter import croniter
from validate import validate_event_webhook,validate_event_headers
from queue import Empty
import json
import time

# The create and delete tests should ideally go in setup and teardown YAML files,
Expand Down Expand Up @@ -145,7 +146,7 @@ def test_create_cron_schedule_triggers(self,hge_ctx):
TestCronTrigger.init_time = datetime.utcnow()
# the cron events will be generated based on the current time, they
# will not be exactly the same though(the server now and now here)
assert cron_st_code == 200,resp
assert cron_st_code == 200,cron_st_resp
assert cron_st_resp['message'] == 'success'

def test_check_generated_cron_scheduled_events(self,hge_ctx):
Expand Down Expand Up @@ -177,6 +178,73 @@ def test_check_generated_cron_scheduled_events(self,hge_ctx):
actual_schedule_timestamps.append(datetime_ts)
assert actual_schedule_timestamps == expected_schedule_timestamps

def test_update_existing_cron_trigger(self,hge_ctx):
expected_schedule_timestamps = []
iter = croniter(self.cron_schedule,datetime.utcnow())
for i in range(100):
expected_schedule_timestamps.append(iter.next(datetime))
q = {
"type":"create_cron_trigger",
"args":{
"name":self.cron_trigger_name,
"webhook":"{{SCHEDULED_TRIGGERS_WEBHOOK_DOMAIN}}" + "/foo",
"schedule":self.cron_schedule,
"headers":[
{
"name":"header-name",
"value":"header-value"
}
],
"payload":{"foo":"baz"},
"include_in_metadata":False,
"replace":True
}
}
st,resp = hge_ctx.v1q(q)
assert st == 200, resp

sql = '''
select header_conf::json
from hdb_catalog.hdb_cron_triggers where
name = '{}' '''
q = {
"type":"run_sql",
"args":{
"sql":sql.format(self.cron_trigger_name)
}
}
st,resp = hge_ctx.v1q(q)
assert st == 200,resp
print ("resp",resp['result'][1][0])
assert json.loads(resp['result'][1][0]) == [{
"name":"header-name",
"value":"header-value"
}]

# Get timestamps in UTC from the db to compare it with
# the croniter generated timestamps
# After updating the cron trigger, the future events should
# have been created
sql = '''
select timezone('utc',scheduled_time) as scheduled_time
from hdb_catalog.hdb_cron_events where
trigger_name = '{}' order by scheduled_time asc;'''
q = {
"type":"run_sql",
"args":{
"sql":sql.format(self.cron_trigger_name)
}
}
st,resp = hge_ctx.v1q(q)
assert st == 200,resp
ts_resp = resp['result'][1:]
assert len(ts_resp) == 100
actual_schedule_timestamps = []
for ts in ts_resp:
datetime_ts = datetime.strptime(ts[0],"%Y-%m-%d %H:%M:%S")
actual_schedule_timestamps.append(datetime_ts)
assert actual_schedule_timestamps == expected_schedule_timestamps

def test_delete_cron_scheduled_trigger(self,hge_ctx):
q = {
"type":"delete_cron_trigger",
Expand Down

0 comments on commit ec1c467

Please sign in to comment.