tests/test-remotefilelog-cacheprocess.t
branchstable
changeset 41290 593718ff5844
parent 41254 2888d12b80a6
child 41476 fd2f1f0071b9
equal deleted inserted replaced
41146:fbd168455b26 41290:593718ff5844
       
     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   > if sys.version_info[0] > 2:
       
    22   >     xrange = range
       
    23   > f = open('$TESTTMP/cachelog.log', 'w')
       
    24   > srccache = os.path.join('$TESTTMP', 'oldhgcache')
       
    25   > def log(message):
       
    26   >     f.write(message)
       
    27   >     f.flush()
       
    28   > destcache = sys.argv[-1]
       
    29   > try:
       
    30   >     while True:
       
    31   >         cmd = sys.stdin.readline().strip()
       
    32   >         log('got command %r\n' % cmd)
       
    33   >         if cmd == 'exit':
       
    34   >             sys.exit(0)
       
    35   >         elif cmd == 'get':
       
    36   >             count = int(sys.stdin.readline())
       
    37   >             log('client wants %r blobs\n' % count)
       
    38   >             wants = []
       
    39   >             for _ in xrange(count):
       
    40   >                 key = sys.stdin.readline()[:-1]
       
    41   >                 wants.append(key)
       
    42   >                 if '\0' in key:
       
    43   >                     _, key = key.split('\0')
       
    44   >                 srcpath = os.path.join(srccache, key)
       
    45   >                 if os.path.exists(srcpath):
       
    46   >                     dest = os.path.join(destcache, key)
       
    47   >                     destdir = os.path.dirname(dest)
       
    48   >                     if not os.path.exists(destdir):
       
    49   >                         os.makedirs(destdir)
       
    50   >                     shutil.copyfile(srcpath, dest)
       
    51   >                 else:
       
    52   >                     # report a cache miss
       
    53   >                     sys.stdout.write(key + '\n')
       
    54   >             sys.stdout.write('0\n')
       
    55   >             for key in sorted(wants):
       
    56   >                 log('requested %r\n' % key)
       
    57   >             sys.stdout.flush()
       
    58   >         elif cmd == 'set':
       
    59   >             assert False, 'todo writing'
       
    60   >         else:
       
    61   >             assert False, 'unknown command! %r' % cmd
       
    62   > except Exception as e:
       
    63   >     log('Exception! %r\n' % e)
       
    64   >     raise
       
    65   > EOF
       
    66 
       
    67   $ cat >> $HGRCPATH <<EOF
       
    68   > [remotefilelog]
       
    69   > cacheprocess = python $TESTTMP/cacheprocess-logger.py
       
    70   > EOF
       
    71 
       
    72 Test cache keys and cache misses.
       
    73   $ hgcloneshallow ssh://user@dummy/repo clone -q
       
    74   3 files fetched over 1 fetches - (3 misses, 0.00% hit ratio) over *s (glob)
       
    75   $ cat cachelog.log
       
    76   got command 'get'
       
    77   client wants 3 blobs
       
    78   requested 'master/11/f6ad8ec52a2984abaafd7c3b516503785c2072/1406e74118627694268417491f018a4a883152f0'
       
    79   requested 'master/39/5df8f7c51f007019cb30201c49e884b46b92fa/69a1b67522704ec122181c0890bd16e9d3e7516a'
       
    80   requested 'master/95/cb0bfd2977c761298d9624e4b4d4c72a39974a/076f5e2225b3ff0400b98c92aa6cdf403ee24cca'
       
    81   got command 'set'
       
    82   Exception! AssertionError('todo writing',)
       
    83 
       
    84 Test cache hits.
       
    85   $ mv hgcache oldhgcache
       
    86   $ rm cachelog.log
       
    87   $ hgcloneshallow ssh://user@dummy/repo clone-cachehit -q
       
    88   3 files fetched over 1 fetches - (0 misses, 100.00% hit ratio) over *s (glob)
       
    89   $ cat cachelog.log | grep -v exit
       
    90   got command 'get'
       
    91   client wants 3 blobs
       
    92   requested 'master/11/f6ad8ec52a2984abaafd7c3b516503785c2072/1406e74118627694268417491f018a4a883152f0'
       
    93   requested 'master/39/5df8f7c51f007019cb30201c49e884b46b92fa/69a1b67522704ec122181c0890bd16e9d3e7516a'
       
    94   requested 'master/95/cb0bfd2977c761298d9624e4b4d4c72a39974a/076f5e2225b3ff0400b98c92aa6cdf403ee24cca'
       
    95 
       
    96   $ cat >> $HGRCPATH <<EOF
       
    97   > [remotefilelog]
       
    98   > cacheprocess.includepath = yes
       
    99   > EOF
       
   100 
       
   101 Test cache keys and cache misses with includepath.
       
   102   $ rm -r hgcache oldhgcache
       
   103   $ rm cachelog.log
       
   104   $ hgcloneshallow ssh://user@dummy/repo clone-withpath -q
       
   105   3 files fetched over 1 fetches - (3 misses, 0.00% hit ratio) over *s (glob)
       
   106   $ cat cachelog.log
       
   107   got command 'get'
       
   108   client wants 3 blobs
       
   109   requested 'x\x00master/11/f6ad8ec52a2984abaafd7c3b516503785c2072/1406e74118627694268417491f018a4a883152f0'
       
   110   requested 'y\x00master/95/cb0bfd2977c761298d9624e4b4d4c72a39974a/076f5e2225b3ff0400b98c92aa6cdf403ee24cca'
       
   111   requested 'z\x00master/39/5df8f7c51f007019cb30201c49e884b46b92fa/69a1b67522704ec122181c0890bd16e9d3e7516a'
       
   112   got command 'set'
       
   113   Exception! AssertionError('todo writing',)
       
   114 
       
   115 Test cache hits with includepath.
       
   116   $ mv hgcache oldhgcache
       
   117   $ rm cachelog.log
       
   118   $ hgcloneshallow ssh://user@dummy/repo clone-withpath-cachehit -q
       
   119   3 files fetched over 1 fetches - (0 misses, 100.00% hit ratio) over *s (glob)
       
   120   $ cat cachelog.log | grep -v exit
       
   121   got command 'get'
       
   122   client wants 3 blobs
       
   123   requested 'x\x00master/11/f6ad8ec52a2984abaafd7c3b516503785c2072/1406e74118627694268417491f018a4a883152f0'
       
   124   requested 'y\x00master/95/cb0bfd2977c761298d9624e4b4d4c72a39974a/076f5e2225b3ff0400b98c92aa6cdf403ee24cca'
       
   125   requested 'z\x00master/39/5df8f7c51f007019cb30201c49e884b46b92fa/69a1b67522704ec122181c0890bd16e9d3e7516a'