Patchwork D1849: lfs: remove internal url in test

login
register
mail settings
Submitter phabricator
Date Jan. 11, 2018, 5:27 a.m.
Message ID <differential-rev-PHID-DREV-lqvnoqt25wzkxrhczrc3-req@phab.mercurial-scm.org>
Download mbox | patch
Permalink /patch/26679/
State Superseded
Headers show

Comments

phabricator - Jan. 11, 2018, 5:27 a.m.
quark created this revision.
Herald added a subscriber: mercurial-devel.
Herald added a reviewer: hg-reviewers.

REVISION SUMMARY
  `test-lfs-test-server.t` refers to a FB internal domain and requires certain
  implementation (ex. set error code to 404) at that endpoint. Without any
  workaround, It should in theory error out like "Domain cannot be resolved".
  I don't know how Matt Harbison ran the test.
  
  This patch changes the test to only depend on `lfs-test-server`.
  Unfortunately the logic has to be changed since `lfs-test-server` does not
  set error code to 404 but just removes "download" from "actions".

REPOSITORY
  rHG Mercurial

REVISION DETAIL
  https://phab.mercurial-scm.org/D1849

AFFECTED FILES
  hgext/lfs/blobstore.py
  tests/test-lfs-test-server.t

CHANGE DETAILS




To: quark, #hg-reviewers
Cc: mercurial-devel
phabricator - Jan. 11, 2018, 6:04 a.m.
mharbison72 added a comment.


  Yeah, I’ve been ignoring this failure. I thought I mentioned it back when this was first brought over. I’m assuming that FB will start using the built in extension and tests soon, and I didn’t want to drop test coverage on you like that.  Thanks for fixing it.

INLINE COMMENTS

> blobstore.py:239
>                  p = ptrmap.get(response['oid'], None)
> -                if error['code'] == 404 and p:
> -                    filename = getattr(p, 'filename', 'unknown')

It looks like we still need the ‘if p’ test.

REPOSITORY
  rHG Mercurial

REVISION DETAIL
  https://phab.mercurial-scm.org/D1849

To: quark, #hg-reviewers
Cc: mharbison72, mercurial-devel
phabricator - Jan. 16, 2018, 8:15 p.m.
quark added inline comments.

INLINE COMMENTS

> mharbison72 wrote in blobstore.py:239
> It looks like we still need the ‘if p’ test.

Sorry. I missed the comment. Fixed now.

REPOSITORY
  rHG Mercurial

REVISION DETAIL
  https://phab.mercurial-scm.org/D1849

To: quark, #hg-reviewers
Cc: mharbison72, mercurial-devel
phabricator - Jan. 17, 2018, 3:01 a.m.
mharbison72 added a comment.


  LGTM, thanks.
  
  Any thoughts on what we should do if 'p' does come up None?  It's a clear server error (sending back an oid we didn't ask for).

REPOSITORY
  rHG Mercurial

REVISION DETAIL
  https://phab.mercurial-scm.org/D1849

To: quark, #hg-reviewers
Cc: mharbison72, mercurial-devel
phabricator - Jan. 17, 2018, 11 p.m.
quark added a comment.


  In https://phab.mercurial-scm.org/D1849#31622, @mharbison72 wrote:
  
  > LGTM, thanks.
  >
  > Any thoughts on what we should do if 'p' does come up None?  It's a clear server error (sending back an oid we didn't ask for).
  
  
  Not sure. Blame the server somehow?

REPOSITORY
  rHG Mercurial

REVISION DETAIL
  https://phab.mercurial-scm.org/D1849

To: quark, #hg-reviewers, yuja
Cc: mharbison72, mercurial-devel

Patch

diff --git a/tests/test-lfs-test-server.t b/tests/test-lfs-test-server.t
--- a/tests/test-lfs-test-server.t
+++ b/tests/test-lfs-test-server.t
@@ -160,12 +160,12 @@ 
   $ rm -rf .hg/store/lfs
   $ rm -rf `hg config lfs.usercache`
   $ hg update -C '.^'
