2017-04-11 21:25:40 +03:00
|
|
|
# Copyright 2004-present Facebook. All Rights Reserved.
|
|
|
|
|
2019-05-21 19:06:46 +03:00
|
|
|
from __future__ import absolute_import
|
|
|
|
|
2017-04-11 21:25:40 +03:00
|
|
|
import errno
|
|
|
|
import os
|
|
|
|
import time
|
|
|
|
import unittest
|
|
|
|
|
|
|
|
import silenttestrunner
|
2019-01-30 03:25:33 +03:00
|
|
|
from edenscm.hgext import extutil
|
2020-09-01 03:32:44 +03:00
|
|
|
from edenscm.mercurial import error, util, vfs
|
2020-01-31 11:16:29 +03:00
|
|
|
from hghave import require
|
2020-01-31 05:40:49 +03:00
|
|
|
|
|
|
|
|
2017-11-30 01:57:10 +03:00
|
|
|
locktimeout = 25
|
|
|
|
locksuccess = 24
|
|
|
|
|
codemod: join the auto-formatter party
Summary:
Turned on the auto formatter. Ran `arc lint --apply-patches --take BLACK **/*.py`.
Then run `arc lint` again so some other autofixers like spellchecker etc. looked
at the code base. Manually accept the changes whenever they make sense, or use
a workaround (ex. changing "dict()" to "dict constructor") where autofix is false
positive. Disabled linters on files that are hard (i18n/polib.py) to fix, or less
interesting to fix (hgsubversion tests), or cannot be fixed without breaking
OSS build (FBPYTHON4).
Conflicted linters (test-check-module-imports.t, part of test-check-code.t,
test-check-pyflakes.t) are removed or disabled.
Duplicated linters (test-check-pyflakes.t, test-check-pylint.t) are removed.
An issue of the auto-formatter is lines are no longer guarnateed to be <= 80
chars. But that seems less important comparing with the benefit auto-formatter
provides.
As we're here, also remove test-check-py3-compat.t, as it is currently broken
if `PYTHON3=/bin/python3` is set.
Reviewed By: wez, phillco, simpkins, pkaush, singhsrb
Differential Revision: D8173629
fbshipit-source-id: 90e248ae0c5e6eaadbe25520a6ee42d32005621b
2018-05-26 07:34:37 +03:00
|
|
|
|
2020-06-24 04:45:45 +03:00
|
|
|
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))
|
|
|
|
|
|
|
|
|
2017-04-11 21:25:40 +03:00
|
|
|
class ExtutilTests(unittest.TestCase):
|
2020-09-01 03:32:44 +03:00
|
|
|
def testspawndetachednoblock(self):
|
|
|
|
"""spawndetached() should return without waiting for the process to
|
codemod: join the auto-formatter party
Summary:
Turned on the auto formatter. Ran `arc lint --apply-patches --take BLACK **/*.py`.
Then run `arc lint` again so some other autofixers like spellchecker etc. looked
at the code base. Manually accept the changes whenever they make sense, or use
a workaround (ex. changing "dict()" to "dict constructor") where autofix is false
positive. Disabled linters on files that are hard (i18n/polib.py) to fix, or less
interesting to fix (hgsubversion tests), or cannot be fixed without breaking
OSS build (FBPYTHON4).
Conflicted linters (test-check-module-imports.t, part of test-check-code.t,
test-check-pyflakes.t) are removed or disabled.
Duplicated linters (test-check-pyflakes.t, test-check-pylint.t) are removed.
An issue of the auto-formatter is lines are no longer guarnateed to be <= 80
chars. But that seems less important comparing with the benefit auto-formatter
provides.
As we're here, also remove test-check-py3-compat.t, as it is currently broken
if `PYTHON3=/bin/python3` is set.
Reviewed By: wez, phillco, simpkins, pkaush, singhsrb
Differential Revision: D8173629
fbshipit-source-id: 90e248ae0c5e6eaadbe25520a6ee42d32005621b
2018-05-26 07:34:37 +03:00
|
|
|
finish."""
|
2017-04-11 21:25:40 +03:00
|
|
|
start = time.time()
|
2020-09-01 03:32:44 +03:00
|
|
|
util.spawndetached(["sleep", "5"])
|
2017-04-11 21:25:40 +03:00
|
|
|
end = time.time()
|
|
|
|
if end - start >= 1.0:
|
codemod: join the auto-formatter party
Summary:
Turned on the auto formatter. Ran `arc lint --apply-patches --take BLACK **/*.py`.
Then run `arc lint` again so some other autofixers like spellchecker etc. looked
at the code base. Manually accept the changes whenever they make sense, or use
a workaround (ex. changing "dict()" to "dict constructor") where autofix is false
positive. Disabled linters on files that are hard (i18n/polib.py) to fix, or less
interesting to fix (hgsubversion tests), or cannot be fixed without breaking
OSS build (FBPYTHON4).
Conflicted linters (test-check-module-imports.t, part of test-check-code.t,
test-check-pyflakes.t) are removed or disabled.
Duplicated linters (test-check-pyflakes.t, test-check-pylint.t) are removed.
An issue of the auto-formatter is lines are no longer guarnateed to be <= 80
chars. But that seems less important comparing with the benefit auto-formatter
provides.
As we're here, also remove test-check-py3-compat.t, as it is currently broken
if `PYTHON3=/bin/python3` is set.
Reviewed By: wez, phillco, simpkins, pkaush, singhsrb
Differential Revision: D8173629
fbshipit-source-id: 90e248ae0c5e6eaadbe25520a6ee42d32005621b
2018-05-26 07:34:37 +03:00
|
|
|
self.fail(
|
2020-09-01 03:32:44 +03:00
|
|
|
"spawndetached() took took %s seconds, should have "
|
codemod: join the auto-formatter party
Summary:
Turned on the auto formatter. Ran `arc lint --apply-patches --take BLACK **/*.py`.
Then run `arc lint` again so some other autofixers like spellchecker etc. looked
at the code base. Manually accept the changes whenever they make sense, or use
a workaround (ex. changing "dict()" to "dict constructor") where autofix is false
positive. Disabled linters on files that are hard (i18n/polib.py) to fix, or less
interesting to fix (hgsubversion tests), or cannot be fixed without breaking
OSS build (FBPYTHON4).
Conflicted linters (test-check-module-imports.t, part of test-check-code.t,
test-check-pyflakes.t) are removed or disabled.
Duplicated linters (test-check-pyflakes.t, test-check-pylint.t) are removed.
An issue of the auto-formatter is lines are no longer guarnateed to be <= 80
chars. But that seems less important comparing with the benefit auto-formatter
provides.
As we're here, also remove test-check-py3-compat.t, as it is currently broken
if `PYTHON3=/bin/python3` is set.
Reviewed By: wez, phillco, simpkins, pkaush, singhsrb
Differential Revision: D8173629
fbshipit-source-id: 90e248ae0c5e6eaadbe25520a6ee42d32005621b
2018-05-26 07:34:37 +03:00
|
|
|
"returned immediately" % (end - start)
|
|
|
|
)
|
2017-04-11 21:25:40 +03:00
|
|
|
|
2020-09-01 03:32:44 +03:00
|
|
|
def testspawndetachedfailure1(self):
|
|
|
|
"""spawndetached() should throw if executing the process fails."""
|
2017-04-11 21:25:40 +03:00
|
|
|
try:
|
2020-09-01 03:32:44 +03:00
|
|
|
util.spawndetached(["no_such_program", "arg1", "arg2"])
|
|
|
|
self.fail("expected spawndetached to fail with ENOENT")
|
|
|
|
except (OSError, IOError) as ex:
|
2017-04-11 21:25:40 +03:00
|
|
|
self.assertEqual(ex.errno, errno.ENOENT)
|
|
|
|
|
2020-09-01 03:32:44 +03:00
|
|
|
def testspawndetachedfailure2(self):
|
|
|
|
"""spawndetached() should throw if executing the process fails."""
|
2017-04-11 21:25:40 +03:00
|
|
|
try:
|
2020-09-01 03:32:44 +03:00
|
|
|
util.spawndetached([os.devnull, "arg1", "arg2"])
|
|
|
|
self.fail("expected spawndetached to fail with EACCES")
|
|
|
|
except (OSError, IOError) as ex:
|
2017-04-11 21:25:40 +03:00
|
|
|
self.assertEqual(ex.errno, errno.EACCES)
|
|
|
|
|
2017-12-01 02:58:37 +03:00
|
|
|
def testflock(self):
|
2017-11-30 01:57:10 +03:00
|
|
|
testtmp = os.environ["TESTTMP"]
|
|
|
|
opener = vfs.vfs(testtmp)
|
codemod: join the auto-formatter party
Summary:
Turned on the auto formatter. Ran `arc lint --apply-patches --take BLACK **/*.py`.
Then run `arc lint` again so some other autofixers like spellchecker etc. looked
at the code base. Manually accept the changes whenever they make sense, or use
a workaround (ex. changing "dict()" to "dict constructor") where autofix is false
positive. Disabled linters on files that are hard (i18n/polib.py) to fix, or less
interesting to fix (hgsubversion tests), or cannot be fixed without breaking
OSS build (FBPYTHON4).
Conflicted linters (test-check-module-imports.t, part of test-check-code.t,
test-check-pyflakes.t) are removed or disabled.
Duplicated linters (test-check-pyflakes.t, test-check-pylint.t) are removed.
An issue of the auto-formatter is lines are no longer guarnateed to be <= 80
chars. But that seems less important comparing with the benefit auto-formatter
provides.
As we're here, also remove test-check-py3-compat.t, as it is currently broken
if `PYTHON3=/bin/python3` is set.
Reviewed By: wez, phillco, simpkins, pkaush, singhsrb
Differential Revision: D8173629
fbshipit-source-id: 90e248ae0c5e6eaadbe25520a6ee42d32005621b
2018-05-26 07:34:37 +03:00
|
|
|
name = "testlock"
|
2017-11-30 01:57:10 +03:00
|
|
|
|
codemod: join the auto-formatter party
Summary:
Turned on the auto formatter. Ran `arc lint --apply-patches --take BLACK **/*.py`.
Then run `arc lint` again so some other autofixers like spellchecker etc. looked
at the code base. Manually accept the changes whenever they make sense, or use
a workaround (ex. changing "dict()" to "dict constructor") where autofix is false
positive. Disabled linters on files that are hard (i18n/polib.py) to fix, or less
interesting to fix (hgsubversion tests), or cannot be fixed without breaking
OSS build (FBPYTHON4).
Conflicted linters (test-check-module-imports.t, part of test-check-code.t,
test-check-pyflakes.t) are removed or disabled.
Duplicated linters (test-check-pyflakes.t, test-check-pylint.t) are removed.
An issue of the auto-formatter is lines are no longer guarnateed to be <= 80
chars. But that seems less important comparing with the benefit auto-formatter
provides.
As we're here, also remove test-check-py3-compat.t, as it is currently broken
if `PYTHON3=/bin/python3` is set.
Reviewed By: wez, phillco, simpkins, pkaush, singhsrb
Differential Revision: D8173629
fbshipit-source-id: 90e248ae0c5e6eaadbe25520a6ee42d32005621b
2018-05-26 07:34:37 +03:00
|
|
|
with extutil.flock(opener.join(name), "testing a lock", timeout=0):
|
2017-11-30 01:57:10 +03:00
|
|
|
otherlock = self.otherprocesslock(opener, name)
|
2020-01-31 21:49:34 +03:00
|
|
|
self.assertEqual(
|
codemod: join the auto-formatter party
Summary:
Turned on the auto formatter. Ran `arc lint --apply-patches --take BLACK **/*.py`.
Then run `arc lint` again so some other autofixers like spellchecker etc. looked
at the code base. Manually accept the changes whenever they make sense, or use
a workaround (ex. changing "dict()" to "dict constructor") where autofix is false
positive. Disabled linters on files that are hard (i18n/polib.py) to fix, or less
interesting to fix (hgsubversion tests), or cannot be fixed without breaking
OSS build (FBPYTHON4).
Conflicted linters (test-check-module-imports.t, part of test-check-code.t,
test-check-pyflakes.t) are removed or disabled.
Duplicated linters (test-check-pyflakes.t, test-check-pylint.t) are removed.
An issue of the auto-formatter is lines are no longer guarnateed to be <= 80
chars. But that seems less important comparing with the benefit auto-formatter
provides.
As we're here, also remove test-check-py3-compat.t, as it is currently broken
if `PYTHON3=/bin/python3` is set.
Reviewed By: wez, phillco, simpkins, pkaush, singhsrb
Differential Revision: D8173629
fbshipit-source-id: 90e248ae0c5e6eaadbe25520a6ee42d32005621b
2018-05-26 07:34:37 +03:00
|
|
|
otherlock, locktimeout, "other process should not have taken the lock"
|
|
|
|
)
|
2017-11-30 01:57:10 +03:00
|
|
|
|
|
|
|
otherlock = self.otherprocesslock(opener, name)
|
2020-01-31 21:49:34 +03:00
|
|
|
self.assertEqual(
|
codemod: join the auto-formatter party
Summary:
Turned on the auto formatter. Ran `arc lint --apply-patches --take BLACK **/*.py`.
Then run `arc lint` again so some other autofixers like spellchecker etc. looked
at the code base. Manually accept the changes whenever they make sense, or use
a workaround (ex. changing "dict()" to "dict constructor") where autofix is false
positive. Disabled linters on files that are hard (i18n/polib.py) to fix, or less
interesting to fix (hgsubversion tests), or cannot be fixed without breaking
OSS build (FBPYTHON4).
Conflicted linters (test-check-module-imports.t, part of test-check-code.t,
test-check-pyflakes.t) are removed or disabled.
Duplicated linters (test-check-pyflakes.t, test-check-pylint.t) are removed.
An issue of the auto-formatter is lines are no longer guarnateed to be <= 80
chars. But that seems less important comparing with the benefit auto-formatter
provides.
As we're here, also remove test-check-py3-compat.t, as it is currently broken
if `PYTHON3=/bin/python3` is set.
Reviewed By: wez, phillco, simpkins, pkaush, singhsrb
Differential Revision: D8173629
fbshipit-source-id: 90e248ae0c5e6eaadbe25520a6ee42d32005621b
2018-05-26 07:34:37 +03:00
|
|
|
otherlock, locksuccess, "other process should have taken the lock"
|
|
|
|
)
|
2017-11-30 01:57:10 +03:00
|
|
|
|
|
|
|
def otherprocesslock(self, opener, name):
|
|
|
|
pid = os.fork()
|
|
|
|
if pid == 0:
|
|
|
|
try:
|
codemod: join the auto-formatter party
Summary:
Turned on the auto formatter. Ran `arc lint --apply-patches --take BLACK **/*.py`.
Then run `arc lint` again so some other autofixers like spellchecker etc. looked
at the code base. Manually accept the changes whenever they make sense, or use
a workaround (ex. changing "dict()" to "dict constructor") where autofix is false
positive. Disabled linters on files that are hard (i18n/polib.py) to fix, or less
interesting to fix (hgsubversion tests), or cannot be fixed without breaking
OSS build (FBPYTHON4).
Conflicted linters (test-check-module-imports.t, part of test-check-code.t,
test-check-pyflakes.t) are removed or disabled.
Duplicated linters (test-check-pyflakes.t, test-check-pylint.t) are removed.
An issue of the auto-formatter is lines are no longer guarnateed to be <= 80
chars. But that seems less important comparing with the benefit auto-formatter
provides.
As we're here, also remove test-check-py3-compat.t, as it is currently broken
if `PYTHON3=/bin/python3` is set.
Reviewed By: wez, phillco, simpkins, pkaush, singhsrb
Differential Revision: D8173629
fbshipit-source-id: 90e248ae0c5e6eaadbe25520a6ee42d32005621b
2018-05-26 07:34:37 +03:00
|
|
|
with extutil.flock(opener.join(name), "other process lock", timeout=0):
|
2017-11-30 01:57:10 +03:00
|
|
|
os._exit(locksuccess)
|
|
|
|
except error.LockHeld:
|
|
|
|
os._exit(locktimeout)
|
|
|
|
else:
|
2020-10-04 14:49:10 +03:00
|
|
|
time.sleep(0.1) # Avoids a crash on OSX
|
2017-11-30 01:57:10 +03:00
|
|
|
p, st = os.waitpid(pid, 0)
|
2020-06-24 04:45:45 +03:00
|
|
|
st = _exitstatus(st) # Convert back to an int
|
2017-11-30 01:57:10 +03:00
|
|
|
return st
|
|
|
|
|
codemod: join the auto-formatter party
Summary:
Turned on the auto formatter. Ran `arc lint --apply-patches --take BLACK **/*.py`.
Then run `arc lint` again so some other autofixers like spellchecker etc. looked
at the code base. Manually accept the changes whenever they make sense, or use
a workaround (ex. changing "dict()" to "dict constructor") where autofix is false
positive. Disabled linters on files that are hard (i18n/polib.py) to fix, or less
interesting to fix (hgsubversion tests), or cannot be fixed without breaking
OSS build (FBPYTHON4).
Conflicted linters (test-check-module-imports.t, part of test-check-code.t,
test-check-pyflakes.t) are removed or disabled.
Duplicated linters (test-check-pyflakes.t, test-check-pylint.t) are removed.
An issue of the auto-formatter is lines are no longer guarnateed to be <= 80
chars. But that seems less important comparing with the benefit auto-formatter
provides.
As we're here, also remove test-check-py3-compat.t, as it is currently broken
if `PYTHON3=/bin/python3` is set.
Reviewed By: wez, phillco, simpkins, pkaush, singhsrb
Differential Revision: D8173629
fbshipit-source-id: 90e248ae0c5e6eaadbe25520a6ee42d32005621b
2018-05-26 07:34:37 +03:00
|
|
|
|
|
|
|
if __name__ == "__main__":
|
2017-04-11 21:25:40 +03:00
|
|
|
silenttestrunner.main(__name__)
|