sapling/eden/hg-server/tests/test-fb-hgext-extutil.py
Durham Goode 98d9269874 server: copy hg to a new hg-server directory
Summary:
Create a fork of the Mercurial code that we can use to build server
rpms. The hg servers will continue to exist for a few more months while we move
the darkstorm and ediscovery use cases off them. In the mean time, we want to
start making breaking changes to the client, so let's create a stable copy of
the hg code to produce rpms for the hg servers.

The fork is based off c7770c78d, the latest hg release.

This copies the files as is, then adds some minor tweaks to get it to build:
- Disables some lint checks that appear to be bypassed by path
- sed replace eden/scm with eden/hg-server
- Removed a dependency on scm/telemetry from the edenfs-client tests since
  scm/telemetry pulls in the original eden/scm/lib/configparser which conflicts
  with the hg-server conflict parser.

allow-large-files

Reviewed By: quark-zju

Differential Revision: D27632557

fbshipit-source-id: b2f442f4ec000ea08e4d62de068750832198e1f4
2021-04-09 10:09:06 -07:00

93 lines
2.9 KiB
Python

# Copyright 2004-present Facebook. All Rights Reserved.
from __future__ import absolute_import
import errno
import os
import time
import unittest
import silenttestrunner
from edenscm.hgext import extutil
from edenscm.mercurial import error, util, vfs
from hghave import require
locktimeout = 25
locksuccess = 24
def _exitstatus(code):
"""convert a posix exit status into the same form returned by
os.spawnv
returns None if the process was stopped instead of exiting"""
if os.WIFEXITED(code):
return os.WEXITSTATUS(code)
elif os.WIFSIGNALED(code):
return -(os.WTERMSIG(code))
class ExtutilTests(unittest.TestCase):
def testspawndetachednoblock(self):
"""spawndetached() should return without waiting for the process to
finish."""
start = time.time()
util.spawndetached(["sleep", "5"])
end = time.time()
if end - start >= 1.0:
self.fail(
"spawndetached() took took %s seconds, should have "
"returned immediately" % (end - start)
)
def testspawndetachedfailure1(self):
"""spawndetached() should throw if executing the process fails."""
try:
util.spawndetached(["no_such_program", "arg1", "arg2"])
self.fail("expected spawndetached to fail with ENOENT")
except (OSError, IOError) as ex:
self.assertEqual(ex.errno, errno.ENOENT)
def testspawndetachedfailure2(self):
"""spawndetached() should throw if executing the process fails."""
try:
util.spawndetached([os.devnull, "arg1", "arg2"])
self.fail("expected spawndetached to fail with EACCES")
except (OSError, IOError) as ex:
self.assertEqual(ex.errno, errno.EACCES)
def testflock(self):
testtmp = os.environ["TESTTMP"]
opener = vfs.vfs(testtmp)
name = "testlock"
with extutil.flock(opener.join(name), "testing a lock", timeout=0):
otherlock = self.otherprocesslock(opener, name)
self.assertEqual(
otherlock, locktimeout, "other process should not have taken the lock"
)
otherlock = self.otherprocesslock(opener, name)
self.assertEqual(
otherlock, locksuccess, "other process should have taken the lock"
)
def otherprocesslock(self, opener, name):
pid = os.fork()
if pid == 0:
try:
with extutil.flock(opener.join(name), "other process lock", timeout=0):
os._exit(locksuccess)
except error.LockHeld:
os._exit(locktimeout)
else:
time.sleep(0.1) # Avoids a crash on OSX
p, st = os.waitpid(pid, 0)
st = _exitstatus(st) # Convert back to an int
return st
if __name__ == "__main__":
silenttestrunner.main(__name__)