Skip to content

Commit

Permalink
fix roll file test at day boundary
Browse files Browse the repository at this point in the history
  • Loading branch information
dsschult committed Oct 1, 2024
1 parent 10e20dd commit edb4686
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 5 deletions.
4 changes: 2 additions & 2 deletions iceprod/server/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import asyncio
from concurrent.futures import ThreadPoolExecutor
from datetime import datetime, timedelta
from datetime import datetime, timedelta, UTC
import logging
import os
import sys
Expand Down Expand Up @@ -59,7 +59,7 @@ async def run(self):


def roll_files(fd, filename, num_files=5):
d = datetime.utcnow()
d = datetime.now(UTC)
ext = (d-timedelta(days=num_files-1)).strftime('%Y-%m-%d')
newfile = f'{filename}.{ext}'
if os.path.exists(newfile): # delete last file
Expand Down
5 changes: 2 additions & 3 deletions tests/server/server_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import shutil
import subprocess
import importlib
from datetime import datetime
from datetime import datetime, UTC
import glob

from unittest.mock import AsyncMock, MagicMock
Expand Down Expand Up @@ -70,8 +70,7 @@ def test_90_roll_files(tmp_path):
fd = roll_files(fd, filename)
assert os.path.exists(filename)

ext = datetime.utcnow().strftime('%Y-%m')
files = glob.glob(f'{filename}.{ext}*')
files = glob.glob(f'{filename}.*')
assert len(files) == 1

fd.write(b'bar')
Expand Down

0 comments on commit edb4686

Please sign in to comment.