Skip to content

Commit aab3a66

Browse files
committed
chore: add cron test
1 parent d2bacf1 commit aab3a66

File tree

3 files changed

+41
-9
lines changed

3 files changed

+41
-9
lines changed

src/query/management/src/task/task_mgr.rs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -274,12 +274,14 @@ impl TaskMgr {
274274
match schedule_options.schedule_type {
275275
ScheduleType::IntervalType => (),
276276
ScheduleType::CronType => {
277-
if let Err(e) = schedule_options.time_zone.as_ref().unwrap().parse::<Tz>() {
278-
return Ok(Err(TaskError::InvalidTimezone {
279-
tenant: self.tenant.tenant_name().to_string(),
280-
name: task.task_name.to_string(),
281-
reason: e.to_string(),
282-
}));
277+
if let Some(tz) = &schedule_options.time_zone {
278+
if let Err(e) = tz.parse::<Tz>() {
279+
return Ok(Err(TaskError::InvalidTimezone {
280+
tenant: self.tenant.tenant_name().to_string(),
281+
name: task.task_name.to_string(),
282+
reason: e.to_string(),
283+
}));
284+
}
283285
}
284286
if let Err(e) = Schedule::from_str(schedule_options.cron.as_ref().unwrap()) {
285287
return Ok(Err(TaskError::InvalidCron {

src/query/service/src/task/service.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -290,9 +290,9 @@ impl TaskService {
290290
let tz = schedule_options
291291
.time_zone
292292
.as_ref()
293-
.unwrap()
294-
.parse::<Tz>()
295-
.unwrap();
293+
.map(|tz| tz.parse::<Tz>())
294+
.transpose()?
295+
.unwrap_or_else(|| Tz::UCT);
296296
let schedule = Schedule::from_str(cron_expr).unwrap();
297297

298298
runtime

tests/task/test-private-task.sh

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,3 +228,33 @@ if [ "$state14" = "Succeeded" ]; then
228228
else
229229
echo "✅ Passed"
230230
fi
231+
232+
response15=$(curl -s -u root: -XPOST "http://localhost:8000/v1/query" -H 'Content-Type: application/json' -d "{\"sql\": \"CREATE TABLE t2 (c1 int)\"}")
233+
create_table_query_id_1=$(echo $response15 | jq -r '.id')
234+
echo "Create Table Query ID: $create_table_query_id_1"
235+
236+
response16=$(curl -s -u root: -XPOST "http://localhost:8000/v1/query" -H 'Content-Type: application/json' -d "{\"sql\": \"CREATE TASK my_task_4 WAREHOUSE = 'mywh' SCHEDULE = USING CRON '*/5 * * * * ?' AS insert into t2 values(0)\"}")
237+
create_task_4_query_id=$(echo $response16 | jq -r '.id')
238+
echo "Create Task 4 Query ID: $create_task_4_query_id"
239+
240+
sleep 1
241+
242+
response17=$(curl -s -u root: -XPOST "http://localhost:8000/v1/query" -H 'Content-Type: application/json' -d "{\"sql\": \"ALTER TASK my_task_4 RESUME\"}")
243+
alter_task_4_query_id=$(echo $response17 | jq -r '.id')
244+
echo "Resume Task 4 ID: $alter_task_4_query_id"
245+
246+
sleep 11
247+
248+
response18=$(curl -s -u root: -XPOST "http://localhost:8000/v1/query" -H 'Content-Type: application/json' -d "{\"sql\": \"SELECT c1 FROM t2 ORDER BY c1\"}")
249+
250+
actual=$(echo "$response18" | jq -c '.data')
251+
expected='[["0"],["0"]]'
252+
253+
if [ "$actual" = "$expected" ]; then
254+
echo "✅ Query result matches expected"
255+
else
256+
echo "❌ Mismatch"
257+
echo "Expected: $expected"
258+
echo "Actual : $actual"
259+
exit 1
260+
fi

0 commit comments

Comments
 (0)