test: don't use sleep

Since we now use file size to help detect file changes on filesystems
with bad mtime resolution, we no longer need these explicit sleep()
calls in our tests for mac os.

Signed-off-by: Ruslan Kuprieiev <[email protected]>
This commit is contained in:
Ruslan Kuprieiev
2018-12-17 12:42:35 +02:00
parent d1cb0a3450
commit d5dd0fd804
5 changed files with 3 additions and 92 deletions
+2 -23
View File
@@ -1,6 +1,5 @@
import os
import yaml
import time
import shutil
import filecmp
import collections
@@ -58,8 +57,6 @@ class TestCheckoutCorruptedCacheFile(TestRepro):
def test(self):
cache = self.foo_stage.outs[0].cache
time.sleep(1)
with open(cache, 'a') as fd:
fd.write('1')
@@ -71,8 +68,6 @@ class TestCheckoutCorruptedCacheFile(TestRepro):
class TestCheckoutCorruptedCacheDir(TestDvc):
def test(self):
time.sleep(1)
# NOTE: using 'copy' so that cache and link don't have same inode
ret = main(['config', 'cache.type', 'copy'])
self.assertEqual(ret, 0)
@@ -165,39 +160,31 @@ class TestRemoveFilesWhenCheckout(CheckoutBase):
class TestCheckoutCleanWorkingDir(CheckoutBase):
@patch('dvc.prompt.confirm', return_value=True)
def test(self, mock_prompt):
from tests.test_data_cloud import sleep
mock_prompt.return_value = True
stages = self.dvc.add(self.DATA_DIR)
stage = stages[0]
sleep()
working_dir_change = os.path.join(self.DATA_DIR, 'not_cached.txt')
with open(working_dir_change, 'w') as f:
f.write('not_cached')
sleep()
ret = main(['checkout', stage.relpath])
self.assertEqual(ret, 0)
self.assertFalse(os.path.exists(working_dir_change))
@patch('dvc.prompt.confirm', return_value=False)
def test_force(self, mock_prompt):
from tests.test_data_cloud import sleep
mock_prompt.return_value = False
stages = self.dvc.add(self.DATA_DIR)
self.assertEqual(len(stages), 1)
stage = stages[0]
sleep()
working_dir_change = os.path.join(self.DATA_DIR, 'not_cached.txt')
with open(working_dir_change, 'w') as f:
f.write('not_cached')
sleep()
ret = main(['checkout', stage.relpath])
self.assertNotEqual(ret, 0)
@@ -208,8 +195,6 @@ class TestCheckoutCleanWorkingDir(CheckoutBase):
class TestCheckoutSelectiveRemove(CheckoutBase):
def test(self):
from tests.test_data_cloud import sleep
# Use copy to test for changes in the inodes
ret = main(['config', 'cache.type', 'copy'])
self.assertEqual(ret, 0)
@@ -219,17 +204,11 @@ class TestCheckoutSelectiveRemove(CheckoutBase):
stage = stages[0]
staged_files = self.outs_info(stage)
sleep()
os.remove(staged_files[0].path)
sleep()
ret = main(['checkout', '--force', stage.relpath])
self.assertEqual(ret, 0)
sleep()
checkedout_files = self.outs_info(stage)
self.assertEqual(len(staged_files), len(checkedout_files))
-20
View File
@@ -2,7 +2,6 @@ from subprocess import CalledProcessError
from subprocess import check_output, Popen
from unittest import SkipTest
import os
import time
import uuid
import shutil
import getpass
@@ -151,15 +150,6 @@ def get_azure_url():
return 'azure://{}/{}'.format(container_name, str(uuid.uuid4()))
def sleep():
# Sleep some time to simulate realistic behavior.
# Some filesystems have a bad date resolution for
# mtime(i.e. 1sec for HFS) that cause problems with
# our 'state' system not being able to distinguish
# files that were modified within that delta.
time.sleep(1)
class TestDataCloud(TestDvc):
def _test_cloud(self, config, cl):
cloud = DataCloud(self.dvc, config=config)
@@ -242,7 +232,6 @@ class TestDataCloudBase(TestDvc):
with self.cloud.project.state:
# Check status
sleep()
status = self.cloud.status([info], show_checksums=True)
self.assertEqual([(md5, STATUS_NEW)], status)
@@ -257,7 +246,6 @@ class TestDataCloudBase(TestDvc):
self.cloud.push([info_dir])
self.assertTrue(os.path.isfile(cache_dir))
sleep()
status = self.cloud.status([info], show_checksums=True)
self.assertEqual([(md5, STATUS_OK)], status)
@@ -265,7 +253,6 @@ class TestDataCloudBase(TestDvc):
self.assertTrue((md5_dir, STATUS_OK) in status_dir)
# Remove and check status
sleep()
shutil.rmtree(self.dvc.cache.local.cache_dir)
status = self.cloud.status([info], show_checksums=True)
@@ -284,7 +271,6 @@ class TestDataCloudBase(TestDvc):
self.cloud.pull([info_dir])
self.assertTrue(os.path.isfile(cache_dir))
sleep()
status = self.cloud.status([info], show_checksums=True)
self.assertEqual([(md5, STATUS_OK)], status)
@@ -397,7 +383,6 @@ class TestDataCloudCLIBase(TestDvc):
cache_dir = stage_dir.outs[0].cache
# FIXME check status output
sleep()
self.main(['status', '-c', '--show-checksums'] + args)
self.main(['push'] + args)
@@ -405,12 +390,10 @@ class TestDataCloudCLIBase(TestDvc):
self.assertTrue(os.path.isfile(cache))
self.assertTrue(os.path.isfile(cache_dir))
sleep()
self.main(['status', '-c', '--show-checksums'] + args)
shutil.rmtree(self.dvc.cache.local.cache_dir)
sleep()
self.main(['status', '-c', '--show-checksums'] + args)
self.main(['fetch'] + args)
@@ -425,7 +408,6 @@ class TestDataCloudCLIBase(TestDvc):
self.assertTrue(os.path.isfile(self.FOO))
self.assertTrue(os.path.isdir(self.DATA_DIR))
sleep()
with open(cache, 'r') as fd:
self.assertEqual(fd.read(), self.FOO_CONTENTS)
self.assertTrue(os.path.isfile(cache_dir))
@@ -437,10 +419,8 @@ class TestDataCloudCLIBase(TestDvc):
shutil.move(self.dvc.cache.local.cache_dir,
self.dvc.cache.local.cache_dir + '.back')
sleep()
self.main(['fetch'] + args)
sleep()
self.main(['pull'] + args)
self.assertTrue(os.path.exists(cache))
self.assertTrue(os.path.isfile(cache))
-32
View File
@@ -26,7 +26,6 @@ from tests.basic_env import TestDvc
from tests.test_data_cloud import _should_test_aws, TEST_AWS_REPO_BUCKET
from tests.test_data_cloud import _should_test_gcp, TEST_GCP_REPO_BUCKET
from tests.test_data_cloud import _should_test_ssh, _should_test_hdfs
from tests.test_data_cloud import sleep
from tests.utils.httpd import StaticFileServer
@@ -64,8 +63,6 @@ class TestReproDepUnderDir(TestDvc):
self.dir_stage = stages[0]
self.assertTrue(self.dir_stage is not None)
sleep()
self.file1 = 'file1'
self.file1_stage = self.file1 + '.dvc'
self.dvc.run(fname=self.file1_stage,
@@ -80,8 +77,6 @@ class TestReproDepUnderDir(TestDvc):
os.unlink(self.DATA)
shutil.copyfile(self.FOO, self.DATA)
sleep()
stages = self.dvc.reproduce(self.file1_stage)
self.assertEqual(len(stages), 2)
self.assertTrue(filecmp.cmp(self.file1, self.FOO, shallow=False))
@@ -93,20 +88,14 @@ class TestReproDepDirWithOutputsUnderIt(TestDvc):
self.assertEqual(len(stages), 1)
self.assertTrue(stages[0] is not None)
sleep()
stages = self.dvc.add(self.DATA_SUB)
self.assertEqual(len(stages), 1)
self.assertTrue(stages[0] is not None)
sleep()
stage = self.dvc.run(fname='Dvcfile',
deps=[self.DATA, self.DATA_SUB])
self.assertTrue(stage is not None)
sleep()
file1 = 'file1'
file1_stage = file1 + '.dvc'
stage = self.dvc.run(fname=file1_stage,
@@ -117,13 +106,9 @@ class TestReproDepDirWithOutputsUnderIt(TestDvc):
file1))
self.assertTrue(stage is not None)
sleep()
os.unlink(self.DATA)
shutil.copyfile(self.FOO, self.DATA)
sleep()
stages = self.dvc.reproduce(file1_stage)
self.assertEqual(len(stages), 2)
@@ -287,8 +272,6 @@ class TestReproIgnoreBuildCache(TestDvc):
file2))
self.assertTrue(stage is not None)
sleep()
with open(code1, 'a') as fobj:
fobj.write('\n\n')
@@ -521,14 +504,10 @@ class TestReproChangedDirData(TestDvc):
dir_name = 'dir'
dir_code = 'dir_code.py'
sleep()
with open(dir_code, 'w+') as fd:
fd.write("import os; import sys; import shutil; "
"shutil.copytree(sys.argv[1], sys.argv[2])")
sleep()
stage = self.dvc.run(outs=[dir_name],
deps=[self.DATA_DIR, dir_code],
cmd="python {} {} {}".format(dir_code,
@@ -539,28 +518,21 @@ class TestReproChangedDirData(TestDvc):
stages = self.dvc.reproduce(stage.path)
self.assertEqual(len(stages), 0)
sleep()
with open(self.DATA_SUB, 'a') as fd:
fd.write('add')
sleep()
stages = self.dvc.reproduce(stage.path)
self.assertEqual(len(stages), 1)
self.assertTrue(stages[0] is not None)
sleep()
# Check that dvc indeed registers changed output dir
shutil.move(self.BAR, dir_name)
sleep()
stages = self.dvc.reproduce(stage.path)
self.assertEqual(len(stages), 1)
self.assertTrue(stages[0] is not None)
# Check that dvc registers mtime change for the directory.
System.hardlink(self.DATA_SUB, self.DATA_SUB + '.lnk')
sleep()
stages = self.dvc.reproduce(stage.path)
self.assertEqual(len(stages), 1)
self.assertTrue(stages[0] is not None)
@@ -685,8 +657,6 @@ class TestReproExternalBase(TestDvc):
self.write(self.bucket, foo_key, self.FOO_CONTENTS)
sleep()
import_stage = self.dvc.imp(out_foo_path, 'import')
self.assertTrue(os.path.exists('import'))
self.assertTrue(filecmp.cmp('import', self.FOO, shallow=False))
@@ -705,8 +675,6 @@ class TestReproExternalBase(TestDvc):
self.write(self.bucket, foo_key, self.BAR_CONTENTS)
sleep()
self.assertNotEqual(self.dvc.status(), {})
stages = self.dvc.reproduce(import_stage.path)
-8
View File
@@ -332,8 +332,6 @@ class TestRunUnprotectOutsHardlink(TestDvc):
class TestCmdRunOverwrite(TestDvc):
def test(self):
import time
ret = main(['run',
'-d', self.FOO,
'-d', self.CODE,
@@ -344,8 +342,6 @@ class TestCmdRunOverwrite(TestDvc):
stage_mtime = os.path.getmtime('out.dvc')
time.sleep(2)
ret = main(['run',
'-d', self.FOO,
'-d', self.CODE,
@@ -358,8 +354,6 @@ class TestCmdRunOverwrite(TestDvc):
self.assertEqual(stage_mtime, os.path.getmtime('out.dvc'))
stage_mtime = os.path.getmtime('out.dvc')
time.sleep(2)
ret = main(['run',
'-d', self.FOO,
'-d', self.CODE,
@@ -374,8 +368,6 @@ class TestCmdRunOverwrite(TestDvc):
self.assertNotEqual(stage_mtime, os.path.getmtime('out.dvc'))
stage_mtime = os.path.getmtime('out.dvc')
time.sleep(2)
ret = main(['run',
'--overwrite-dvcfile',
'-f', 'out.dvc',
+1 -9
View File
@@ -1,5 +1,4 @@
import os
import time
from dvc.state import State
from dvc.utils import file_md5
@@ -19,15 +18,8 @@ class TestState(TestDvc):
entry_md5 = state.update(path)
self.assertEqual(entry_md5, md5)
# Sleep some time to simulate realistic behavior.
# Some filesystems have a bad date resolution for
# mtime(i.e. 1sec for HFS) that cause problems with
# our 'state' system not being able to distinguish
# files that were modified within that delta.
time.sleep(1)
os.unlink(path)
with open(path, 'w+') as fd:
with open(path, 'a') as fd:
fd.write('1')
md5 = file_md5(path)[0]