Skip to content

Commit

Permalink
debug code
Browse files Browse the repository at this point in the history
  • Loading branch information
pjbull committed Aug 15, 2024
1 parent 4bb951f commit 60235b2
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions tests/test_caching.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import gc
import os
import sys
from time import sleep
from pathlib import Path

Expand Down Expand Up @@ -501,12 +502,37 @@ def test_manual_cache_clearing(rig: CloudProviderTestRig):

assert len(list(filter(lambda x: x.is_file(), client._local_cache_dir.rglob("*")))) == 0

# Enable debugging for garbage collection
gc.callbacks.append(lambda event, args: print(f"GC {event} - {args}"))

# also removes containing folder on client cleanted up
local_cache_path = cp._local
client_cache_folder = client._local_cache_dir
del cp
del client

def _debug(path):
import subprocess
import psutil

# file handles on windows
if sys.platform == "win32":
import subprocess

result = subprocess.run(["handle.exe", path], capture_output=True, text=True)
print(f" HANDLES FOR {path}")
print(result.stdout)

# processes with open files
open_files = []
for proc in psutil.process_iter(["pid", "name", "open_files"]):
for file in proc.info["open_files"] or []:
if path in file.path:
open_files.append((proc.info["pid"], proc.info["name"], file.path))

print(f" OPEN FILES INFO FOR {path}")
print(open_files)

# in CI there can be a lag before the cleanup actually happens
@retry(
retry=retry_if_exception_type(AssertionError),
Expand All @@ -515,13 +541,18 @@ def test_manual_cache_clearing(rig: CloudProviderTestRig):
reraise=True,
)
def _resilient_assert():
_debug(str(local_cache_path.resolve()))
_debug(str(client_cache_folder.resolve()))

gc.collect() # force gc before asserting

assert not local_cache_path.exists()
assert not client_cache_folder.exists()

_resilient_assert()

gc.callbacks.pop()


def test_reuse_cache_after_manual_cache_clear(rig: CloudProviderTestRig):
# use client that we can delete rather than default
Expand Down

0 comments on commit 60235b2

Please sign in to comment.