Debian Codegraph @

tests/test-remotefilelog-cacheprocess.t

raw
1 #require no-windows
2
3 $ . "$TESTDIR/remotefilelog-library.sh"
4
5 $ hg init repo
6 $ cd repo
7 $ cat >> .hg/hgrc <<EOF
8 > [remotefilelog]
9 > server=True
10 > EOF
11 $ echo x > x
12 $ echo y > y
13 $ echo z > z
14 $ hg commit -qAm xy
15 $ cd ..
16
17 $ cat > cacheprocess-logger.py <<EOF
18 > import os
19 > import shutil
20 > import sys
21 > f = open('$TESTTMP/cachelog.log', 'w')
22 > srccache = os.path.join('$TESTTMP', 'oldhgcache')
23 > def log(message):
24 > f.write(message)
25 > f.flush()
26 > destcache = sys.argv[-1]
27 > try:
28 > while True:
29 > cmd = sys.stdin.readline().strip()
30 > log('got command %r\n' % cmd)
31 > if cmd == 'exit':
32 > sys.exit(0)
33 > elif cmd == 'get':
34 > count = int(sys.stdin.readline())
35 > log('client wants %r blobs\n' % count)
36 > wants = []
37 > for _ in range(count):
38 > key = sys.stdin.readline()[:-1]
39 > wants.append(key)
40 > if '\0' in key:
41 > _, key = key.split('\0')
42 > srcpath = os.path.join(srccache, key)
43 > if os.path.exists(srcpath):
44 > dest = os.path.join(destcache, key)
45 > destdir = os.path.dirname(dest)
46 > if not os.path.exists(destdir):
47 > os.makedirs(destdir)
48 > shutil.copyfile(srcpath, dest)
49 > else:
50 > # report a cache miss
51 > sys.stdout.write(key + '\n')
52 > sys.stdout.write('0\n')
53 > for key in sorted(wants):
54 > log('requested %r\n' % key)
55 > sys.stdout.flush()
56 > elif cmd == 'set':
57 > raise Exception('todo writing')
58 > else:
59 > raise Exception('unknown command! %r' % cmd)
60 > except Exception as e:
61 > log('Exception! %s\n' % e)
62 > raise
63 > EOF
64
65 $ cat >> $HGRCPATH <<EOF
66 > [remotefilelog]
67 > cacheprocess = "$PYTHON" $TESTTMP/cacheprocess-logger.py
68 > EOF
69
70 Test cache keys and cache misses.
71 $ hgcloneshallow ssh://user@dummy/repo clone -q
72 3 files fetched over 1 fetches - (3 misses, 0.00% hit ratio) over *s (glob)
73 $ cat cachelog.log
74 got command 'get'
75 client wants 3 blobs
76 requested 'master/11/f6ad8ec52a2984abaafd7c3b516503785c2072/1406e74118627694268417491f018a4a883152f0'
77 requested 'master/39/5df8f7c51f007019cb30201c49e884b46b92fa/69a1b67522704ec122181c0890bd16e9d3e7516a'
78 requested 'master/95/cb0bfd2977c761298d9624e4b4d4c72a39974a/076f5e2225b3ff0400b98c92aa6cdf403ee24cca'
79 got command 'set'
80 Exception! todo writing
81
82 Test cache hits.
83 $ mv hgcache oldhgcache
84 $ rm cachelog.log
85 $ hgcloneshallow ssh://user@dummy/repo clone-cachehit -q
86 3 files fetched over 1 fetches - (0 misses, 100.00% hit ratio) over *s (glob)
87 $ cat cachelog.log | grep -v exit
88 got command 'get'
89 client wants 3 blobs
90 requested 'master/11/f6ad8ec52a2984abaafd7c3b516503785c2072/1406e74118627694268417491f018a4a883152f0'
91 requested 'master/39/5df8f7c51f007019cb30201c49e884b46b92fa/69a1b67522704ec122181c0890bd16e9d3e7516a'
92 requested 'master/95/cb0bfd2977c761298d9624e4b4d4c72a39974a/076f5e2225b3ff0400b98c92aa6cdf403ee24cca'
93
94 $ cat >> $HGRCPATH <<EOF
95 > [remotefilelog]
96 > cacheprocess.includepath = yes
97 > EOF
98
99 Test cache keys and cache misses with includepath.
100 $ rm -r hgcache oldhgcache
101 $ rm cachelog.log
102 $ hgcloneshallow ssh://user@dummy/repo clone-withpath -q
103 3 files fetched over 1 fetches - (3 misses, 0.00% hit ratio) over *s (glob)
104 $ cat cachelog.log
105 got command 'get'
106 client wants 3 blobs
107 requested 'x\x00master/11/f6ad8ec52a2984abaafd7c3b516503785c2072/1406e74118627694268417491f018a4a883152f0'
108 requested 'y\x00master/95/cb0bfd2977c761298d9624e4b4d4c72a39974a/076f5e2225b3ff0400b98c92aa6cdf403ee24cca'
109 requested 'z\x00master/39/5df8f7c51f007019cb30201c49e884b46b92fa/69a1b67522704ec122181c0890bd16e9d3e7516a'
110 got command 'set'
111 Exception! todo writing
112
113 Test cache hits with includepath.
114 $ mv hgcache oldhgcache
115 $ rm cachelog.log
116 $ hgcloneshallow ssh://user@dummy/repo clone-withpath-cachehit -q
117 3 files fetched over 1 fetches - (0 misses, 100.00% hit ratio) over *s (glob)
118 $ cat cachelog.log | grep -v exit
119 got command 'get'
120 client wants 3 blobs
121 requested 'x\x00master/11/f6ad8ec52a2984abaafd7c3b516503785c2072/1406e74118627694268417491f018a4a883152f0'
122 requested 'y\x00master/95/cb0bfd2977c761298d9624e4b4d4c72a39974a/076f5e2225b3ff0400b98c92aa6cdf403ee24cca'
123 requested 'z\x00master/39/5df8f7c51f007019cb30201c49e884b46b92fa/69a1b67522704ec122181c0890bd16e9d3e7516a'