-  abort: LFS server claims required objects do not exist:
-  8e6ea5f6c066b44a0efa43bcce86aea73f17e6e23f0663df0251e7524e140a13!
+  abort: LFS server error. Remote object for "b" not found:(.*)! (re)
   [255]
 
 Check error message when object does not exist:
 
+  $ cd $TESTTMP
   $ hg init test && cd test
   $ echo "[extensions]" >> .hg/hgrc
   $ echo "lfs=" >> .hg/hgrc
@@ -183,7 +183,22 @@ 
   x-is-binary 0
   $ cd ..
   $ rm -rf `hg config lfs.usercache`
-  $ hg --config 'lfs.url=https://dewey-lfs.vip.facebook.com/lfs' clone test test2
+
+(Restart the server in a different location so it no longer has the content)
+
+  $ $PYTHON $RUNTESTDIR/killdaemons.py $DAEMON_PIDS
+  $ rm $DAEMON_PIDS
+  $ mkdir $TESTTMP/lfs-server2
+  $ cd $TESTTMP/lfs-server2
+#if no-windows
+  $ lfs-test-server &> lfs-server.log &
+  $ echo $! >> $DAEMON_PIDS
+#else
+  $ $PYTHON $TESTTMP/spawn.py >> $DAEMON_PIDS
+#endif
+
+  $ cd $TESTTMP
+  $ hg clone test test2
   updating to branch default
   abort: LFS server error. Remote object for "a" not found:(.*)! (re)
   [255]
diff --git a/hgext/lfs/blobstore.py b/hgext/lfs/blobstore.py
--- a/hgext/lfs/blobstore.py
+++ b/hgext/lfs/blobstore.py
@@ -227,20 +227,26 @@ 
                                  % rawjson)
         return response
 
-    def _checkforservererror(self, pointers, responses):
+    def _checkforservererror(self, pointers, responses, action):
         """Scans errors from objects
 
         Returns LfsRemoteError if any objects has an error"""
         for response in responses:
-            error = response.get('error')
-            if error:
+            # The server should return 404 when objects cannot be found. Some
+            # server implementation (ex. lfs-test-server)  does not set "error"
+            # but just removes "download" from "actions". Treat that case
+            # as the same as 404 error.
+            notfound = (response.get('error', {}).get('code') == 404
+                        or (action == 'download'
+                            and action not in response.get('actions', [])))
+            if notfound:
                 ptrmap = {p.oid(): p for p in pointers}
                 p = ptrmap.get(response['oid'], None)
-                if error['code'] == 404 and p:
-                    filename = getattr(p, 'filename', 'unknown')
-                    raise LfsRemoteError(
-                        _(('LFS server error. Remote object '
-                          'for "%s" not found: %r')) % (filename, response))
+                filename = getattr(p, 'filename', 'unknown')
+                raise LfsRemoteError(
+                    _(('LFS server error. Remote object '
+                      'for "%s" not found: %r')) % (filename, response))
+            if 'error' in response:
                 raise LfsRemoteError(_('LFS server error: %r') % response)
 
     def _extractobjects(self, response, pointers, action):
@@ -252,21 +258,11 @@ 
         """
         # Scan errors from objects - fail early
         objects = response.get('objects', [])
-        self._checkforservererror(pointers, objects)
+        self._checkforservererror(pointers, objects, action)
 
         # Filter objects with given action. Practically, this skips uploading
         # objects which exist in the server.
         filteredobjects = [o for o in objects if action in o.get('actions', [])]
-        # But for downloading, we want all objects. Therefore missing objects
-        # should be considered an error.
-        if action == 'download':
-            if len(filteredobjects) < len(objects):
-                missing = [o.get('oid', '?')
-                           for o in objects
-                           if action not in o.get('actions', [])]
-                raise LfsRemoteError(
-                    _('LFS server claims required objects do not exist:\n%s')
-                    % '\n'.join(missing))
 
         return filteredobjects