def test_two_downloaders(self): """两个downloader同时跑,但是store的目录不一样。""" oss2.defaults.multiget_threshold = 1 oss2.defaults.multiget_part_size = 100 oss2.defaults.multiget_num_threads = 2 store1 = oss2.make_download_store() store2 = oss2.make_download_store(dir='.another-py-oss-download') file_size = 1000 key, filename, content = self.__prepare(file_size) context1a = {} context1b = {} context2 = {} def mock_rename(src, dst, ctx=None, store=None): r = self.__record(key, filename, store=store) ctx['tmp_suffix'] = r['tmp_suffix'] ctx['etag'] = r['etag'] ctx['mtime'] = r['mtime'] raise RuntimeError('intentional') with patch.object(os, 'rename', side_effect=partial(mock_rename, ctx=context1a, store=store1), autospect=True): self.assertRaises(RuntimeError, oss2.resumable_download, self.bucket, key, filename, store=store1) with patch.object(os, 'rename', side_effect=partial(mock_rename, ctx=context1b, store=store1), autospect=True): self.assertRaises(RuntimeError, oss2.resumable_download, self.bucket, key, filename, store=store1) with patch.object(os, 'rename', side_effect=partial(mock_rename, ctx=context2, store=store2), autospect=True): self.assertRaises(RuntimeError, oss2.resumable_download, self.bucket, key, filename, store=store2) self.assertEqual(context1a['tmp_suffix'], context1b['tmp_suffix']) self.assertEqual(context1a['etag'], context1b['etag']) self.assertEqual(context1a['mtime'], context1b['mtime']) self.assertNotEqual(context1a['tmp_suffix'], context2['tmp_suffix']) self.assertEqual(context1a['etag'], context2['etag']) self.assertEqual(context1a['mtime'], context2['mtime']) self.assertTrue(os.path.exists(filename + context1a['tmp_suffix'])) self.assertTrue(os.path.exists(filename + context2['tmp_suffix'])) oss2.resumable_download(self.bucket, key, filename, store=store1) self.assertTrue(not os.path.exists(filename + context1a['tmp_suffix'])) self.assertTrue(os.path.exists(filename + context2['tmp_suffix'])) oss2.resumable_download(self.bucket, key, filename, store=store2) self.assertTrue(not os.path.exists(filename + context2['tmp_suffix']))