Skip to content

Commit fb41798

Browse files
server: fix updating of headers behaviour in the update cron trigger 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 <[email protected]>
1 parent 08d6ea4 commit fb41798

File tree

2 files changed

+69
-11
lines changed

2 files changed

+69
-11
lines changed

server/commit_diff.txt

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -197,16 +197,6 @@ Date: Tue Jun 23 20:35:36 2020 -0400
197197
GHC should probably also be doubling the stack buffer at each overflow
198198
or doing something even smarter; the knobs we have aren't so helpful.
199199

200-
commit 6a58c144f540508e3a75c977585577e0b757d550
201-
Author: Karthikeyan Chinnakonda <[email protected]>
202-
Date: Tue Jun 23 20:51:34 2020 +0530
203-
204-
server: fix updating of headers behaviour in the update cron trigger API and create future events immediately (#5151)
205-
206-
* server: fix bug to update headers in an existing cron trigger and create future events
207-
208-
Co-authored-by: Tirumarai Selvan <[email protected]>
209-
210200
(Done, but we should re-visit this, if we do query plan caching)
211201
commit 20cbe9cfd3e90b91d3f4faf370b081fc3859cbde
212202
Author: Auke Booij <[email protected]>

server/tests-py/test_scheduled_triggers.py

Lines changed: 69 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
from croniter import croniter
66
from validate import validate_event_webhook,validate_event_headers
77
from queue import Empty
8+
import json
89
import time
910

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

151152
def test_check_generated_cron_scheduled_events(self,hge_ctx):
@@ -177,6 +178,73 @@ def test_check_generated_cron_scheduled_events(self,hge_ctx):
177178
actual_schedule_timestamps.append(datetime_ts)
178179
assert actual_schedule_timestamps == expected_schedule_timestamps
179180

181+
def test_update_existing_cron_trigger(self,hge_ctx):
182+
expected_schedule_timestamps = []
183+
iter = croniter(self.cron_schedule,datetime.utcnow())
184+
for i in range(100):
185+
expected_schedule_timestamps.append(iter.next(datetime))
186+
q = {
187+
"type":"create_cron_trigger",
188+
"args":{
189+
"name":self.cron_trigger_name,
190+
"webhook":"{{SCHEDULED_TRIGGERS_WEBHOOK_DOMAIN}}" + "/foo",
191+
"schedule":self.cron_schedule,
192+
"headers":[
193+
{
194+
"name":"header-name",
195+
"value":"header-value"
196+
}
197+
],
198+
"payload":{"foo":"baz"},
199+
"include_in_metadata":False,
200+
"replace":True
201+
}
202+
}
203+
st,resp = hge_ctx.v1q(q)
204+
assert st == 200, resp
205+
206+
sql = '''
207+
select header_conf::json
208+
from hdb_catalog.hdb_cron_triggers where
209+
name = '{}' '''
210+
q = {
211+
"type":"run_sql",
212+
"args":{
213+
"sql":sql.format(self.cron_trigger_name)
214+
}
215+
}
216+
st,resp = hge_ctx.v1q(q)
217+
assert st == 200,resp
218+
print ("resp",resp['result'][1][0])
219+
assert json.loads(resp['result'][1][0]) == [{
220+
"name":"header-name",
221+
"value":"header-value"
222+
}]
223+
224+
# Get timestamps in UTC from the db to compare it with
225+
# the croniter generated timestamps
226+
# After updating the cron trigger, the future events should
227+
# have been created
228+
sql = '''
229+
select timezone('utc',scheduled_time) as scheduled_time
230+
from hdb_catalog.hdb_cron_events where
231+
trigger_name = '{}' order by scheduled_time asc;'''
232+
q = {
233+
"type":"run_sql",
234+
"args":{
235+
"sql":sql.format(self.cron_trigger_name)
236+
}
237+
}
238+
st,resp = hge_ctx.v1q(q)
239+
assert st == 200,resp
240+
ts_resp = resp['result'][1:]
241+
assert len(ts_resp) == 100
242+
actual_schedule_timestamps = []
243+
for ts in ts_resp:
244+
datetime_ts = datetime.strptime(ts[0],"%Y-%m-%d %H:%M:%S")
245+
actual_schedule_timestamps.append(datetime_ts)
246+
assert actual_schedule_timestamps == expected_schedule_timestamps
247+
180248
def test_delete_cron_scheduled_trigger(self,hge_ctx):
181249
q = {
182250
"type":"delete_cron_trigger",

0 commit comments

Comments
 (0)