Skip to content

Commit

Permalink
add sleep to more db tests (facebookresearch#408)
Browse files Browse the repository at this point in the history
Summary:
Pull Request resolved: facebookresearch#408

DB tests sometimes fails on Windows because db files are not ready yet. Adding sleeps throughout should guarantee their success.

Additionally we try to catch further fails in tearDown such that fails here do not cause test fails as errors here are not what is strictly being tested.

Reviewed By: crasanders

Differential Revision: D64541706

fbshipit-source-id: a747ac3a9e4d64725e9807b0a0776ab91c0c4601
  • Loading branch information
JasonKChow authored and facebook-github-bot committed Oct 17, 2024
1 parent 7c7fa88 commit bbda7fe
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
9 changes: 6 additions & 3 deletions tests/server/test_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
import json
import logging
import select
import time
import unittest
import uuid
from unittest.mock import MagicMock
import time

import aepsych.server as server
import aepsych.utils_logging as utils_logging
Expand Down Expand Up @@ -64,11 +64,14 @@ def tearDown(self):
self.s.cleanup()

# sleep to ensure db is closed
time.sleep(0.1)
time.sleep(0.2)

# cleanup the db
if self.s.db is not None:
self.s.db.delete_db()
try:
self.s.db.delete_db()
except PermissionError as e:
print("Failed to deleted database: ", e)

def dummy_create_setup(self, server, request=None):
request = request or {"test": "test request"}
Expand Down
8 changes: 8 additions & 0 deletions tests/test_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import json
import os
import shutil
import time
import unittest
import uuid
from configparser import DuplicateOptionError
Expand All @@ -26,6 +27,7 @@ def setUp(self):
self._database = db.Database(db_path=self._dbname)

def tearDown(self):
time.sleep(0.1)
self._database.delete_db()

def test_db_create(self):
Expand Down Expand Up @@ -129,6 +131,9 @@ def test_update_db(self):
shutil.copy(str(db_path), str(dst_db_path))
self.assertTrue(dst_db_path.is_file())

# add sleep to ensure file is ready
time.sleep(0.1)

# open the new db
test_database = db.Database(db_path=dst_db_path.as_posix())

Expand Down Expand Up @@ -170,6 +175,9 @@ def test_update_db_with_raw_data_tables(self):
shutil.copy(str(db_path), str(dst_db_path))
self.assertTrue(dst_db_path.is_file())

# sleep to ensure db is ready
time.sleep(0.1)

# open the new db
test_database = db.Database(db_path=dst_db_path.as_posix())

Expand Down

0 comments on commit bbda7fe

Please sign in to comment.