Skip to content

Commit 0ad3d05

Browse files
authored
Fix flaky storage tests (#47987)
* Fix flaky storage tests * Fix tests * Fix tests * Retrigger CI/CD pipeline * Remove extra guard * Fix format
1 parent e38d018 commit 0ad3d05

2 files changed

Lines changed: 13 additions & 15 deletions

File tree

sdk/monitor/azure-monitor-opentelemetry-exporter/tests/conftest.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,5 +30,3 @@
3030
collect_ignore_glob = []
3131
if sys.version_info < (3, 6):
3232
collect_ignore_glob.append("*")
33-
34-
collect_ignore = ["test_storage.py"]

sdk/monitor/azure-monitor-opentelemetry-exporter/tests/test_storage.py

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import errno
55
import os
66
import shutil
7+
import tempfile
78
import unittest
89
from unittest import mock
910

@@ -39,7 +40,7 @@ def func(*_args, **_kwargs):
3940

4041

4142
def clean_folder(folder):
42-
if os.path.isfile(folder):
43+
if os.path.isdir(folder):
4344
for filename in os.listdir(folder):
4445
file_path = os.path.join(folder, filename)
4546
try:
@@ -53,16 +54,12 @@ def clean_folder(folder):
5354

5455
# pylint: disable=unused-variable
5556
class TestLocalFileBlob(unittest.TestCase):
56-
@classmethod
57-
def setup_class(cls):
58-
os.makedirs(TEST_FOLDER, exist_ok=True)
59-
60-
@classmethod
61-
def tearDownClass(cls):
62-
shutil.rmtree(TEST_FOLDER, True)
57+
def setUp(self):
58+
global TEST_FOLDER
59+
TEST_FOLDER = tempfile.mkdtemp()
6360

6461
def tearDown(self):
65-
clean_folder(TEST_FOLDER)
62+
shutil.rmtree(TEST_FOLDER, ignore_errors=True)
6663

6764
def test_delete(self):
6865
blob = LocalFileBlob(os.path.join(TEST_FOLDER, "foobar"))
@@ -320,9 +317,12 @@ def test_lease_with_existing_lock(self):
320317

321318
# pylint: disable=protected-access, too-many-public-methods
322319
class TestLocalFileStorage(unittest.TestCase):
323-
@classmethod
324-
def tearDownClass(cls):
325-
shutil.rmtree(TEST_FOLDER, True)
320+
def setUp(self):
321+
global TEST_FOLDER
322+
TEST_FOLDER = tempfile.mkdtemp()
323+
324+
def tearDown(self):
325+
shutil.rmtree(TEST_FOLDER, ignore_errors=True)
326326

327327
def test_get_nothing(self):
328328
with LocalFileStorage(os.path.join(TEST_FOLDER, "test", "a")) as stor:
@@ -374,7 +374,7 @@ def test_check_storage_size_full(self):
374374
os.makedirs(test_path, exist_ok=True)
375375
with mock.patch.object(LocalFileStorage, "_check_and_set_folder_permissions", return_value=True):
376376
with LocalFileStorage(test_path, 1) as stor:
377-
stor.put(test_input)
377+
stor.put(test_input, lease_period=0)
378378
self.assertFalse(stor._check_storage_size())
379379

380380
def test_check_storage_size_not_full(self):

0 commit comments

Comments
 (0)