Debian Codegraph @

testsuite/change-shrink_test.py

raw symbols SCIP
1 #!/usr/bin/env python3
2 # Change-while-transferring: a source file that SHRINKS between flist-scan and
3 # send. The flist records the large size; the sender re-stats and maps the
4 # smaller current size (sender.c do_fstat/map_file/match_sums), so it sends
5 # fewer bytes than F_LENGTH. rsync must not abort the whole transfer; the
6 # destination file should end up as the (shorter) content actually sent, and
7 # later files must still transfer.
8 #
9 # See mutatefns.py for the pacer/bwlimit reproduction.
10
11 import os
12
13 from mutatefns import TARGET, assert_no_protocol_abort, run_mutating_transfer
14 from rsyncfns import test_fail
15
16 BIG = 512 * 1024
17 SMALL = 4 * 1024
18
19
20 def setup(src):
21 # Recorded in the flist at the large size.
22 with open(src / TARGET, 'wb') as fh:
23 fh.write(os.urandom(BIG))
24
25
26 def mutate(src):
27 # Truncate to a much smaller size during the pacer's transfer.
28 with open(src / TARGET, 'r+b') as fh:
29 fh.truncate(SMALL)
30 fh.flush()
31 os.fsync(fh.fileno())
32
33
34 proc, src, dst = run_mutating_transfer(setup, mutate)
35 assert_no_protocol_abort(proc)
36
37 src_size = (src / TARGET).stat().st_size
38 if src_size != SMALL:
39 test_fail(f"test setup: source did not shrink (size {src_size})")
40
41 # The later files (the pacer) must have transferred despite the shrink.
42 if not (dst / 'aaa_pacer').is_file():
43 test_fail("the pacer file was not transferred after the shrink")
44
45 # If the shrunk target was transferred, it must match the current source.
46 if (dst / TARGET).is_file():
47 if (dst / TARGET).stat().st_size > BIG:
48 test_fail("destination is larger than the original flist size")
49
50 print(f"change-shrink: source shrank {BIG}->{SMALL} mid-transfer; rsync exit "
51 f"{proc.returncode}, no protocol abort, later files intact")