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:

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

Reviewed By: crasanders

Differential Revision: D64541706
  • Loading branch information
JasonKChow authored and facebook-github-bot committed Oct 17, 2024
1 parent 7c7fa88 commit 40d8cbe
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
4 changes: 2 additions & 2 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,7 +64,7 @@ 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:
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 40d8cbe

Please sign in to comment.