|
3 | 3 | from tasks.cephfs.fuse_mount import FuseMount |
4 | 4 | from tasks.cephfs.cephfs_test_case import CephFSTestCase |
5 | 5 | from teuthology.exceptions import CommandFailedError |
| 6 | +from textwrap import dedent |
6 | 7 | import errno |
7 | 8 | import platform |
8 | 9 | import time |
@@ -236,35 +237,62 @@ def test_fs_lsflags(self): |
236 | 237 | self.assertEqual(lsflags["allow_multimds_snaps"], True) |
237 | 238 | self.assertEqual(lsflags["allow_standby_replay"], True) |
238 | 239 |
|
239 | | - def test_filesystem_sync_stuck_for_around_5s(self): |
240 | | - """ |
241 | | - To check whether the fsync will be stuck to wait for the mdlog to be |
242 | | - flushed for at most 5 seconds. |
243 | | - """ |
244 | | - |
245 | | - dir_path = "fsync_do_not_wait_mdlog_testdir" |
| 240 | + def _test_sync_stuck_for_around_5s(self, dir_path, file_sync=False): |
246 | 241 | self.mount_a.run_shell(["mkdir", dir_path]) |
247 | 242 |
|
| 243 | + sync_dir_pyscript = dedent(""" |
| 244 | + import os |
| 245 | +
|
| 246 | + path = "{path}" |
| 247 | + dfd = os.open(path, os.O_DIRECTORY) |
| 248 | + os.fsync(dfd) |
| 249 | + os.close(dfd) |
| 250 | + """.format(path=dir_path)) |
| 251 | + |
248 | 252 | # run create/delete directories and test the sync time duration |
249 | 253 | for i in range(300): |
250 | 254 | for j in range(5): |
251 | 255 | self.mount_a.run_shell(["mkdir", os.path.join(dir_path, f"{i}_{j}")]) |
252 | 256 | start = time.time() |
253 | | - self.mount_a.run_shell(["sync"]) |
| 257 | + if file_sync: |
| 258 | + self.mount_a.run_shell(['python3', '-c', sync_dir_pyscript]) |
| 259 | + else: |
| 260 | + self.mount_a.run_shell(["sync"]) |
254 | 261 | duration = time.time() - start |
255 | | - log.info(f"mkdir i = {i}, duration = {duration}") |
| 262 | + log.info(f"sync mkdir i = {i}, duration = {duration}") |
256 | 263 | self.assertLess(duration, 4) |
257 | 264 |
|
258 | 265 | for j in range(5): |
259 | 266 | self.mount_a.run_shell(["rm", "-rf", os.path.join(dir_path, f"{i}_{j}")]) |
260 | 267 | start = time.time() |
261 | | - self.mount_a.run_shell(["sync"]) |
| 268 | + if file_sync: |
| 269 | + self.mount_a.run_shell(['python3', '-c', sync_dir_pyscript]) |
| 270 | + else: |
| 271 | + self.mount_a.run_shell(["sync"]) |
262 | 272 | duration = time.time() - start |
263 | | - log.info(f"rmdir i = {i}, duration = {duration}") |
| 273 | + log.info(f"sync rmdir i = {i}, duration = {duration}") |
264 | 274 | self.assertLess(duration, 4) |
265 | 275 |
|
266 | 276 | self.mount_a.run_shell(["rm", "-rf", dir_path]) |
267 | 277 |
|
| 278 | + def test_filesystem_sync_stuck_for_around_5s(self): |
| 279 | + """ |
| 280 | + To check whether the fsync will be stuck to wait for the mdlog to be |
| 281 | + flushed for at most 5 seconds. |
| 282 | + """ |
| 283 | + |
| 284 | + dir_path = "filesystem_sync_do_not_wait_mdlog_testdir" |
| 285 | + self._test_sync_stuck_for_around_5s(dir_path) |
| 286 | + |
| 287 | + def test_file_sync_stuck_for_around_5s(self): |
| 288 | + """ |
| 289 | + To check whether the filesystem sync will be stuck to wait for the |
| 290 | + mdlog to be flushed for at most 5 seconds. |
| 291 | + """ |
| 292 | + |
| 293 | + dir_path = "file_sync_do_not_wait_mdlog_testdir" |
| 294 | + self._test_sync_stuck_for_around_5s(dir_path, True) |
| 295 | + |
268 | 296 |
|
269 | 297 | class TestCacheDrop(CephFSTestCase): |
270 | 298 | CLIENTS_REQUIRED = 1 |
|
0 commit comments