From bcb39e29fbe5891022a938dff48f0f976bbfe9bf Mon Sep 17 00:00:00 2001 From: jiajingbin Date: Thu, 18 Jul 2024 15:34:15 +0800 Subject: [PATCH 1/4] test: refactor cases --- tests/pytest/util/common.py | 18 +++++++++++++++--- .../8-stream/at_once_state_window.py | 4 ++-- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/tests/pytest/util/common.py b/tests/pytest/util/common.py index 7bb2f42495..467948c3b0 100644 --- a/tests/pytest/util/common.py +++ b/tests/pytest/util/common.py @@ -28,8 +28,8 @@ from util.common import * from util.constant import * from dataclasses import dataclass,field from typing import List -from datetime import datetime -import re +from datetime import datetime, timedelta + @dataclass class DataSet: ts_data : List[int] = field(default_factory=list) @@ -1797,6 +1797,18 @@ class TDCom: self.sdelete_rows(tbname=self.ctb_name, start_ts=self.time_cast(self.record_history_ts, "-")) self.sdelete_rows(tbname=self.tb_name, start_ts=self.time_cast(self.record_history_ts, "-")) + def get_timestamp_30_days_later(self): + """ + Get the timestamp for a date 30 days later than the current date. + + Returns: + float: The timestamp for the date 30 days later. + """ + now = datetime.now() + thirty_days_later = now + timedelta(days=30) + timestamp_thirty_days_later = thirty_days_later.timestamp() + return int(timestamp_thirty_days_later*1000) + def prepare_data(self, interval=None, watermark=None, session=None, state_window=None, state_window_max=127, interation=3, range_count=None, precision="ms", fill_history_value=0, ext_stb=None, custom_col_index=None, col_value_type="random"): """prepare stream data @@ -1827,7 +1839,7 @@ class TDCom: "state_window_max": state_window_max, "iteration": interation, "range_count": range_count, - "start_ts": 1655903478508, + "start_ts": self.get_timestamp_30_days_later(), } if range_count is not None: self.range_count = range_count diff --git a/tests/system-test/8-stream/at_once_state_window.py b/tests/system-test/8-stream/at_once_state_window.py index 933a41553e..51c24c752b 100644 --- a/tests/system-test/8-stream/at_once_state_window.py +++ b/tests/system-test/8-stream/at_once_state_window.py @@ -95,7 +95,7 @@ class TDTestCase: if partition == "c1": if subtable: tbname = self.tdCom.get_subtable_wait(f'{self.ctb_name}_{self.tdCom.subtable_prefix}{c1_value[1]}{self.tdCom.subtable_suffix}') - tdSql.query(f'select count(*) from `{tbname}`') + tdSql.query(f'select count(*) from `{tbname}`', count_expected_res=1) else: tbname = self.tdCom.get_subtable_wait(f'{self.ctb_name}_{self.tdCom.subtable_prefix}{partition_elm_alias}{self.tdCom.subtable_suffix}') tdSql.query(f'select count(*) from `{tbname}`') @@ -103,7 +103,7 @@ class TDTestCase: elif partition == "abs(c1)": abs_c1_value = abs(c1_value[1]) tbname = self.tdCom.get_subtable_wait(f'{self.ctb_name}_{self.tdCom.subtable_prefix}{abs_c1_value}{self.tdCom.subtable_suffix}') - tdSql.query(f'select count(*) from `{tbname}`') + tdSql.query(f'select count(*) from `{tbname}`', count_expected_res=1) elif partition == "tbname" and ptn_counter == 0: tbname = self.tdCom.get_subtable_wait(f'{self.ctb_name}_{self.tdCom.subtable_prefix}{self.ctb_name}{self.tdCom.subtable_suffix}') tdSql.query(f'select count(*) from `{tbname}`') From 97b5e8fde02c3fd3a194646387309bf603cd9fa8 Mon Sep 17 00:00:00 2001 From: jiajingbin Date: Thu, 18 Jul 2024 15:36:20 +0800 Subject: [PATCH 2/4] test: refactor cases --- tests/pytest/util/common.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/pytest/util/common.py b/tests/pytest/util/common.py index 467948c3b0..e2b210151e 100644 --- a/tests/pytest/util/common.py +++ b/tests/pytest/util/common.py @@ -1797,7 +1797,7 @@ class TDCom: self.sdelete_rows(tbname=self.ctb_name, start_ts=self.time_cast(self.record_history_ts, "-")) self.sdelete_rows(tbname=self.tb_name, start_ts=self.time_cast(self.record_history_ts, "-")) - def get_timestamp_30_days_later(self): + def get_timestamp_n_days_later(self, n=30): """ Get the timestamp for a date 30 days later than the current date. @@ -1805,7 +1805,7 @@ class TDCom: float: The timestamp for the date 30 days later. """ now = datetime.now() - thirty_days_later = now + timedelta(days=30) + thirty_days_later = now + timedelta(days=n) timestamp_thirty_days_later = thirty_days_later.timestamp() return int(timestamp_thirty_days_later*1000) @@ -1839,7 +1839,7 @@ class TDCom: "state_window_max": state_window_max, "iteration": interation, "range_count": range_count, - "start_ts": self.get_timestamp_30_days_later(), + "start_ts": self.get_timestamp_n_days_later(), } if range_count is not None: self.range_count = range_count From db4a2c7e9866800a5661b8d7c19a1e2bcbe44dd1 Mon Sep 17 00:00:00 2001 From: jiajingbin Date: Thu, 18 Jul 2024 15:37:30 +0800 Subject: [PATCH 3/4] test: refactor cases --- tests/pytest/util/common.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/tests/pytest/util/common.py b/tests/pytest/util/common.py index e2b210151e..3d25207158 100644 --- a/tests/pytest/util/common.py +++ b/tests/pytest/util/common.py @@ -1799,10 +1799,13 @@ class TDCom: def get_timestamp_n_days_later(self, n=30): """ - Get the timestamp for a date 30 days later than the current date. + Get the timestamp of a date n days later from the current date. + + Args: + n (int): Number of days to add to the current date. Default is 30. Returns: - float: The timestamp for the date 30 days later. + int: Timestamp of the date n days later, in milliseconds. """ now = datetime.now() thirty_days_later = now + timedelta(days=n) From 8fe1353b963936d51cf0ffe64cff23bf9990dce3 Mon Sep 17 00:00:00 2001 From: jiajingbin Date: Fri, 19 Jul 2024 09:12:32 +0800 Subject: [PATCH 4/4] test: update --- tests/pytest/util/common.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/pytest/util/common.py b/tests/pytest/util/common.py index 3d25207158..63dc9773c4 100644 --- a/tests/pytest/util/common.py +++ b/tests/pytest/util/common.py @@ -29,6 +29,7 @@ from util.constant import * from dataclasses import dataclass,field from typing import List from datetime import datetime, timedelta +import re @dataclass class DataSet: