Skip to content

Commit 6ab6243

Browse files
FengPan-Frankmssonicbld
authored andcommitted
Fix UT test data due to timestamp break. (#117)
Fix UT test data due to timestamp break.
1 parent 7a68e40 commit 6ab6243

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

tests/procdockerstatsd_test.py

+6-3
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
from unittest.mock import call, patch
66
from swsscommon import swsscommon
77
from sonic_py_common.general import load_module_from_source
8+
from datetime import datetime, timedelta
89

910
from .mock_connector import MockConnector
1011

@@ -109,11 +110,13 @@ def test_run_command(self):
109110

110111
def test_update_processstats_command(self):
111112
pdstatsd = procdockerstatsd.ProcDockerStats(procdockerstatsd.SYSLOG_IDENTIFIER)
112-
113+
current_time = datetime.now()
114+
valid_create_time1 = int((current_time - timedelta(days=1)).timestamp())
115+
valid_create_time2 = int((current_time - timedelta(days=2)).timestamp())
113116
# Create a list of mocked processes
114117
mocked_processes = [
115-
MockProcess(uids=[1000], pid=1234, ppid=5678, memory_percent=10.5, cpu_percent=20.5, create_time=1234567890, cmdline=['python', 'script.py'], user_time=1.5, system_time=2.0),
116-
MockProcess(uids=[1000], pid=5678, ppid=0, memory_percent=5.5, cpu_percent=15.5, create_time=9876543210, cmdline=['bash', 'script.sh'], user_time=3.5, system_time=4.0)
118+
MockProcess(uids=[1000], pid=1234, ppid=5678, memory_percent=10.5, cpu_percent=20.5, create_time=valid_create_time1, cmdline=['python', 'script.py'], user_time=1.5, system_time=2.0),
119+
MockProcess(uids=[1000], pid=5678, ppid=0, memory_percent=5.5, cpu_percent=15.5, create_time=valid_create_time2, cmdline=['bash', 'script.sh'], user_time=3.5, system_time=4.0)
117120
]
118121

119122
with patch("procdockerstatsd.psutil.process_iter", return_value=mocked_processes) as mock_process_iter:

0 commit comments

Comments
 (0)