异步优化写入备份
This commit is contained in:
		
							
								
								
									
										32
									
								
								tests/core/objects/test_backup_object.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										32
									
								
								tests/core/objects/test_backup_object.py
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,32 @@ | ||||
|  | ||||
| from core.objects.backup_object import BackupObject | ||||
| import tempfile | ||||
| import os | ||||
|  | ||||
|  | ||||
| class TestBackup(): | ||||
|     def createTempDataDir(self): | ||||
|         temp_data_dir = tempfile.TemporaryDirectory() | ||||
|         for i in range(100): | ||||
|             f = open(temp_data_dir.name + "/testFile" + str(i), "w") | ||||
|             f.write("test data"+str(i)) | ||||
|             f.close() | ||||
|         os.mkdir(temp_data_dir.name + "/testDir") | ||||
|         for i in range(100): | ||||
|             f = open(temp_data_dir.name + "/testDir/testFile" + str(i), "w") | ||||
|             f.write("test data1"*10000+str(i)) | ||||
|             f.close() | ||||
|         return temp_data_dir | ||||
|  | ||||
|     def test_BackupWriteBlob(self): | ||||
|         ''' | ||||
|         测试备份写入blob | ||||
|         ''' | ||||
|         with tempfile.TemporaryDirectory() as tmpdir: | ||||
|             temp_data_dir = self.createTempDataDir() | ||||
|             b = BackupObject("testBackup", tmpdir) | ||||
|             b.createNewBackup([temp_data_dir.name]) | ||||
|             b.backup() | ||||
|             temp_data_dir.cleanup() | ||||
|             assert os.path.exists(b.backup_path+"/objects") | ||||
|  | ||||
| @@ -1,3 +1,4 @@ | ||||
| import asyncio | ||||
| from core.objects.blob_object import BlobObject | ||||
| import hashlib | ||||
| import tempfile | ||||
| @@ -11,7 +12,8 @@ class Test_Blob: | ||||
|             newBlob.object_id | ||||
|             == hashlib.sha1(open("README.md", "rb").read()).hexdigest() | ||||
|         ) | ||||
|  | ||||
|     def test_writeBlob(self): | ||||
|         newBlob = BlobObject("README.md") | ||||
|         with tempfile.TemporaryDirectory() as tmpdirname: | ||||
|             newBlob.writeBlob(tmpdirname) | ||||
|             asyncio.run(newBlob.writeBlob(tmpdirname)) | ||||
		Reference in New Issue
	
	Block a user